* @param filter the group search filter for ldap
* @return the list of groups matching filter
* @throws NamingException if an LDAP naming exception occurs
*/
protected Groups readGroups(DirContext dirContext,String filter) throws NamingException{
Groups groups = new Groups();
NamingEnumeration<SearchResult> enSearch = null;
try{
LdapGroupProperties groupProps = getConfiguration().getGroupProperties();
String sNameAttribute = groupProps.getGroupDisplayNameAttribute();
String sBaseDN = groupProps.getGroupSearchDIT();
String sFilter = groupProps.returnGroupNameSearchFilter(filter);
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
if (sNameAttribute.length() > 0) {
String[] aReturn = new String[1];
aReturn[0] = sNameAttribute;
controls.setReturningAttributes(aReturn);
}
enSearch = dirContext.search(sBaseDN,sFilter,controls);
try {
while (enSearch.hasMore()) {
SearchResult result = (SearchResult)enSearch.next();
String sDN = buildFullDN(result.getName(),sBaseDN);
if (sDN.length() > 0) {
String sName = "";
if (sNameAttribute.length() > 0) {
Attribute attrName = result.getAttributes().get(sNameAttribute);
if ((attrName != null) && (attrName.size() > 0)) {
sName = Val.chkStr(attrName.get(0).toString());
}
}
Group group = new Group();
group.setDistinguishedName(sDN);
group.setKey(group.getDistinguishedName());
group.setName(sName);
groups.add(group);
}
}
} catch (PartialResultException pre) {
LogUtil.getLogger().finer(pre.toString());
} catch (LimitExceededException lee) {