use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class UserDAO method findUsers.
/**
* @param user
* @param limit
* @return
* @throws FinderException
*/
List<String> findUsers(User user, int limit) throws FinderException {
List<String> userList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(user.getContextId(), GlobalIds.USER_ROOT);
try {
String searchVal = encodeSafeText(user.getUserId(), GlobalIds.USERID_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(Config.getInstance().getProperty(USER_OBJECT_CLASS));
filterbuf.append(")(");
filterbuf.append(SchemaConstants.UID_AT);
filterbuf.append("=");
filterbuf.append(searchVal);
filterbuf.append("*))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), USERID, false, limit);
while (searchResults.next()) {
Entry entry = searchResults.getEntry();
userList.add(getAttribute(entry, SchemaConstants.UID_AT));
}
} catch (LdapException e) {
String warning = "findUsers caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "findUsers caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userList;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class UserDAO method getAssignedUsers.
/**
* @param roles
* @return
* @throws FinderException
*/
Set<String> getAssignedUsers(Set<String> roles, String contextId) throws FinderException {
Set<String> userSet = new HashSet<>();
LdapConnection ld = null;
String userRoot = getRootDn(contextId, GlobalIds.USER_ROOT);
try {
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(USERS_AUX_OBJECT_CLASS_NAME);
filterbuf.append(")(|");
if (CollectionUtils.isNotEmpty(roles)) {
for (String roleVal : roles) {
String filteredVal = encodeSafeText(roleVal, GlobalIds.USERID_LEN);
filterbuf.append("(");
filterbuf.append(GlobalIds.USER_ROLE_ASSIGN);
filterbuf.append("=");
filterbuf.append(filteredVal);
filterbuf.append(")");
}
} else {
return null;
}
filterbuf.append("))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), USERID_ATRS, false, GlobalIds.BATCH_SIZE);
while (searchResults.next()) {
userSet.add(getAttribute(searchResults.getEntry(), SchemaConstants.UID_AT));
}
} catch (LdapException e) {
String warning = "getAssignedUsers caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "getAssignedUsers caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userSet;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class UserDAO method getUserAdminRoles.
/**
* @param user
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
List<UserAdminRole> getUserAdminRoles(User user) throws FinderException {
List<UserAdminRole> roles = null;
LdapConnection ld = null;
String userDn = getDn(user.getUserId(), user.getContextId());
try {
ld = getAdminConnection();
Entry findEntry = read(ld, userDn, AROLE_ATR);
roles = unloadUserAdminRoles(findEntry, user.getUserId(), user.getContextId());
} catch (LdapNoSuchObjectException e) {
String warning = "getUserAdminRoles COULD NOT FIND ENTRY for user [" + user.getUserId() + "]";
throw new FinderException(GlobalErrIds.USER_NOT_FOUND, warning);
} catch (LdapException e) {
String error = "getUserAdminRoles [" + userDn + "]= caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_READ_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return roles;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class UserDAO method findUsersList.
/**
* @param searchVal
* @return
* @throws FinderException
*/
List<String> findUsersList(String searchVal, String contextId) throws FinderException {
List<String> userList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(contextId, GlobalIds.USER_ROOT);
try {
searchVal = encodeSafeText(searchVal, GlobalIds.USERID_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(Config.getInstance().getProperty(USER_OBJECT_CLASS));
filterbuf.append(")(");
filterbuf.append(SchemaConstants.UID_AT);
filterbuf.append("=");
filterbuf.append(searchVal);
filterbuf.append("*))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), defaultAtrs, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
userList.add((unloadLdapEntry(searchResults.getEntry(), sequence++, contextId)).getUserId());
}
} catch (LdapException e) {
String warning = "findUsersList caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "findUsersList caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userList;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class UserDAO method getRoles.
/**
* @param user
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
List<String> getRoles(User user) throws FinderException {
List<String> roles = null;
LdapConnection ld = null;
String userDn = getDn(user.getUserId(), user.getContextId());
try {
ld = getAdminConnection();
Entry findEntry = read(ld, userDn, ROLES);
if (findEntry == null) {
String warning = "getRoles userId [" + user.getUserId() + "] not found, Fortress rc=" + GlobalErrIds.USER_NOT_FOUND;
throw new FinderException(GlobalErrIds.USER_NOT_FOUND, warning);
}
roles = getAttributes(findEntry, GlobalIds.USER_ROLE_ASSIGN);
} catch (LdapNoSuchObjectException e) {
String warning = "getRoles COULD NOT FIND ENTRY for user [" + user.getUserId() + "]";
throw new FinderException(GlobalErrIds.USER_NOT_FOUND, warning);
} catch (LdapException e) {
String error = "getRoles [" + userDn + "]= caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return roles;
}
Aggregations