如何在ldap中使用/设置authenticationProvider

时间:2019-01-25 12:07:50

标签: spring spring-security ldap spring-security-ldap

我必须基于用户具有的ldap“ memberOf”属性进行身份验证。因此,我正在尝试使用ActiveDirectoryLdapAuthenticationProvider。 问题是,如果我尝试使用uid登录,则会收到 [LDAP:错误代码34-无效DN] 。当我使用完整的DN时,例如: cn =测试用户,ou = users,dc = mycompany,dc = com 我一直都有糟糕的资历。

使用ldapAuthentication这样的设置我没有问题:

@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {

    auth
            .ldapAuthentication()
            .userSearchFilter("uid={0}")
            .groupSearchFilter("member={0})")
            .userDetailsContextMapper(userContextMapper())
            .contextSource()
            .url("ldap://ldap.mycompany.com:389/dc=mycompany,dc=com")
            .port(389);
}

当我尝试使用authenticationProvider时的设置:

@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {

    auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
}


@Bean
public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
    ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(null, "ldap://ldap.mycompany.com:389", "dc=mycompany,dc=com");
    provider.setConvertSubErrorCodesToExceptions(true);
    provider.setUseAuthenticationRequestCredentials(true);
    return provider;
}

0 个答案:

没有答案
相关问题