The active| standard supports the LDAP protocol in ActiveDirectory, and we can access it using the standard Java JNDI API in Java. The LDAP server does not really have to support the JNDI API, as long as the LDAP protocol is supported. We have provided a simple test case program to authenticate an LDAP server's distinguished name. In general, the treatment of activedirectory does not have to be different from treating any other LDAP server.
Import Java.util.properties;import javax.naming.*; Import Javax.naming.directory.*;//include The JNDI in the classpath. Should use the same JDK used by WebSphere application Server.class Wasldapauth {public static void main (string[) args) {//***************** user information to is authenticated ********************************//*****************Plea SE Modify the following three properties accordingly ************ String ldaphost= "ldap://cliang1.austin.ibm.com:389"; LDAP Host + port number String DN = "cn=user1, ou=austin,o=ibm,c=us"; DN to is authenticated String password = "Security"; DN ' s password//***************** end of user information properties props = new properties (); Props.put (Context.initial_context_factory, "com.sun.jndi.ldap.LdapCtxFactory"); For WebSphere 4.0 and 5.0//props.put (Context.initial_context_factory, "com.ibm.jndi.LDAPCtxFactory"); For WebSphere 3.5 release Props.put (Context.securiTy_authentication, "simple"); Use simple authentication mechanism props.put (context.security_credentials, password); Props.put (Context.security_principal, DN); Props.put (Context.provider_url, ldaphost); Long start = System.currenttimemillis (); Long end=0; Long time = 0; try {System.out.println ("authenticating"); DirContext CTX = new InitialDirContext (props); SYSTEM.OUT.PRINTLN ("authenticated"); End = System.currenttimemillis (); Time = End-start; SYSTEM.OUT.PRINTLN ("Authentication takes =" + Time + "Millis"); SYSTEM.OUT.PRINTLN ("Successfully authenticate DN:" +DN); The catch (Exception ex) {end = System.currenttimemillis (); Time = End-start; System.out.println ("Exception is" +ex.tostring ()); Ex.printstacktrace (); SYSTEM.OUT.PRINTLN ("Authentication takes =" + Time + "Millis"); SYSTEM.OUT.PRINTLN ("Fail to authenticate DN: "+DN); }}}