简体   繁体   English

Spring LDAP:InvalidNameException:/:[LDAP:错误代码34

[英]Spring LDAP: InvalidNameException: /: [LDAP: error code 34

I am getting following exception while authenticating a user: 验证用户身份时出现以下异常:

If I use values in applicationContext like this: 如果我像这样在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,DC=lab2,DC=ins" />

Exception will be: 例外是:

Exception in thread "main" org.springframework.ldap.InvalidNameException: /: [LDAP: error code 34 - 0000208F: NameErr: DSID-031001BA, problem 2006 (BAD_NAME), data 8349, best match of:
    'DC=lab2,DC=ins/dc=lab2,dc=ins'

else if application context like this: 否则,如果应用程序上下文是这样的:

<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" />

Exception will be: 例外是:

Exception in thread "main" org.springframework.ldap.PartialResultException: nested exception is javax.naming.PartialResultException [Root exception is javax.naming.CommunicationException: lab2.ins:389 [Root exception is java.net.UnknownHostException: lab2.ins]]
    at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:205)

Authenticate method: 验证方式:

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 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>

testClass: 识别TestClass:

Resource r = new ClassPathResource("applicationContext.xml");
BeanFactory factory = new XmlBeanFactory(r);
ContactLDAP contact = (ContactLDAP) factory.getBean("ldapContact"); 

System.out.println(contact.authenticate("username", "secret"));

What am I missing here? 我在这里想念什么?

You don't need 你不需要

<property name="base" value="DC=lab2,DC=ins" />

As in UserDn, you already put the full DN. 与在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" />

...

This should work. 这应该工作。 (But I would avoid spaces in the DN) (但我会避免在DN中留空格)

There is a slash / character in the distinguished name. 可分辨名称中有一个斜杠/字符。 While this is a legal character in a DN, perhaps it should be a comma , . 尽管这在DN中是合法字符,但也许应该是逗号, See also Distinguished Names 另请参阅专有名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM