File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes LDAP Authentication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "LDAP Authentication" Watch "LDAP Authentication" New topic

LDAP Authentication

shyam sundar reddy

Joined: Jun 05, 2003
Posts: 1
I worked on LDAP authentication , and i used the following code, but i'm getting the error, i.e
javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials] .
Pls solve this problem and provide the solution.
code is
String url="ldap://,ou=company name,o=organization name";
Hashtable environment =new Hashtable();
environment.put(Context.SECURITY_AUTHENTICATION, "simple");
environment.put(Context.SECURITY_PRINCIPAL,"CN=" + username);
DirContext dircontext=new InitialDirContext(environment);
Attributes attributes=dircontext.getAttributes("CN=" + username);
String fullname=(String) attributes.get("givenname").get();
} catch(AuthenticationException ex) {out.println(ex);}
Jayaprakash A

Joined: Jun 12, 2003
Posts: 5
What is the principal you are passing? It has to be the dn without the prefix "dn="
But I have seen this error only when the password is wrong. What's the LDAP server you are using? Also check passing an empty string for password.

<b>Jayaprakash A</b>
I agree. Here's the link:
subject: LDAP Authentication
It's not a secret anymore!