javax.naming.AuthenticationException: [LDAP: 错误代码 49 - 凭据无效]

13

我对ldap还不熟悉,我正在尝试使用一个已经设置好的ldap实例来测试spring ldap模块,这是一个简单的示例。

有关我正在使用的ldap实例的详细信息可以在这里找到: http://blog.stuartlewis.com/2008/07/07/test-ldap-service/comment-page-3/

我使用了一个ldap浏览器/管理工具(Softerra LDAP Admin),我可以无问题地访问目录。

当我尝试使用java和spring-ldap(2.0.1)时,我遇到了上面提到的身份验证异常。在设置自己的ldap实例以进一步排除故障之前,我想在这里检查一下,以防有更多经验的人能指出我错过的一些明显的东西。

以下是我使用的代码:

import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;

import java.util.List;

public class LdapTest {


public List<String> getListing() {

    LdapTemplate template = getTemplate();

    List<String> children = template.list("dc=testathon,dc=net");

   return children;
}


private LdapTemplate getTemplate(){

    LdapContextSource contextSource = new LdapContextSource();
    contextSource.setUrl("ldap://ldap.testathon.net:389");
    contextSource.setUserDn("cn=john");
    contextSource.setPassword("john");

    try {
        contextSource.afterPropertiesSet();
    } catch (Exception ex) {
        ex.printStackTrace();
    }


    LdapTemplate template = new LdapTemplate();

    template.setContextSource(contextSource);

    return template;

}


public static void main(String[] args){


    LdapTest sClient = new LdapTest();
    List<String> children = sClient.getListing();

    for  (String child :children) {
        System.out.println(child);
    }

}

}

堆栈跟踪:

Exception in thread "main" org.springframework.ldap.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]; nested exception is javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]
at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:191)
at org.springframework.ldap.core.support.AbstractContextSource.createContext(AbstractContextSource.java:356)
at org.springframework.ldap.core.support.AbstractContextSource.doGetContext(AbstractContextSource.java:140)

你必须使用Spring吗? - vkg
2个回答

10

原来我只需要包含颁发者名称中的所有内容,包括组织单位。使用此方法即可。

contextSource.setBase(...);

因为某种原因未能正常工作。 在进行更正后,一切都正常了。

contextSource.setUserDn("cn=john,ou=Users,dc=testathon,dc=net");

0
contextSource.setUserDn();

可能是用于LDAP管理用户。 因此应该是"cn=john,ou=Users,dc=testathon,dc=net"contextSource.setBase(...);则是为后续使用如template.list(...)做准备。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接