Can my JSP application validate users against an LDAP server which contains the userid's and passwords for all the employees? If so, how can I connect with the LDAP server and perform this authentication?

Ivo Limmen

To be short: Yes, you can. I did it as well. Simply open a LDAP connection with the LDAP server using JNDI and use the name and password of the user you need to authenticate. JDNI will throw an eception if the user is not in the LDAP.

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, providerURL);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, fullUserName);
env.put(Context.SECURITY_CREDENTIALS, password);

DirContext ctx = new InitialDirContext(env);
If an AuthenticationException gets thrown the use is not autorized.
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact