Code copied here if you cannot access it
I haven't compiled or checked code but with some modification it should work or at least it can provide guidelines to make something similar
@gagrani if imported library is not in java by default then install/get it
Servlet Code to authenticate the Users in LDAP:
import netscape.ldap.LDAPConnection;
import netscape.ldap.LDAPSearchResults;
import netscape.ldap.LDAPAttribute;
import netscape.ldap.LDAPAttributeSet;
import netscape.ldap.LDAPEntry;
import netscape.ldap.LDAPException;
import java.util.Vector;
public java.util.Hashtable AuthenticateUser(String strUName, String strPwd) throws LDAPException
{
LDAPConnection oLDAPConn = null;
LDAPSearchResults oLDAPSearchRes = null;
LDAPAttribute ldapAttr = null;
LDAPAttributeSet ldapAttrset = null;
LDAPEntry ldapEntry = null;
java.util.Hashtable hAttributes = new java.util.Hashtable();
try
{
oLDAPConn = new LDAPConnection();
oLDAPConn.connect(LDAP_SERVER,LDAP_SERVER_PORT);
oLDAPConn.authenticate(LDAP_DIRMANAGER,LDAP_DIRMGRPWD);
strLDAPBase = "dc=XXX";
strUser = "(uid=" +strUName+")";
oLDAPSearchRes = oLDAPConn.search(strLDAPBase,LDAPConnection.SCOPE_SUB,strUser, null, false);
if(oLDAPSearchRes != null)
{
if( oLDAPSearchRes.hasMoreElements() && oLDAPSearchRes.getCount() > 0)
{
java.util.Enumeration enum = null;
ldapEntry = oLDAPSearchRes.next();
oLDAPConn.bind(ldapEntry.getDN(),strPwd);
for(int i = 0; i < strAttributes.length; i++)
{
ldapAttr = ldapEntry.getAttribute(strAttributes[i]);
if(ldapAttr != null)
{
enum = ldapAttr.getStringValues();
String strTemp = (String)enum.nextElement();
hAttributes.put(ldapAttr.getName(),strTemp);
}
else if(ldapAttr == null)
{
hAttributes.put(strAttributes[i]," ");
}
}
enum = null;
}
}
oLDAPSearchRes = null;
ldapEntry = null;
ldapAttr = null;
}
catch (LDAPException e)
{
System.out.println("Exception occured in LDAP AuthenticateUser Method : " + e);
}
finally
{
if(oLDAPConn.isConnected())
{
oLDAPConn.disconnect();
oLDAPConn = null;
}
}
return hAttributes;
}// End of the AuthenticateUser method.
01/10/03 05:18 AM, ID: 9466006
you need to give your own values for the following in the above code:
LDAP_SERVER
LDAP_SERVER_PORT,
LDAP_DIRMANAGER,
LDAP_DIRMGRPWD,
"dc=XXX"
Regards,
Pravarakhya
Hope this helps :)
--
Smit Patel | Junior
Undergraduate | Computer Science &
Engineering | IIT
Bombay