Difference between revisions of "Authenticating against Active Directory"
From MyWiki
Line 26: | Line 26: | ||
"com.sun.jndi.ldap.LdapCtxFactory"); | "com.sun.jndi.ldap.LdapCtxFactory"); | ||
env.put(Context.PROVIDER_URL, | env.put(Context.PROVIDER_URL, | ||
− | "LDAP://"+server+". | + | "LDAP://"+server+".camping.goldfinger.ac.uk:389"); //replace with your server URL/IP |
//only DIGEST-MD5 works with our Windows Active Directory | //only DIGEST-MD5 works with our Windows Active Directory | ||
env.put(Context.SECURITY_AUTHENTICATION, | env.put(Context.SECURITY_AUTHENTICATION, |
Revision as of 15:09, 29 August 2014
Code to check that user credentials are valid
package myservlets; import java.util.*; import javax.naming.*; import javax.naming.directory.*; public class QueryNewAd { public String checkPass(String SERVER, String USERNAME, String PASS){ String server = ""; String userName = ""; String pass = ""; server = SERVER; userName = USERNAME; pass = PASS; try { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "LDAP://"+server+".camping.goldfinger.ac.uk:389"); //replace with your server URL/IP //only DIGEST-MD5 works with our Windows Active Directory env.put(Context.SECURITY_AUTHENTICATION, "DIGEST-MD5"); //No other SALS worked with me env.put(Context.SECURITY_PRINCIPAL, userName); // specify the username ONLY to let Microsoft Happy env.put(Context.SECURITY_CREDENTIALS, pass); //the password DirContext ctx = new InitialDirContext(env); ctx.close(); } catch(NamingException ne) { return "fail"; } //if no exception, the user is already authenticated. return "success"; }} ~