Spring LDAP:InvalidNameException:/:[LDAP:错误代码34
我在验证用户时遇到以下异常: 如果我在applicationContext中使用如下值:Spring LDAP:InvalidNameException:/:[LDAP:错误代码34,spring,ldap,spring-ldap,Spring,Ldap,Spring Ldap,我在验证用户时遇到以下异常: 如果我在applicationContext中使用如下值: <property name="url" value="ldap://10.10.10.10:389/DC=lab2,DC=ins" /> <property name="base" value="DC=lab2,DC=ins" /> <property name="userDn" value="CN=Ldap Bind,OU=Service Accounts,OU=TECH,
<property name="url" value="ldap://10.10.10.10:389/DC=lab2,DC=ins" />
<property name="base" value="DC=lab2,DC=ins" />
<property name="userDn" value="CN=Ldap Bind,OU=Service Accounts,OU=TECH,DC=lab2,DC=ins" />
<property name="url" value="ldap://10.10.10.10:389" />
<property name="base" value="DC=lab2,DC=ins" />
<property name="userDn" value="CN=Ldap Bind,OU=Service Accounts,OU=TECH,DC=lab2,DC=ins" />
否则,如果应用程序上下文如下所示:
<property name="url" value="ldap://10.10.10.10:389/DC=lab2,DC=ins" />
<property name="base" value="DC=lab2,DC=ins" />
<property name="userDn" value="CN=Ldap Bind,OU=Service Accounts,OU=TECH,DC=lab2,DC=ins" />
<property name="url" value="ldap://10.10.10.10:389" />
<property name="base" value="DC=lab2,DC=ins" />
<property name="userDn" value="CN=Ldap Bind,OU=Service Accounts,OU=TECH,DC=lab2,DC=ins" />
验证方法:
public boolean authenticate(String userName, String password) {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "person")).and(
new EqualsFilter("sAMAccountName", userName));
return ldapTemplate.authenticate(DistinguishedName.EMPTY_PATH, filter
.toString(), password);
}
Applicationcontext.xml
<bean id="contextSource"
class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldap://10.10.10.10:389" />
<property name="base" value="DC=lab2,DC=ins" />
<property name="userDn" value="CN=Ldap Bind,OU=Service Accounts,OU=TECH,DC=lab2,DC=ins" />
<property name="password" value="secret" />
<property name="baseEnvironmentProperties">
<map>
<entry key="java.naming.referral">
<value>follow</value>
</entry>
</map>
</property>
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="ldapContact"
class="ldap.ContactLDAP ">
<property name="ldapTemplate" ref="ldapTemplate" />
</bean>
这里缺少什么?可分辨名称中有一个斜杠
/
字符。虽然这是DN中的合法字符,但可能应该是逗号,
。另请参见您不需要的
<property name="base" value="DC=lab2,DC=ins" />
与UserDn一样,您已经放置了完整的DN
<bean id="contextSource"
class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldap://10.10.10.10:389" />
<property name="userDn" value="CN=Ldap Bind,OU=Service Accounts,OU=TECH,DC=lab2,DC=ins" />
<property name="password" value="secret" />
...
...
这应该行得通。(但我会避免在DN中使用空格)我已经用ldap url添加了base,这就是它出现的原因,但是在删除它之后,我得到了一些其他异常。
<bean id="contextSource"
class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldap://10.10.10.10:389" />
<property name="userDn" value="CN=Ldap Bind,OU=Service Accounts,OU=TECH,DC=lab2,DC=ins" />
<property name="password" value="secret" />
...