首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在多个线程中使用JNDI为用户带来

问在多个线程中使用JNDI为用户带来
EN

Stack Overflow用户
提问于 2017-01-19 08:45:43
回答 1查看 59关注 0票数 0

我设计了一个应用程序,它将用户从活动目录带到MySQL数据库,并在GUI上显示他们。它还会带来用户所属的组。

所以,我的程序是这样工作的:

代码语言:javascript
复制
for(String domain : allConfiguredADomains)  {
    LdapContext domainCtx = getDomainCtx(domain);

    // Bring all users from this domain and store them in DB
    getAllUsersForDomain(domain, domainCtx);

    // Bring all the groups for every user
    getAllGroupsForUsersInTheDomain(domain, domainCtx)
}

void getAllUsersForDomain(String domain, LdapContext domainCtx) {
    String filter = "(objectClass=User)"

    NamingEnumeration<SearchResult> result = domainCtx.search(domain, filter, ..);
    while(result.hasMoreElements()) {
        SearchResult searchResult = (SearchResult) result.nextElement();

        // Process and store in database
        storeUserInDatabase(searchResult);
    }
}

void getAllGroupsForUsersInTheDomain(String domain, LdapContext domainCtx)  {

    List<String> userDistinguishedNames = getAllUsersFromDatabase("distinguishedName");

    for(String userDn : userDistinguishedNames) {
        String filter = "(&(objectClass=Group)(distinguishedName=" + userDn + "))";

        NamingEnumeration<SearchResult> result = domainCtx.search(domain, filter, ..);

        List<String> allGroupsOfUser = new List<String>();
        while(result.hasMoreElements()) {
            SearchResult searchResult = (SearchResult) result.nextElement();

            String groupDistinguishedName = searchResult.getAttributes().get("distinguishedName").get();
            allGroupsOfUser.add(groupDistinguishedName);
        }

        // Store them in database
        storeAllGroupsOfUserInDatabase(userDn, allGroupsOfUser);
    }
}

然而,当active目录中有太多用户时,这个应用程序会花费大量的时间。因此,我决定实现并行性(使用线程)。我在用户的distinguishedName上使用搜索过滤器来划分这个部分。

代码语言:javascript
复制
String filter = "(&(objectClass=User)(distinguishedName=a*"))";

以此类推。在每个线程中获取用户。

  • 我的表现更好,但还是不太好。有人能提出更好的办法吗?
  • 另外,我不知道如何在获取组的同时引入并行性?
  • 如果有人建议更好地使用powershell或C#,请建议,我对技术是开放的。

请注意:读取用户属性memberOf并不提供所有组,因此我将单独获取组。

EN

回答 1

Stack Overflow用户

发布于 2017-02-14 20:54:12

我不是一个活动目录专家-只是想分享一些想法。

  1. 使用字母表字母进行线程处理最多允许26个线程。您考虑过通过其他属性、组成员等创建搜索线程吗?这可能让您创建更多的线程。
  2. 检查Active Directory文档以查看是否有提高搜索性能的方法(例如,使用数据库我们可以创建索引)。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41737352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档