使用Spring LDAP对用户进行身份验证时出现异常

时间:2012-08-28 12:45:43

标签: java spring ldap spring-ldap

我在验证用户时遇到异常:

Exception in thread "main" org.springframework.ldap.PartialResultException: Unprocessed Continuation Reference(s); nested exception is javax.naming.PartialResultException: Unprocessed Continuation Reference(s); remaining name '/'
    at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:205)

验证方法:

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

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

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

我在这里缺少什么?

1 个答案:

答案 0 :(得分:2)

通过设置java.naming.referral=follow来尝试关注推介。