LDAP (Apache DS) 的 JNDI SPI 提供程序

JNDI SPI provider for LDAP (Apache DS)

我试图实现一个程序来为 LDAP 执行 JNDI 查找。我看到有来自 Apache 的开源 LDAP 即:apacheds-2.0.0-M20

下面是我写的程序:

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import javax.naming.directory.InitialDirContext;

class JndiLDAPLookup {

    public static void main(String[] args) throws Exception {

        Context ctx = null;
        Object obj = null;

        try {
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
            env.put(Context.SECURITY_AUTHENTICATION,"simple");
            env.put(Context.SECURITY_PRINCIPAL,"uid=admin,ou=system");
            env.put(Context.SECURITY_CREDENTIALS,"secret");
            env.put(Context.PROVIDER_URL,"ldap://127.0.0.1:10389");
            ctx = new InitialDirContext(env);

            obj = ctx.lookup("uid=admin,ou=system");
            System.out.println("Connection Successful.");
            } catch(NamingException nex){
                 System.out.println("LDAP Connection: FAILED");
                 nex.printStackTrace();
            }
    }

}

上面的程序成功运行了,但是我有一些疑问。

服务提供者是LDAP --> apacheds-2.0.0-M20(目录服务)。

  1. env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory"); 这是否告诉我们使用 "com.sun.jndi.ldap.LdapCtxFactory" 作为 LDAP SPI 服务 API?

  2. 如果这是正确的,那么LDAP SPI服务不是应该由Apache本身提供,因为我使用了Apache的LDAP吗?

  3. "com.sun.jndi.ldap.LdapCtxFactory" 如何使用 Apache DS? "com.sun.jndi.ldap.LdapCtxFactory" 是 Sun/Oracle 的实现。这是否意味着任何 SPI 都可以与任何供应商的服务提供商(在这种情况下,服务提供商来自 Apache)一起工作?

The service provider is LDAP --> apacheds-2.0.0-M20 (directory service).

没有。服务提供者是 JNDI LDAP SPI。 LDAP 服务器是 ApacheDS。

  1. env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory"); Does this tell to use "com.sun.jndi.ldap.LdapCtxFactory" as the LDAP SPI service API?

是的。

  1. If this is correct, then isn't LDAP SPI service supposed to be provided by the Apache itself, because I have used the LDAP from Apache?

没有。 Apache 正在提供 LDAP 服务器的实现。 JNDI LDAP SPI 是一个 客户端。

  1. How "com.sun.jndi.ldap.LdapCtxFactory" is working with Apache DS?

因为他们都使用 LDAP 有线协议。

"com.sun.jndi.ldap.LdapCtxFactory" is the implementation from Sun/Oracle.

它是 LDAP 客户端的实现。

Does this mean that any SPI works with any vendor's service provider (in this case the service provider is from Apache)?

Apache 不是这种情况下的服务提供者。它是 LDAP 服务器。你的术语很混乱。

以上所有的意思是任何 LDAP 客户端都可以与任何 LDAP 服务器一起工作,这是任何协议定义的要点。