我已经实现了方法:
public static LdapContext buildContext(String username, String password) {
LdapContext context = null;
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);
env.put(Context.PROVIDER_URL, DOMAIN_URL);
try {
context = new InitialLdapContext(env, null);
} catch (NamingException e) {
}
return context;
}
我不知道完整的CN / DN字符串。我只传递用户名(例如Tom)和密码。
我没有有关团体等的信息。
先感谢您!
最佳答案
使用您拥有的信息搜索条目。搜索结果将包含与搜索匹配的条目数以及与之匹配的每个条目的DN,因此,搜索应尽可能严格,以便仅返回您要查找的一个条目。然后使用该DN绑定到服务器,