通过spring security进行的Active Directory身份验证会为有效用户返回错误凭据

时间:2014-06-04 17:32:58

标签: java spring spring-security active-directory

我有一个基于spring的应用程序,我正在尝试实现spring安全性并对我的Active Directory进行身份验证。我在

上看到了一个很好的例子

Active Directory Authentication using Spring Security 3.2, Spring Ldap 2.0 and JavaConfig

但我的申请中没有基于角色的权限。有没有办法在通过spring security进行身份验证时避免使用userAuthoritiesMapper?。

这是我的配置:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(AuthenticationManagerBuilder authManagerBuilder)
        throws Exception {

    authManagerBuilder
            .authenticationProvider(activeDirectoryLdapAuthenticationProvider());

}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

@Bean
public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
    ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider = new ActiveDirectoryLdapAuthenticationProvider(
            "mydomain.com",
            "ldaps://URL:636");
    activeDirectoryLdapAuthenticationProvider
            .setConvertSubErrorCodesToExceptions(true);
    activeDirectoryLdapAuthenticationProvider
            .setUseAuthenticationRequestCredentials(true);

    return activeDirectoryLdapAuthenticationProvider;
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED).and()
            .authorizeRequests().antMatchers("/login/**").authenticated()
            .and().formLogin().loginPage("/Pages/Login.jsp")
            .loginProcessingUrl("/login");
    // .and().requiresChannel().anyRequest().requiresSecure();
}

0 个答案:

没有答案