This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Security and the fly likes hi Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "hi " Watch "hi " New topic
Author

hi

subin john Malikayil
Greenhorn

Joined: Mar 08, 2007
Posts: 7
can any please help me with a hello world user authentication program for with microsoft AD.

i have this code with me, then how do i authenticate a user?

String user = "test";
String password = "test";
String domain = "DC=domain,DC=com"; // if your domain is domain.com
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap:///" + domain);
env.put(Context.REFERRAL, "follow");
env.put(Context.SECURITY_PRINCIPAL, "cn=" + user + ",cn=users," + domain);
env.put(Context.SECURITY_CREDENTIALS, password);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
DirContext ctx = null;
try
{
ctx = new InitialDirContext(env);
} catch (NamingException e)
{
throw new Exception("Cannot connect to Ldap server");
}
SearchControls constrains = new SearchControls();
constrains.setSearchScope(SearchControls.SUBTREE_SCOPE);
constrains.setReturningAttributes(new String[] { "sn", "mail",
"givenName", "sAMAccountName" });
NamingEnumeration results = null;
try
{
// find all users
results = ctx.search("", "(objectclass=user)", constrains);
} catch (NamingException e1)
{
throw new Exception("An Error Occured during Ldap search");
}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60740
    
  65

Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hi
 
Similar Threads
Ldap newbie
How to add a user in the Active Directory via JNDI/LDAP?
How to add a user in the Active Directory via JNDI/LDAP?
JNDI : Binding to an Active Directory Global Catalog with auser froma trusted Domain
login help