简体   繁体   English

如何通过Java代码在没有完整的CN / DN的情况下与Active Directory连接

[英]How to connect with Active Directory without a full CN/DN from Java code

I have implemented method: 我已经实现了方法:

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;
}

I do not know the full CN/DN string. 我不知道完整的CN / DN字符串。 I only pass the name of a user (fe Tom) and password. 我只传递用户名(fe Tom)和密码。

I have no info about groups etc.. 我没有有关团体等的信息。

Thank you in advance! 先感谢您!

Search for the entry using what information you have. 使用您拥有的信息搜索条目。 The search result will contain the number of entries that matched the search and the DN of each entry that matched, therefore the search should be as restrictive as possible in order to return just the one entry for which you're looking. 搜索结果将包含与搜索匹配的条目数以及与之匹配的每个条目的DN,因此,搜索应尽可能严格,以便仅返回您要查找的一个条目。 Then use that DN to BIND to the server, 然后使用该DN绑定到服务器,

What Terry said. 特里怎么说 We have an example of performing Basic JNDI Search with Administration Account 我们有一个使用管理帐户执行基本JNDI搜索的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM