List the root contexts in LDAP

Posted by Lennart Schedin on Stack Overflow See other posts from Stack Overflow or by Lennart Schedin
Published on 2010-04-11T08:40:13Z Indexed on 2010/04/11 8:43 UTC
Read the original article Hit count: 542

Filed under:
|
|

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: alt text

© Stack Overflow or respective owner

Related posts about ldap

Related posts about apacheds