Spring Boot LDAP身份验证:始终获取错误凭据

Spring Boot LDAP身份验证:始终获取错误凭据,spring,active-directory,ldap,Spring,Active Directory,Ldap,我正在尝试使用Spring启动应用程序对本地网络中的Active Directory服务器进行身份验证,但我不知道我可能做错了什么 当我访问localhost时,我被重定向到登录页面: 每当我写入任何真实用户凭据时,我都会被重定向到同一页面,并显示一条错误消息: 如果我以用户和密码的身份随机发送一个单词,我会看到相同的登录错误屏幕,但另外,Eclipse控制台会显示此消息: 2016-02-04 18:54:47.591 INFO 10092 --- [nio-8080-exec-8] c

我正在尝试使用Spring启动应用程序对本地网络中的Active Directory服务器进行身份验证,但我不知道我可能做错了什么

当我访问localhost时,我被重定向到登录页面:

每当我写入任何真实用户凭据时,我都会被重定向到同一页面,并显示一条错误消息:

如果我以用户和密码的身份随机发送一个单词,我会看到相同的登录错误屏幕,但另外,Eclipse控制台会显示此消息:

2016-02-04 18:54:47.591  INFO 10092 --- [nio-8080-exec-8] ctiveDirectoryLdapAuthenticationProvider : Active Directory authentication failed: Supplied password was invalid
在Active Directory服务器中,我要访问的组的区别名称是:CN=Bulnes,OU=Usuarios Locales,DC=Bulnes,DC=local,因此它在安全配置类中配置如下:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/css/**").permitAll()
                .anyRequest().fullyAuthenticated()
                .and()
            .formLogin();
    }

    @Configuration
    protected static class AuthenticationConfiguration extends
            GlobalAuthenticationConfigurerAdapter {

        @Override
        public void init(AuthenticationManagerBuilder auth) throws Exception {
            ActiveDirectoryLdapAuthenticationProvider provider=
                    new ActiveDirectoryLdapAuthenticationProvider("bulnes.local"
                            ,"ldap://192.168.1.3:389/"
                            ,"CN=Bulnes,OU=Usuarios Locales,DC=Bulnes,DC=local");
            auth.authenticationProvider(provider);
        }
    }
}

刚刚创建了这样的提供者,它工作得很好

ActiveDirectoryLdapAuthenticationProvider provider=
                    new ActiveDirectoryLdapAuthenticationProvider("bulnes.local"
                            ,"ldap://192.168.1.3:389);
它仍然会给出一个异常,但至少会进行身份验证

2016-02-04 21:30:36.293  INFO 12056 --- [nio-8080-exec-3] o.s.s.ldap.SpringSecurityLdapTemplate    : Ignoring PartialResultException

这就是我的工作原理:

广告属性

ad.url=ldap://yourserver.abc.com:389
ad.domain=abc.com
WebSecurityConfig.java

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {   

    @Value("${ad.domain}")
    private String adDomain;

    @Value("${ad.url}")
    private String adUrl;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/login", "/css/**", "/public/**").permitAll().anyRequest().authenticated()
                .and().formLogin().loginPage("/login").defaultSuccessUrl("/", true)             
                .failureUrl("/login?failed=badcredentials")
                .permitAll().and().logout().logoutUrl("/logout")
                .logoutSuccessUrl("/login");
    }

    @Bean
    @Override
    public AuthenticationManager authenticationManager() {
        return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider()));
    }

    @Bean
    public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
        ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(adDomain,
                adUrl);
        provider.setConvertSubErrorCodesToExceptions(true);
        provider.setUseAuthenticationRequestCredentials(true);

        return provider;
    }
}