OpenLDAP rootDN fetch with Java
I am using Java, I am messing around with connecting to an OpenLDAP directory, I was wondering how I can query the directory to find out the rootDN. So that I can be given the server name, username and password, without requiring them to provide the rootDN. In otherwords, the use says "localhost", user is cn=Manager, and password is secret, I would like to make an annonymous connection to the directory on localhost, fetch the rootDN, then make a bound connection dc=my-domain,dc=com, on localhost with cn=Manager,dc=my-domain,dc=com.
I tried doing:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost/");
SearchControls contrs = new SearchControls();
contrs.setSearchScope(SearchControls.OBJECT_SCOPE);
NamingEnumeration results = context.search("",
"(|(objectclass=*)(objectclass=ldapsubentry))", null, contrs);
while (results.hasMore())
{
System.out.println((javax.naming.directory.SearchResult)results.next());
}
But all I get is: : null:null:{objectclass=objectClass: top, OpenLDAProotDSE}
|