我正在尝试使用 Spring 的 LDAP 包对活动目录进行身份验证,但我不断收到错误消息,指出我指定了错误的 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
编辑:我更改了 userDN:cn=username,out=people,dc=example,dc=com 这仍然给出错误 32 代码。