Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

login help  RSS feed

 
Kiran Sonaje
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I m new in JNDI.
As my company is going to apply active directories, all the applications have to use the AD's login name and password.

I try the following code for checking the user's login and password. but something is interesting...
except the "administrator" can pass the login, all the user in the AD are fail to pass the login.

So........ Did I miss some setting in AD or my code has problem?

pls help

Thanks

Regards,

Kiran sonaje



public static int chklogin(String loginName, String password)
throws Exception {
int found = 0;
Hashtable env = new Hashtable(11);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "CN=" + loginName + ", CN=users, DC=mydc");
env.put(Context.SECURITY_CREDENTIALS, password);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://:389/DC=mydc");
env.put(Context.REFERRAL, "follow");

try {
DirContext ctx = new InitialDirContext(env);
String[] sAttrIDs = new String[2];
Attributes attr = ctx.getAttributes("");
System.out.println("Domain Name:" + attr.get("name").get());
found = 1;
} catch (NamingException e) {
System.err.println("Problem getting attribute: " + e);
throw e;
} catch (Exception e) {
System.err.println("ERROR: " + e);
throw e;
}
return found;
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!