jay liu jay liu - 1 year ago 54
Java Question

how to use java to query LDAP's ROOTDSE

in c#, only two line need to achieve this:

DirectoryEntry rootDSE = new DirectoryEntry(string.Format("LDAP://{0}/RootDSE", dnsDomainName));
string configurationNamingContext = rootDSE.Properties["configurationNamingContext"][0].ToString();

how to do this in java world?

Answer Source

figured it out by using Spring LDAP, the LDAP URL cannot add RootDSE postfix: LDAP://{domain name}, then use wildcard search:

    LdapTemplate template = new LdapTemplate(ldapContextSource);
    String returnedAtts[] = { "configurationNamingContext" };
    SearchControls controls = new SearchControls(SearchControls.OBJECT_SCOPE,0,0,returnedAtts,false,false);

    LikeFilter  filter = new LikeFilter ("objectClass", "*");
    List<String> result = template.search("", filter.encode(), controls, new AttributesMapper<String>() {
        public String mapFromAttributes(Attributes attrs)
                throws NamingException {
                return attrs.get("configurationNamingContext").get().toString();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download