* @param filter the user search filter for ldap
* @return the list of users matching filter
* @throws NamingException if an LDAP naming exception occurs
*/
protected Users readUsers(DirContext dirContext,String filter, String attributeName) throws NamingException{
Users users = new Users();
NamingEnumeration<SearchResult> enSearch = null;
try{
LdapUserProperties userProps = getConfiguration().getUserProperties();
String sNameAttribute = userProps.getUserDisplayNameAttribute();
String sBaseDN = userProps.getUserSearchDIT();
String sFilter = userProps.returnUserLoginSearchFilter(filter);
if(attributeName != null){
sFilter = userProps.returnUserNewRequestSearchFilter(filter, attributeName);
}
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());
}
}
User user = new User();
user.setDistinguishedName(sDN);
user.setKey(user.getDistinguishedName());
user.setName(sName);
users.add(user);
}
}
} catch (PartialResultException pre) {
LogUtil.getLogger().finer(pre.toString());
} catch (LimitExceededException lee) {