I'm new to ldap and I was trying to figure out what, in my opinion, was a trivial example of testing the ldap spring module with an ldap instance that someone had already set up for testing.
Details about the ldap instance that I use can be found here:
http://blog.stuartlewis.com/2008/07/07/test-ldap-service/comment-page-3/
I used the ldap browser / admin tool (Softerra LDAP Admin) and I can access the directory without any problems.
When I try to use java and spring -ldap (2.0.1), I get the above authentication exception. Before setting up my own instance of ldap to try to fix this problem, I wanted to check here if someone with a lot of experience could point out something obvious that I missed.
The following is the code I'm 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)
source
share