【发布时间】:2014-06-18 11:31:14
【问题描述】:
我已经在默认端口 389 上安装了损坏的开放 LDAP, 我想搜索目录中的所有人,我正在使用我在这个网站上找到的代码
final String ldapAdServer = "ldap://";
final String ldapSearchBase = "ou=People,dc=maxcrc,dc=com";
final String ldapUsername = "Manager";
final String ldapPassword = "secret";
final String ldapAccountToLookup = "*";
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.SECURITY_AUTHENTICATION, "simple");
if(ldapUsername != null) {
env.put(Context.SECURITY_PRINCIPAL, ldapUsername);
}
if(ldapPassword != null) {
env.put(Context.SECURITY_CREDENTIALS, ldapPassword);
}
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapAdServer);
//ensures that objectSID attribute values
//will be returned as a byte[] instead of a String
env.put("java.naming.ldap.attributes.binary", "objectSID");
// the following is helpful in debugging errors
//env.put("com.sun.jndi.ldap.trace.ber", System.err);
Context ctx = new InitialContext(env);
LdapContext ctxLap = new InitialLdapContext();
但出现类似
的错误Exception in thread "main" javax.naming.InvalidNameException: [LDAP: error code 34 - invalid DN]
我认为这是主机名的问题,我无法正确找到它如何找到我需要连接的 url?
【问题讨论】:
-
如果您使用的是 Mac,请确保您的 build.xml 文件中没有任何
&quot;
标签: ldap