« | October 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | |
| 公告 |
暂无公告... |
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); }}} |
|
回复: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 »
|