0

I have installed open LDAP which is ruinning on port default port 389, i want to search all people in the directory, i am using code i found on this site

          final String ldapAdServer = "ldap://";
    final String ldapSearchBase = "ou=People,dc=maxcrc,dc=com";

    final String ldapUsername = "Manager";
    final String ldapPassword = "secret";

    final String ldapAccountToLookup = "*";


    Hashtable<String, Object> env = new Hashtable<String, Object>();
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    if(ldapUsername != null) {
        env.put(Context.SECURITY_PRINCIPAL, ldapUsername);
    }
    if(ldapPassword != null) {
        env.put(Context.SECURITY_CREDENTIALS, ldapPassword);
    }
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, ldapAdServer);

    //ensures that objectSID attribute values
    //will be returned as a byte[] instead of a String
    env.put("java.naming.ldap.attributes.binary", "objectSID");

    // the following is helpful in debugging errors
    //env.put("com.sun.jndi.ldap.trace.ber", System.err);
    Context ctx = new InitialContext(env);
    LdapContext ctxLap = new InitialLdapContext();

but getting error like

Exception in thread "main" javax.naming.InvalidNameException: [LDAP: error code 34 - invalid DN]

i think this is problem with host name ,which i am not able find correctly how can i find url to which i need to connect?

1
  • If you're on Mac make sure you don't have any &quot; in your build.xml file Commented Jun 12, 2017 at 16:06

1 Answer 1

1
Exception in thread "main" javax.naming.InvalidNameException: [LDAP: error code 34 - invalid DN]

I think this is problem with host name, which i am not able find correctly

No. It's a problem with a DN. A DN is not a hostname. If it was a hostname problem, you would get a connect exception of some kind. If you get an LDAP error code, it is proof you are connected to an LDAP server.

It's probably a problem with the Manager DN. But you shouldn't be logging in as the LDAP root account anyway. That's for OpenLDAP itself. Create another account with sufficient privilege and use that.

Sign up to request clarification or add additional context in comments.

1 Comment

if i make Context.SECURITY_AUTHENTICATION to none i get below error Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.