javax.naming.AuthenticationException: [LDAP: 错误代码 49 - 凭据无效]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23689964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]
提问by Quantum_Entanglement
I'm new to ldap and I was trying what I thought was a trivial example to test the spring ldap module with an ldap instance that someone had already setup for testing.
我是 ldap 的新手,我正在尝试我认为是一个微不足道的示例,以使用某人已经设置用于测试的 ldap 实例来测试 spring ldap 模块。
Details about the ldap instance that I am using can be found here: http://blog.stuartlewis.com/2008/07/07/test-ldap-service/comment-page-3/
可以在此处找到有关我正在使用的 ldap 实例的详细信息:http: //blog.stuartlewis.com/2008/07/07/test-ldap-service/comment-page-3/
I've used an ldap browser/admin tool (Softerra LDAP Admin) and I can access the directory without any issues.
我使用了 ldap 浏览器/管理工具(Softerra LDAP Admin),我可以毫无问题地访问该目录。
When I try it using java and spring-ldap (2.0.1) I get the Authentication Exception mentioned above. Before setting up my own ldap instance to try and troubleshoot this further I wanted to check here in case someone with more experience could point out something obvious that I missed.
当我使用 java 和 spring-ldap (2.0.1) 尝试它时,我得到了上面提到的身份验证异常。在设置我自己的 ldap 实例以尝试进一步解决此问题之前,我想在这里检查一下,以防有更多经验的人指出我遗漏的明显内容。
Below is the code I am using:
下面是我正在使用的代码:
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);
}
}
}
Stack trace:
堆栈跟踪:
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)
采纳答案by Quantum_Entanglement
It turns out I just needed to include everything in the distinguished name(including the organization unit). Using
结果证明我只需要在专有名称中包含所有内容(包括组织单位)。使用
contextSource.setBase(...);
for some reason did not work. After making that correction all was fine.
由于某种原因没有工作。进行修正后一切正常。
contextSource.setUserDn("cn=john,ou=Users,dc=testathon,dc=net");