使用java获取Ldap服务器版本

使用java获取Ldap服务器版本,java,ldap,openldap,Java,Ldap,Openldap,我发现了一个关于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

我发现了一个关于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服务器和版本?

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

请尝试查看我们提供的一些通常有效的方法的位置。没有一种方法可以适用于所有LDAP服务器实现

LDAP版本也太模糊了。你想要什么?还是LDAP的应用


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

您的提供商URL包含rootDSE,因此在本例中,只需从初始上下文中查找(“”)。返回rootDSE的DirContext。从中获取属性。你会在那里发现各种有趣的东西。