【问题标题】:Get Ldap server version with java用java获取Ldap服务器版本
【发布时间】:2014-01-07 22:44:17
【问题描述】:

我发现了这个简单的 java 连接 LDAP 服务器示例:

import javax.naming.*;
import javax.naming.directory.*;

import java.util.Hashtable;

/**
 * Demonstrates how to create an initial context to an LDAP server
 * using SSL. For this example to work, JSSE must be installed and
 * configured, and the issuer of the LDAP server's certificate must 
 * be in the JSSE trust store.
 *
 * usage: java Ssl
 */
class Ssl {
    public static void main(String[] args) {
        // Set up environment for creating initial context
        Hashtable env = new Hashtable(11);
        env.put(Context.INITIAL_CONTEXT_FACTORY, 
            "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldap://localhost:636/o=JNDITutorial");

        // Specify SSL
        env.put(Context.SECURITY_PROTOCOL, "ssl");

        // Authenticate as S. User and password "mysecret"
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires, o=JNDITutorial");
        env.put(Context.SECURITY_CREDENTIALS, "mysecret");

        try {
            // Create initial context
            DirContext ctx = new InitialDirContext(env);

            System.out.println(ctx.lookup("ou=NewHires"));

            // ... do something useful with ctx

            // Close the context when we're done
            ctx.close();
        } catch (NamingException e) {
            e.printStackTrace();
        }
    }
}

有什么方法可以在我连接时获取 LDAP 服务器和版本?

【问题讨论】:

    标签: java ldap openldap


    【解决方案1】:

    尝试查看http://ldapwiki.willeke.com/wiki/Determine%20LDAP%20Server%20Vendor,我们提供了一些我们发现通常有效的方法。没有一种方法适用于所有 LDAP 服务器实现。

    另外 LDAP 版本也太模糊了。你想要:LDAPSupported Version?还是LDAP的vendorVersion

    此外,除非您与具有适当权限的帐户绑定,否则某些 rootDSE 条目可能不可用。

    【讨论】:

      【解决方案2】:

      获取rootDSE的属性。根据服务器的不同,此信息可能在其中。

      【讨论】:

      • 您的提供者 URL 包含 rootDSE,因此在这种情况下,只需从您的初始上下文中查找(“”)。这将返回 rootDSE 的 DirContext。从中获取属性。你会在那里找到各种有趣的东西。
      猜你喜欢
      • 2011-11-18
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-25
      • 1970-01-01
      相关资源
      最近更新 更多