Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'dc=server,dc=lan,cn=admin'

Tags:

java

ldap

Am new to LDAP and am trying to use it for authentication. But i keep on getting this error: Connection Successful.

[LDAP: error code 32 - No Such Object]
javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'dc=server,dc=lan,cn=admin'
    at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3112)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3033)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2840)
    at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1849)
    at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1772)
    at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:386)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:356)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:339)
    at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:267)
    at ldap.Fedora.one(Fedora.java:104)
    at ldap.Fedora.main(Fedora.java:67)

This is where i have reached so far:

    Hashtable<String, Object> env = new Hashtable<String, Object>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://localhost:389/dc=server,dc=lan");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "cn=admin,dc=server,dc=world");
    env.put(Context.SECURITY_CREDENTIALS, "william");

    DirContext context = null;

    NamingEnumeration namingEnumeration = null;
    try {
        context = new InitialDirContext(env);
        System.out.println("Connection Successful.");

        SearchControls controls = new SearchControls();
        controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        namingEnumeration = context.search("dc=server,dc=lan,cn=admin", "objectClass=posixGroup", controls);
        while (namingEnumeration.hasMore()) {
            SearchResult searchResult = (SearchResult) namingEnumeration.next();
            Attributes attributes = searchResult.getAttributes();
            Attribute attr = attributes.get("cn");
            String cn = (String) attr.get();
            System.out.println(" Person Common Name = " + cn);
        }

    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();

    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        if (namingEnumeration != null) {
            try {
                namingEnumeration.close();
            } catch (Exception e) {
            }
        }
        if (context != null) {
            try {
                context.close();
            } catch (Exception e) {
            }
        }


}
like image 327
user3278647 Avatar asked Mar 11 '16 09:03

user3278647


People also ask

What is LDAP error code 32?

Answer. LDAP error code 32 with data code 0 (data 0) can be caused by the "Defined DN does not exist". The DN, is the Distinguished name (a sequence of relative distinguished names (RDN) connected by commas): https://msdn.microsoft.com/en-us/library/windows/desktop/aa366101%28v=v…


1 Answers

The error message means that the object "dc=server,dc=lan,cn=admin" cannot be found.

Your search base should probably be "cn=admin,dc=server,dc=lan"

like image 153
Thomas Kläger Avatar answered Oct 12 '22 22:10

Thomas Kläger