JNDI, LDAP, and Active Directory
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

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

Re: JNDI, LDAP, and Active Directory

Posted By:   Kian_Parsee  
Posted On:   Wednesday, September 19, 2001 06:58 AM

You need to provide your credentials to ADSI. before creating the InitialDirContext, try the following:


oEnv.put(Context.SECURITY_AUTHENTICATION,"simple");

oEnv.put(Context.SECURITY_PRINCIPAL, "USERName");

oEnv.put(Context.SECURITY_CREDENTIALS, "Password");
About | Sitemap | Contact