Error when trying to do LDAP lookup in active directory

25,510

Solution 1

As the error message states you have to perform bind operation, i.e. login into the AD. Here is the LDAP Authentication tutorial from Oracle.

Solution 2

The coder should use the ldapsearch command line utility to verify that the connection can be established that the credentials for the bind DN are correct. This low-level approach will ensure that a connection can be made from the client system to the target directory server. This is a basic troubleshooting technique.

For more information, see LDAP: Programming Practices

Share:
25,510
Andreas
Author by

Andreas

Updated on July 09, 2022

Comments

  • Andreas
    Andreas almost 2 years

    I'm trying to lookup a user on a local active-directory using java.
    When I try to execute the code, I get the following error:

    Error:

    Lookup failed: javax.naming.NamingException: [LDAP: error code 1 - 000004DC: Lda pErr: DSID-0C0906DC, comment: In order to perform this operation a successful bi nd must be completed on the connection., data 0, v1db1 ]; remaining name: 'CN= John Doe, OU=Accounts'

    Could anyone tell me what I'm doing wrong?

    My code:

    import java.util.Hashtable;    
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.naming.ldap.LdapContext;
    
    /**
     * Demonstrates how to look up an object.
     * 
     * usage: java Lookup
     */
    class Lookup {
        public static void main(String[] args) {
    
            // Set up the environment for creating the initial context
            Hashtable env = new Hashtable(11);
            env.put(Context.INITIAL_CONTEXT_FACTORY,
                    "com.sun.jndi.ldap.LdapCtxFactory");
            env.put(Context.PROVIDER_URL,
                    "ldap://localhost:389/DC=PORTAL-UAT,DC=COMPANY,DC=COM");
    
            try {
                // Create the initial context
                Context ctx = new InitialContext(env);
    
                // Perform lookup and cast to target type
                LdapContext b = (LdapContext) ctx
                        .lookup("CN=John Doe,OU=Accounts");
    
                System.out.println(b);
    
                // Close the context
                ctx.close();
            } catch (NamingException e) {
                System.out.println("Lookup failed: " + e);
            }
        }
    }