快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

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); }}}





返回类别: 教程
上一教程: JAVA代码编写的30条建议
下一教程: JAVA写的四则混合运算

您可以阅读与"java 调用ActiveDirectory,使用标准的LDAP协议"相关的教程:
· 全面挖掘Java Excel API 使用方式(2)
· 利用Java调用可执行命令
· Java Swing中使用双击事件
· Java串行端口技术协议
· Java keytool工具的作用及使用方式[zz]
    微笑服务 优质保证 索取样品