This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 61092
    
  66

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