Posted By:
Sam_Jallad
Posted On:
Wednesday, August 29, 2001 07:08 AM
I'm trying to access MS Active Directory to validate user name & password. Since it's an Active Directory, I'm unable to use the "uid=" attribute, however, I have to use the "sAMAccountName=" attribute. Does anyone have a sample code how to use the search() method to validate the user id & password, and based on that they will be authinticated to access my app.? Thanks.. Sample code I've written: Hashtable oEnv = new Hashtable(); oEnv.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); oEnv.put(javax.naming.Context.PROVIDER_URL, m_sProviderUrl); try { oCTX = new Initia
More>>
I'm trying to access MS Active Directory to validate user name & password. Since it's an Active Directory, I'm unable to use the "uid=" attribute, however, I have to use the "sAMAccountName=" attribute.
Does anyone have a sample code how to use the search() method to validate the user id & password, and based on that they will be authinticated to access my app.?
Thanks..
Sample code I've written:
Hashtable oEnv = new Hashtable();
oEnv.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
oEnv.put(javax.naming.Context.PROVIDER_URL, m_sProviderUrl);
try {
oCTX = new InitialDirContext(oEnv);
String[] attrIDs = {"sAMAccountName"};
SearchControls ctls = new SearchControls();
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
ctls.setReturningAttributes(attrIDs);
Object DNS = null;
NamingEnumeration result = oCTX.search(m_sBaseDN, sDN, ctls);
while (result.hasMoreElements())
DNS = result.nextElement();
String Check = DNS.toString();
return true;
} catch (NamingException e) {
return false;
}
<<Less