File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes LDAP authentication using ssl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic

LDAP authentication using ssl

Dharmakumar Gajendran

Joined: Feb 22, 2010
Posts: 20

I am writing a program to authenticate the login user with my organisations ldap directory. I have given the code below,

public boolean authenticate() {

String userName = "username";
String password = "password";
Hashtable<String, String> env = new Hashtable<String, String>();


env.put(Context.PROVIDER_URL, "ldap://,DC=com,DC=au");
env.put(Context.SECURITY_AUTHENTICATION, "Simple");
* Review : Please Move the domain name to the properties file.
env.put(Context.SECURITY_CREDENTIALS, password);
DirContext ctx = null;
NamingEnumeration results = null;
try {
try {
ctx = new InitialDirContext(env);

} catch (AuthenticationException authEx) {
} catch(Exception e) {

The authentication is successful with the above code. Now I am trying to authenticate with ldaps:// and using 'ssl' instead of 'simple'. But the authentication has failed and I am getting the below error.

javax.naming.AuthenticationNotSupportedException: ssl
at com.sun.jndi.ldap.sasl.LdapSasl.saslBind(
at com.sun.jndi.ldap.LdapClient.authenticate(
at com.sun.jndi.ldap.LdapCtx.connect(
at com.sun.jndi.ldap.LdapCtx.<init>(
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(
at javax.naming.spi.NamingManager.getInitialContext(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.init(
at javax.naming.InitialContext.<init>(
at SimpleLdapClient.authenticate(
at SimpleLdapClient.main(

Can any one please help to resolve this issue.

Thanks in advance.
Henry Wong

Joined: Sep 28, 2004
Posts: 20521

duplicate topic... CarefullyChooseOneForum

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: LDAP authentication using ssl
It's not a secret anymore!