【发布时间】:2020-02-18 09:07:39
【问题描述】:
我的客户要求之一是根据他的公司 ActiveDirectory (LDAP) 对用户进行身份验证。所以我使用了标准的 ActiveDirectoryLdapAuthenticationProvider,它就像一个魅力。
@Bean
public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
ActiveDirectoryLdapAuthenticationProvider adProvider = new ActiveDirectoryLdapAuthenticationProvider(
ldapConfig.getLdapDomain(), ldapConfig.getLdapUrl(), ldapConfig.getLdapRoot());
adProvider.setConvertSubErrorCodesToExceptions(true);
adProvider.setUseAuthenticationRequestCredentials(true);
adProvider.setSearchFilter(ldapConfig.getLdapSearchFilter());
return adProvider;
}
问题是客户端 AC 隐藏在防火墙后面。它在部署后工作,但由于客户端安全策略,我在本地开发期间无法访问 AC。所以,我有一个想法,也许对于开发配置文件,我将使用嵌入式 LDAP 服务器(UnboundID LDAP SDK for Java)。我不是 LDAP 专家,但我以某种方式编写了简单的 ldif 文件,它看起来像这样:
dn: dc=test,dc=local
objectclass: top
objectclass: domain
objectclass: extensibleObject
dc: test
# Organizational Units
dn: ou=groups,dc=test,dc=local
objectclass: top
objectclass: organizationalUnit
ou: groups
dn: ou=people,dc=test,dc=local
objectclass: top
objectclass: organizationalUnit
ou: people
# Users
dn: uid=john,ou=people,dc=test,dc=local
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: John Doe
sn: John
uid: john
password: johnspassword
# Create Groups
dn: cn=administrators,ou=groups,dc=test,dc=local
objectclass: top
objectclass: groupOfUniqueNames
cn: administrators
ou: administrator
uniqueMember: uid=john,ou=people,dc=test,dc=local
我还配置了嵌入式 ldap 属性:
spring.ldap.embedded.base-dn=dc=test,dc=local
spring.ldap.embedded.ldif=classpath:localldapactivedirectory.ldif
spring.ldap.embedded.port=12345
spring.ldap.embedded.url=ldap://localhost:12345/
spring.ldap.embedded.validation.enabled=false
UnboundID 对此没有任何问题,但正如您猜测的那样,我在身份验证期间遇到了问题:
[LDAP: error code 34 - Unable to parse bind DN 'john@test.local': Unable to parse string 'john@test.local' as a DN because it does not have an equal sign after RDN attribute 'john@test.local'.]; nested exception is javax.naming.InvalidNameException: [LDAP: error code 34 - Unable to parse bind DN 'john@test.local': Unable to parse string 'user_cms@test.com' as a DN because it does not have an equal sign after RDN attribute 'john@test.local'.]
为了向您展示全貌,我添加了在身份验证尝试期间发生的错误(在自定义身份验证服务中):
Authentication authentication = authenticationManagerBuilder.getObject()
.authenticate(authenticationToken);
我推测是因为我的 ldif 文件太简单了。它适用于 vanilla Ldap 身份验证提供程序,但不适用于 ActiveDirectoryLdapAuthenticationProvider。
是否有人知道如何在 ldif 文件中“模拟”ActiveDirectory(LDAP),以便 ActiveDirectoryLdapAuthenticationProvider 可以在身份验证期间使用它?
【问题讨论】:
-
很久了,你找到解决办法了吗?
标签: java spring authentication active-directory ldap