我有两个LDAP JNDI查询,其中:如何合并两个LDAP查询/搜索 - LDAP子查询
1>人们得到属于特定群体
下面所有用户的列表是我这个
代码String group = StringUtils.isBlank(groupName) ? "*" : groupName
.endsWith("*") ? groupName : groupName + "*";
// Create the search controls
SearchControls searchCtls = new SearchControls();
// Specify the search scope
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
// specify the LDAP search filter
String searchFilter = "(&(objectClass=*)(CN=" + group + "))";
// Specify the Base for the search
// String searchBase =
// "ou=internal,ou=groups,ou=people,dc=somecomp,dc=com";
String searchBase = "";
// initialize counter to total the group members
int totalResults = 0;
// Specify the attributes to return
String returnedAtts[] = { "member" };
searchCtls.setReturningAttributes(returnedAtts);
// Search for objects using the filter
NamingEnumeration<?> answer = ctx.search(searchBase, searchFilter,
searchCtls);
2>第二获取所有属性对于给定用户标识
用户这是为所述第二查询的代码
String attrName = "uid="
+ userId
+ ","
+ (isInternal ? "ou=internal,"
: isExternal ? "ou=external,"
: LDAPServicesConstants.EMPTY_STRING)
+ "ou=people,dc=somecomp,dc=com";
Attributes attrs = ctx.getAttributes(attrName);
if (attrs != null) {
for (NamingEnumeration<?> ae = attrs.getAll(); ae.hasMore();) {
Attribute attr = (Attribute) ae.next();
String uidAttribute = attr.getID();
if (!LDAPHelperUtilities.isSystemAttribute(ctx,
uidAttribute)) {
ArrayList<String> attrValues = new ArrayList<String>();
for (NamingEnumeration<?> attrEnum = attr.getAll(); attrEnum
.hasMore(); attrValues.add(String
.valueOf(attrEnum.next()))) {
}
userAttrs.put(uidAttribute.toLowerCase(),
(String[]) attrValues
.toArray(new String[0]));
log.debug("value(s) : "
+ Arrays.asList((String[]) userAttrs
.get(uidAttribute.toLowerCase())));
}
}
我需要将这两个查询合并为一个,因为从第一个调用第二个查询是不是一个选项(它可能返回数以千计的用户)。
有没有一种方法可以让我结合这两种,并返回属性的集合的集合,每个用户
感谢您从“成员”
不回答这个问题,但肯定'objectClass = *'不是必需的,作为过滤器的一个组件。这是objectClass的“现有”过滤器,并且目录中的所有条目都至少有一个objectClass,因此该过滤器组件不是必需的,可能会导致性能问题。 –