我设计了一个应用程序,它将用户从活动目录带到MySQL数据库,并在GUI上显示他们。它还会带来用户所属的组。
所以,我的程序是这样工作的:
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上使用搜索过滤器来划分这个部分。
String filter = "(&(objectClass=User)(distinguishedName=a*"))";以此类推。在每个线程中获取用户。
请注意:读取用户属性memberOf并不提供所有组,因此我将单独获取组。
发布于 2017-02-14 20:54:12
我不是一个活动目录专家-只是想分享一些想法。
https://stackoverflow.com/questions/41737352
复制相似问题