The LDAP protocol is supported in ActiveDirectory. We can use the standard Java jndi api in Java to access it. The LDAP server does not really have to support the jndi api. You only need to support the LDAP protocol. We have provided a simple test case Program to authenticate the recognition name of an LDAP server. Generally, treating 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. You shoshould use the same JDK used by WebSphere Application server.
Class wasLdapAuth
{
Public static void main (String [] args)
{
// ***************** User information to be authenticated **************** ****************
// ****************** Please 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 be 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 mechanic
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 ();
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.