本站首页    管理页面    写新日志    退出


«October 2025»
1234
567891011
12131415161718
19202122232425
262728293031


公告
暂无公告...

我的分类(专题)

日志更新

最新评论

留言板

链接


Blog信息
blog名称:
日志总数:19
评论数量:31
留言数量:0
访问次数:141655
建立时间:2004年12月19日




Active Directory 作为LDAP用java访问
软件技术

gecko 发表于 2005/10/13 16:23:00

问:我们的 J2EE 应用程序目前正通过我们在内部开发的 LDAPAuthentication 类访问 Domino LDAP Server 进行认证。这一 LDAPAuthentication 类将使用 JNDI API 来搜索 Domino LDAP Server。然而,我们无法使用这个 LDAPAuthentication 类来搜索 Active Directory,因为 Active Directory 不支持 JNDI API。有没有另一个 JAVA API(Active Directory 支持)可供我们用来定制 LDAPAuthentication 类以访问 Active Directory 进行认证? 答:ActiveDirectory 支持 LDAP 协议,您可以在 Java 中使用标准的 Java JNDI API 来访问它。LDAP 服务器并非真的必须支持 JNDI API,只要支持 LDAP 协议就可以了。如果您有问题,最有可能是关于您打算如何访问 ActiveDirectory 的配置问题。我已经提供了一个简单的测试案例程序来认证一个 LDAP 服务器的识别名。请确认您的 LDAPAuthentication 类与它基本相同。一般情况下,您对待 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);    }}}


阅读全文(13023) | 回复(5) | 编辑 | 精华
 


回复:Active Directory 作为LDAP用java访问
软件技术

ddd(游客)发表评论于2009/5/15 13:20:54

<a href="http://www.baidu.com">百度</a>[url=http://www.baidu.com/]百度[/url]


个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
 


回复:Active Directory 作为LDAP用java访问
软件技术

ddddddd(游客)发表评论于2009/5/15 13:20:32

百度

个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
 


回复:Active Directory 作为LDAP用java访问
软件技术

sss(游客)发表评论于2009/5/12 16:06:03

百度

个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
 


回复:Active Directory 作为LDAP用java访问
软件技术

sss(游客)发表评论于2009/5/12 16:05:46

百度

个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
 


回复:Active Directory 作为LDAP用java访问
软件技术

guzi(游客)发表评论于2007/11/25 16:40:38

非常感谢!我收藏了

个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
 


» 1 »

发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144797328 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号