我正在编写一个要求用户登录的Web应用程序.我的公司有一个Active Directory服务器,我想为此目的使用它.但是,我在使用Spring验证用户凭据时遇到问题.
我正在使用Spring Security 3.2.2,Spring Ldap 2.0.1和Java 1.7.
Web应用程序启动良好,针对InMemory-Authentication的身份验证也运行良好,因此我的应用程序的其余部分似乎配置正确.
这是我的配置:
@Configuration
@EnableWebSecurity
public class LdapConfig extends WebSecurityConfigurerAdapter {
@Bean
public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
val provider = new ActiveDirectoryLdapAuthenticationProvider("my.domain", "ldap://LDAP_ID:389/OU=A_GROUP,DC=domain,DC=tld");
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
provider.setUseAuthenticationRequestCredentials(true);
return provider;
}
@Bean
public LoggerListener loggerListener() {
return new LoggerListener();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
// Configuration for Redirects, Login-Page and stuff
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用MY_USERNAME和MY_PASSWORD登录时,我得到了一个 Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials
完整Stacktrace:
14:59:00,508 …Run Code Online (Sandbox Code Playgroud)