using LDAP to authenticate login + JSP
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, March 31, 2003 04:29 AM

Hi I m using a JSP page and form based Login, to authenticate username by LDAP and JNDI. I have some sample code, this my first time using LDAP so I m not sure how it works. Here's the code that I currently have. <% if(request.getParameter("uid")!= null) { String uid = request.getParameter("uid"); String pwd = request.getParameter("pwd"); // Set up the environment for creating the initial context Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://10.1.1.199:389/o=hcfhe"); // Specify SSL env.put   More>>


Hi I m using a JSP page and form based Login, to authenticate username by LDAP and JNDI. I have some sample code, this my first time using LDAP so I m not sure how it works.

Here's the code that I currently have.





<% if(request.getParameter("uid")!= null) {
String uid = request.getParameter("uid");
String pwd = request.getParameter("pwd");

// Set up the environment for creating the initial context
Hashtable env = new Hashtable();

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://10.1.1.199:389/o=hcfhe");
// Specify SSL
env.put(Context.SECURITY_PROTOCOL, "ssl");

//Authenticate as uid and pwd.
boolean verification = false;

try {

// Create the initial context
DirContext ctx = new InitialDirContext(env);
//Perform search.
SearchControls ctls = new SearchControls();
NamingEnumeration answer = ctx.search("", "(cn="+ uid +")", ctls);
String myContext = ((SearchResult)answer.next()).getName();

//Authenticate.
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=ldap,o=hcfhe");
env.put(Context.SECURITY_CREDENTIALS, "ldapbrowse");

DirContext Authctx = new InitialDirContext(env);
authenticate = true;

ctx.close();

} catch (NamingException e) {
System.err.println("Problem getting attribute:" + e);
}
}



A) what I want to do is search for the username in the directory
if it is there I want to forward them to another page.

B) I m using apache. Do I need to add anything to the configuration.




any code example would be nice. Thanks.



   <<Less
About | Sitemap | Contact