Hi Team, I am always getting below error when trying to connect with ldap server- error is on the below line - return new InitialLdapContext(env, null);

Below is my configuration for bind user-

private DirContext bindAsUser(String username, String password) { // TODO. add DNS lookup based on domain final String bindUrl = url; Hashtable env = new Hashtable(); env.put(Context.SECURITY_AUTHENTICATION, "simple"); String bindPrincipal = createBindPrincipal(username); // env.put(Context.SECURITY_PRINCIPAL, bindPrincipal); env.put(Context.SECURITY_PRINCIPAL, "ServerName\" + username); env.put(Context.PROVIDER_URL, bindUrl); env.put(Context.SECURITY_CREDENTIALS, password); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.OBJECT_FACTORIES, DefaultDirObjectFactory.class.getName());

    try {
        return contextFactory.createContext(env);
    }
    catch (NamingException e) {
        if ((e instanceof AuthenticationException)
                || (e instanceof OperationNotSupportedException)) {
            handleBindException(bindPrincipal, e);
            throw badCredentials(e);
        }
        else {
            throw LdapUtils.convertLdapException(e);
        }
    }
}

Comment From: jgrandja

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. We prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add a minimal sample that reproduces this issue if you feel this is a genuine bug.