Apache 目录服务器 LDAP 设置

Apache Directory Server LDAP Setting

在我的组织中有 CORP 网络,我们有 LDAP 服务器,我可以通过 java 程序通过证明用户名(主体)和密码很容易地连接该服务器。下面是我的 java 连接到 org LDAP 服务器的代码。

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,  "ldap://corp.testorg.com:10389");      
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "CORP\username");
env.put(Context.SECURITY_CREDENTIALS, "password");
try
{
 DirContext ctx = new InitialDirContext(env);
 System.out.println("connected");
}

但我的问题是,我在本地计算机上通过 apache DS 创建了自己的 LDAP 服务器,然后尝试通过相同的程序连接到该本地 LDAP 服务器,然后我必须提供带有用户名的基本 dn,如下所示以下

put(Context.SECURITY_PRINCIPAL, "cn=username,ou=users,o=test")

为什么我必须提供带有用户名的基本 dn,我不明白。我是否缺少 LDAP 服务器上的某些配置,请告诉我。

SECURITY_PRINCIPAL 支持的格式在很大程度上取决于服务提供商。通常,需要用户的可分辨名称,但 Active Directory supports a couple of additional formats