Я написал веб-приложение Spring bot, которое использует Spring security. У меня есть 2 ссылки, которые используются двумя разными группами людей. Поэтому я создал три активные группы каталогов для пользователей и администраторов соответственно. Моя проблема заключается в том, что люди в одной из групп имеют доступ к приложению, но остальные две группы не могут получить доступ к приложению. Это говорит, что не разрешено просматривать страницу.Spring security logon active directory not working
Моя конфигурация Войти является
@Configuration
@EnableWebMvcSecurity
@ComponentScan("com.books.controller")
public class LoginConfiguration extends WebSecurityConfigurerAdapter
{
@Override
protected void configure(HttpSecurity http) throws Exception
{
http
.authorizeRequests()
.antMatchers("/")
.hasAuthority("BookAdmin")
.and()
.authorizeRequests()
.antMatchers("/rentBook")
.hasAuthority("RentalBook")
.and()
.authorizeRequests()
.antMatchers("/buybook")
.hasAuthority("BuyBook")
.and()
.authorizeRequests()
.antMatchers("/rentBook")
.hasAuthority("BookAdmin")
.and()
.authorizeRequests()
.antMatchers("/buyBook")
.hasAuthority("BookAdmin")
and().authorizeRequests().and().formLogin().loginProcessingUrl("/login")
.and().logout().permitAll()
.and().csrf().disable()
;
http.headers().frameOptions().disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception
{
auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
}
@Bean
public AuthenticationManager authenticationManager() {
return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider()));
}
@Bean
public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider("xxx.klc", "ldap://klcdc03");
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
return provider;
}
}
Пожалуйста, найти свой контроллер класса ниже. Он отлично работает на моей локальной машине. Но при развертывании на сервере он работает только для группы BookAdmin. Я не имею эти группы, перечисленные в любых свойствах файла
package com.tgw.gift.info.controller;
@Controller
public class LoginController {
@RequestMapping("/")
public String home(Model model, Authentication principal)
{
Set<String> authorities=listAuthorties(principal);
if(authorities.contains("BookAdmin"))
{
return "index";
} else {
return "fail";
}
}
private Set<String> listAuthorties(Authentication principal)
{
Set<String> set = new HashSet<String>();
for(GrantedAuthority s: principal.getAuthorities()){
set.add(s.getAuthority());
}
return set;
}
@RequestMapping("/buyBook")
public String printDetails(Model model, Authentication principal){
Set<String> authorities=listAuthorties(principal);
if(authorities.contains("BuyBook"))
{
return "buyBook";
} else if(authorities.contains("BookAdmin")){
return "buyBook";
} else{
return "fail";
}
}
@RequestMapping("/rentBook")
public String printDetails(Model model, Authentication principal){
Set<String> authorities=listAuthorties(principal);
if(authorities.contains("RentalBook"))
{
return "rentBook";
} else if(authorities.contains("RentalAdmin")){
return "rentBook";
} else{
return "fail";
}
}
}
also this works fine when run locally, but not in server.
Добро пожаловать к переполнению стека. Я исправил несколько опечаток. Я также удалил ведущие пробелы в ваше описание, чтобы остановить его как код. И я выделил несколько ключевых слов, используя 2 звездочки. Пожалуйста, объясните, что вы подразумеваете под «это не работает для группы, отличной от BookAdmin». –