• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

sudipti mishra
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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://, 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,


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:
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.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!