• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LDAP Authentication

 
shyam sundar reddy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,
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://192.168.1.1/CN=Recipients,ou=company name,o=organization name";
Hashtable environment =new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
environment.put(Context.PROVIDER_URL,url);
environment.put(Context.SECURITY_AUTHENTICATION, "simple");
environment.put(Context.SECURITY_PRINCIPAL,"CN=" + username);
environment.put(Context.SECURITY_CREDENTIALS,password);
try{
DirContext dircontext=new InitialDirContext(environment);
Attributes attributes=dircontext.getAttributes("CN=" + username);
String fullname=(String) attributes.get("givenname").get();
out.println(fullname);
} catch(AuthenticationException ex) {out.println(ex);}
 
Jayaprakash A
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic