我是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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
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)
Run Code Online (Sandbox Code Playgroud)
事实证明,我只需要在可分辨名称(包括组织单位)中包含所有内容.运用
contextSource.setBase(...);
Run Code Online (Sandbox Code Playgroud)
由于某种原因没有奏效.做出那次纠正之后一切都很好.
contextSource.setUserDn("cn=john,ou=Users,dc=testathon,dc=net");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33182 次 |
| 最近记录: |