📄 newtestldap.java
字号:
package com.ibm.introtoldap;
import java.util.Properties;
import javax.naming.*;
import javax.naming.directory.*;
//include the JNDI in the classpath. You should use the same JDK used by WebSphere Application server.
/**
* <pre>
*
* Accela Automation
* File: NewTestLDAP.java
*
* Accela, Inc.
* Copyright (C): 2008
*
* Description:
* TODO
*
* Notes:
* $Id: V360CodeTemplates.xml 72642 2007-07-10 20:01:57Z vernon.crandall NewTestLDAP.java,v 1.4 2007/05/16 07:46:52 achievo_ken_wen Exp $
*
* Revision History
* <Date>, <Who>, <What>
* 23-十二月-08 xavier.huang Initial.
*
* </pre>
*/
public class NewTestLDAP
{
public static void main(String[] args)
{
// ***************** user information to be authenticated ********************************
// *****************Please modify the following three properties accordingly ************
String ldapHost = "ldap://szsite2.achievo.com:389"; // ldap host + port number
String DN = "ou=sz,dc=achievo,dc=com"; // DN to be authenticated
String password = "fly915hx"; // DN's password
// ***************** End of user information
Properties props = new Properties();
//General
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.put(Context.PROVIDER_URL, ldapHost);
props.put(Context.URL_PKG_PREFIXES,"com.sun.jndi.url");
props.put(Context.REFERRAL, "ignore");
//props.put(Context.SECURITY_PRINCIPAL, DN);
props.put(Context.SECURITY_AUTHENTICATION, "simple"); // use simple authentication mechanism
props.put(Context.SECURITY_PRINCIPAL, "xavier.huang@achievo.com");
props.put(Context.SECURITY_CREDENTIALS, password);
//--------------------------------------------------
//specify the root password
// --------------------------------------------------
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);
Attributes Atb = ctx.getAttributes("ou=sz,dc=achievo,dc=com");
NamingEnumeration ne = Atb.getAll();
System.out.println("achievo");
while (ne.hasMore()) {
Attribute attr = (Attribute)ne.next();
System.out.println(attr);
}
}
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);
}
}
}
/*
*$Log: av-env.bat,v $
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -