我来我网
https://5come5.cn
 
您尚未 登录  注册 | 菠菜 | 软件站 | 音乐站 | 邮箱1 | 邮箱2 | 风格选择 | 更多 » 
 

本页主题: Java调用ActiveDirectory,使用标准的LDAP协议 显示签名 | 打印 | 加为IE收藏 | 收藏主题 | 上一主题 | 下一主题

2004



性别: 帅哥 状态: 该用户目前不在线
等级: 品行端正
发贴: 222
威望: 0
浮云: 1107
在线等级:
注册时间: 2006-09-25
最后登陆: 2011-10-25

5come5帮你背单词 [ available /ə'veiləbl/ a. 可利用的,可得到的,有效的 ]


Java调用ActiveDirectory,使用标准的LDAP协议


在ActiveDirectory中 支持 LDAP 协议,我们可以在 Java 中使用标准的 Java JNDI API 来访问它。LDAP 服务器并非真的必须支持 JNDI API,只要支持 LDAP 协议就可以了。我们已经提供了一个简单的测试案例程序来认证一个 LDAP 服务器的识别名。一般情况下,对待 ActiveDirectory 不必与对待任何其他的 LDAP 服务器有什么不同。

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.
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 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);
}
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);
}
}
}
顶端 Posted: 2008-01-10 15:36 | [楼 主]
est





性别: 帅哥 状态: 该用户目前不在线
等级: 荣誉会员
发贴: 6578
威望: 3
浮云: 431
在线等级:
注册时间: 2006-10-14
最后登陆: 2018-07-05

5come5帮你背单词 [ fluctuation /flΛktju'eiən/ n. (物价的)波动,涨落,周期性变动,脉动 ]


跨平台的么?如果是windows only的话可以用COM
顶端 Posted: 2008-01-10 17:31 | [1 楼]
我来我网·5come5 Forum » 程序员之家

Total 0.010626(s) query 5, Time now is:05-03 15:50, Gzip enabled
Powered by PHPWind v5.3, Localized by 5come5 Tech Team, 黔ICP备16009856号