How to use "User logon name" insteads of "Full name" to logon in active directory.
I would like to use the user logon name combine with password to logon into my application.
However, I've worked on and I can just logon with full name.
The following code I worked is success when I logon full name.
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=mydomain");
env.put(Context.SECURITY_CREDENTIALS, password);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://<myip>:389/DC=mydomain");
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;
}
How to change it to make it can accept "user logon name"?
Thanks a lot.
Please help.
Thanks
Regards,
Kin
-
Active Directory authentication problem (2 messages)
- Posted by: kin Yeung
- Posted on: November 03 2004 05:14 EST
Threaded Messages (2)
- Active Directory authentication problem by Michael McKelvey on November 11 2004 12:57 EST
- Active Directory authentication problem by Tim Mull?? on December 09 2004 12:25 EST
-
Active Directory authentication problem[ Go to top ]
- Posted by: Michael McKelvey
- Posted on: November 11 2004 12:57 EST
- in response to kin Yeung
Kin -
Try something like the following:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, YourLdapUrl);
env.put(Context.SECURITY_PRINCIPAL, YourDomain\YourLogonName);
env.put(Context.SECURITY_CREDENTIALS, YourPassword);
DirContext dir = new InitialDirContext(env);
- M -
Active Directory authentication problem[ Go to top ]
- Posted by: Tim Mull??
- Posted on: December 09 2004 12:25 EST
- in response to Michael McKelvey
I've also been using this one successfully.
// append the @DOMAIN_NAME onto the user
env.put(Context.SECURITY_PRINCIPAL, "USERNAME@DOMAIN_NAME");