Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sudipti mishra
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic