在搜索AD时更改@domain结尾

时间:2017-01-19 07:32:43

标签: spring ldap spring-ldap

DC=red,DC=xyz
AD中的

userPrincipalName: firstname.lastname@blue.com

@Bean
    public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
        ActiveDirectoryLdapAuthenticationProvider ap =
                new ActiveDirectoryLdapAuthenticationProvider(domain, url);

        ap.setSearchFilter("(userPrincipalName={0})"); //change @ ending here?
        ap.setConvertSubErrorCodesToExceptions(true);
        ap.setUseAuthenticationRequestCredentials(true);
        ap.setUserDetailsContextMapper(userDetailsContextMapper);

        return ap;
    }

此代码成功对AD进行身份验证,并尝试使用DC=red,DC=xyz

搜索树userPrincipalName: firstname@red.xyz

搜索失败,因为@ red.xyz已过时且使用了@ blue.com。如何在不更改域的情况下重新配置java中的@结尾?

1 个答案:

答案 0 :(得分:0)

问题是userPrincipalName与AD用户名和域名不同。 ActiveDirectoryLdapAuthenticationProvider默认添加搜索参数username @ domain。

作为解决方案,我覆盖了ActiveDirectoryLdapAuthenticationProvider并将搜索过滤器更改为sAMAccountName,并将值更改为不带域的普通用户名。