我正在尝试使用 Spring 的 LDAP 包对 Activity 目录进行身份验证,但我一直收到一条错误消息,提示我指定了错误的 baseDN(Ldap 错误代码 32):
org.springframework.ldap.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-031001E4, problem 2001 (NO_OBJECT), data 0, best match of:
[testng] 'OU=People,DC=example,DC=com'
[testng] ]; nested exception is javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-031001E4, problem 2001 (NO_OBJECT), data 0, best match of:
[testng] 'OU=People,DC=example,DC=com'
[testng] ]; remaining name 'ou=people,dc=example,dc=com'
奇怪的是 ldapsearch 命令使用了精确的 basedn,而且它起作用了:
ldapsearch -V -x -H ldap://ad.example.com:389 -b 'ou=people,dc=example,dc=com' -D '<user>' -w '<password>' (sAMAccountName=<user>)
以下代码设置 DN(ldapContextSource 以编程方式设置):
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("sAMAccountName", user));
DistinguishedName dn = new DistinguishedName("ou=people,dc=example,dc=com");
boolean in = ldapTemplate.authenticate(dn, filter.toString(), password);
不确定这是否有帮助,但这些是其他字段:
userDN = <myusername>@example.com
url = ldap://ad.example.com:389
password = <mypassword>
baseDN = ou=people,dc=example,dc=com
编辑:我更改了用户 DN:cn=username,out=people,dc=example,dc=com 这仍然会给出错误 32 代码。
最佳答案
谢谢大家,您的线索确实阐明了问题。
首先,userDN确实是错误的。我解决了这个问题(请参阅原始帖子中的编辑)。
其次,由于我已经在ldapContextSource 中指定了baseDN,因此在调用authenticate() 时无需再次指定。所以使用 DistinguishedName.EMPTY_PATH
解决了这个问题。
第三,我的 equals 过滤器不正确。当我更改 userDN 时,我忘记了 sAMAccountName
需要更改为实际的登录名,而不是最初设置的 userDN。
ldapTemplate.authenticate() 现在返回 true,这意味着我已经通过身份验证。
关于java - 为什么在执行 ldapTemplate.authenticate() 时 baseDN 不正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13692048/