• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

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

发布: 2007-7-01 18:47 | 作者: admin | 来源: | 查看: 11次 | 进入软件测试论坛讨论

领测软件测试网 在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); } } }

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网