我有两个 LDAP JNDI 查询,其中:
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> 第二个获取给定用户 ID 的用户的所有属性
这是第二个查询的代码
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())));
}
}
我需要将这两个查询合并为一个,因为从第一个开始为每个 uid 调用第二个查询不是一个选项(它可能返回数千个用户)。
有没有办法可以将这两者结合起来并为每个用户返回属性集合
谢谢