File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Security and the fly likes Getting javax.naming.AuthenticationException while connecting to LDAP server from java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Security
Bookmark "Getting javax.naming.AuthenticationException while connecting to LDAP server from java code" Watch "Getting javax.naming.AuthenticationException while connecting to LDAP server from java code" New topic
Author

Getting javax.naming.AuthenticationException while connecting to LDAP server from java code

sudipti mishra
Greenhorn

Joined: Aug 18, 2011
Posts: 2
Hi,

I am trying to connnect to LDAP server from our webapp. The webapp requests the Data from LDAP server by passing the Directorty Server account/access information.


From the java code when I try to create the InitialLdapContext by passing the environment and control

My java code looks like this:

LdapContext ctx;
try {
ctx = new InitialLdapContext(env, null);
}
catch (NamingException e) {
throw new RuntimeException(e);
}

"env" is just a HashTable with the following data that it sets based on what user enters on UI

{java.naming.provider.url=ldap://192.168.72.4:389, java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory,

java.naming.security.principal=CN=smishra,OU=ops,DC=greyhawk,DC=tonecommander,DC=com, java.naming.security.authentication=simple,

java.naming.security.credentials=password}

As soon as it try to create a InitialLdapContext in java code, it throws a AuthenticationException exception:

javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db0

I digged little bit details into it. It means invalid credentials; user name or password is incorrect.

But, I can directly login/connect/bind/search to the ldap server from command prompt using ldap.exe utility with the same information.

connect to server: 192.168.72.4:389
username:smishra
password: password

Here is what I see in LDAP server by doing a serach using the LDAP utility:

distinguished Name:CN=Sudipti Mishra,OU=Ops,DC=GreyHawk,DC=tonecommander,DC=com

I am not sure why keep on getting this error when I try to login using the Java code. Am I missing something?


Any help is greatly appreciated.

Thanks,
smishra
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting javax.naming.AuthenticationException while connecting to LDAP server from java code