【发布时间】:2014-07-04 14:13:44
【问题描述】:
我是 ldap 的新手,我正在尝试我认为是一个简单的例子来测试 spring ldap 模块,其中包含有人已经为测试设置的 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吗?
标签: java spring-ldap