List of context root in LDAP

I would like to list or search for the root context in an LDAP tree. I am using 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 subsidiary nodes of the ou = system. But I cannot list the helper nodes of the real root node. I would like to have this list in the same way that Apache Directory Studio can: alt text http://lesc.se/stackoverflow/ldap_root_contexts.png

+2


source to share


1 answer


Base DNs can be obtained from the namingContexts attribute of the root node (RootDSE). The code should look like this:



Attributes attributes = dirContext.getAttributes( "", new String[]{"namingContexts"} );
Attribute attribute = attributes.get( "namingContexts" );
NamingEnumeration<?> all = attribute.getAll();
while(all.hasMore())
{
    String next = (String)all.next();
    System.out.println(next);
}

      

+4


source







All Articles