Translate

Wednesday, January 5, 2011

Authenticate from your organization AD

Created any web application and wants to authenticate from Active Directory of your organization, so that you can use your company ID to login into your application ...here are the simple steps...
Most of the organization uses Active directory with default port 389 so its a very easy task... here is a sample login code for such application :-
Login

<%@page import="javax.naming.*"%>
<%@page import="javax.naming.directory.*"%>
<%@page import="java.util.Hashtable"%>
<%@page import="javax.naming.NameClassPair" %>
< % try {
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, " ldap: // company-doamin>:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "<>@<>");
env.put(Context.SECURITY_CREDENTIALS,"<>");
DirContext ctx = new InitialDirContext(env);
ctx.close();
out.println("success");
} catch (Exception e)
{
out.println("Exception " + e);%>
< href="login.jsp">Back to login Page < /a>
< %
}
% >
P.S :- There are some extra spaces in code for example

No comments:

Post a Comment