I would like to list or search the root context(s) in a LDAP tree. I use Apache Directory Server and Java:
Hashtable<String, String> contextParams = new Hashtable<String, String>();
contextParams.put("java.naming.provider.url", "ldap://localhost:10389");
contextParams.put("java.naming.security.principal", "uid=admin,ou=system");
contextParams.put("java.naming.security.credentials", "secret");
contextParams.put("java.naming.security.authentication", "simple");
contextParams.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory");
DirContext dirContext = new InitialDirContext(contextParams);
NamingEnumeration<NameClassPair> resultList;
//Works
resultList = dirContext.list("ou=system");
while (resultList.hasMore()) {
NameClassPair result = resultList.next();
System.out.println(result.getName());
}
//Does not work
resultList = dirContext.list("");
while (resultList.hasMore()) {
NameClassPair result = resultList.next();
System.out.println(result.getName());
}
I can list the sub nodes of ou=system. But I cannot list the sub nodes of the actual root node. I would like to have this list just like Apache Directory Studio can: