I am not able to authenticate a user using LDAP. I have got following details:
URL=ldap://10.10.10.10:389
LDAP BASE:DC=lab2,DC=ins
LDAP Bind Account: CN=Ld
Try using this, it worked for me
public static Boolean validateLogin(String userName, String userPassword) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://" + LDAP_SERVER + ":" + LDAP_SERVER_PORT + "/" + LDAP_BASE_DN);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, userName + "@" + LDAP_SERVER);
env.put(Context.SECURITY_CREDENTIALS, userPassword);
DirContext ctx;
try {
ctx = new InitialDirContext(env); //throw exception, if username-password not correct
return true;
} catch (Exception e) {
return false;
}
}