通过Active Directory通过Spring Security进行身份验证

时间:2019-10-10 21:13:41

标签: spring-boot spring-security active-directory windows-authentication

我需要在Windows上使用AD进行身份验证,并且使用Spring Security。我按照文档进行操作 this documentation

我尝试了很多方法,但是什么也没有。

我简单的控制器

@RestController
public class HomeController {

 @GetMapping("/")
 public String index() {
    return "Welcome to the home page!";
 }
}

还有我的webConfigure

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

 @Bean
 public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
     ActiveDirectoryLdapAuthenticationProvider provider = new 
 ActiveDirectoryLdapAuthenticationProvider("DOMAIN","LDAP URL"); 
         provider.setConvertSubErrorCodesToExceptions(true);
         provider.setUseAuthenticationRequestCredentials(true);
     return provider;
 }
 @Bean
 public LoggerListener loggerListener() {
     return new LoggerListener();
 }

 @Override
 protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
 }

 @Override
 public void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
 }
}

在我测试的所有时间,我都会遇到此错误:

Security authorization failed due to: org.springframework.security.access.AccessDeniedException:

请帮帮我!

0 个答案:

没有答案