use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class UserDAO method findUsers.
/**
* @param user
* @return
* @throws FinderException
*/
List<User> findUsers(User user) throws FinderException {
List<User> userList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(user.getContextId(), GlobalIds.USER_ROOT);
try {
// String filter;
StringBuilder filterbuf = new StringBuilder();
if (StringUtils.isNotEmpty(user.getUserId())) {
// place a wild card after the input userId:
String searchVal = encodeSafeText(user.getUserId(), GlobalIds.USERID_LEN);
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("*))");
} else if (StringUtils.isNotEmpty(user.getInternalId())) {
// internalUserId search
String searchVal = encodeSafeText(user.getInternalId(), GlobalIds.USERID_LEN);
// this is not a wildcard search. Must be exact match.
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(Config.getInstance().getProperty(USER_OBJECT_CLASS));
filterbuf.append(")(");
filterbuf.append(GlobalIds.FT_IID);
filterbuf.append("=");
filterbuf.append(searchVal);
filterbuf.append("))");
} else {
// Beware - returns ALL users!!:"
filterbuf.append("(objectclass=");
filterbuf.append(Config.getInstance().getProperty(USER_OBJECT_CLASS));
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++, user.getContextId()));
}
} catch (LdapException e) {
String warning = "findUsers userRoot [" + userRoot + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "findUsers userRoot [" + userRoot + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userList;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class UserDAO method getAssignedUserIds.
/**
* @param role
* @return
* @throws FinderException
*/
List<String> getAssignedUserIds(Role role) throws FinderException {
List<String> userList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(role.getContextId(), GlobalIds.USER_ROOT);
try {
String roleVal = encodeSafeText(role.getName(), GlobalIds.USERID_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(USERS_AUX_OBJECT_CLASS_NAME);
filterbuf.append(")(");
filterbuf.append(GlobalIds.USER_ROLE_ASSIGN);
filterbuf.append("=");
filterbuf.append(roleVal);
filterbuf.append("))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), USERID_ATR, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
userList.add(unloadUser(searchResults.getEntry()));
}
} catch (LdapException e) {
String warning = "getAssignedUserIds role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "getAssignedUserIds role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userList;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class UserDAO method getAssignedUsers.
/**
* @param role
* @param roleConstraint
* @return
* @throws FinderException
*/
List<User> getAssignedUsers(Role role, RoleConstraint roleConstraint) throws FinderException {
List<User> userList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(role.getContextId(), GlobalIds.USER_ROOT);
try {
String roleVal = encodeSafeText(role.getName(), GlobalIds.USERID_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(USERS_AUX_OBJECT_CLASS_NAME);
filterbuf.append(")(");
filterbuf.append(GlobalIds.USER_ROLE_ASSIGN);
filterbuf.append("=");
filterbuf.append(roleVal);
filterbuf.append(")");
if (roleConstraint != null) {
filterbuf.append("(");
filterbuf.append(GlobalIds.USER_ROLE_DATA);
filterbuf.append("=");
filterbuf.append(roleConstraint.getRawData(new UserRole(role.getName())));
filterbuf.append(")");
}
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++, role.getContextId()));
}
} catch (LdapException e) {
String warning = "getAssignedUsers role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "getAssignedUsers role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userList;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class UserDAO method findUsers.
/**
* @param ou
* @return
* @throws FinderException
*/
List<User> findUsers(OrgUnit ou, boolean limitSize) throws FinderException {
List<User> userList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(ou.getContextId(), GlobalIds.USER_ROOT);
try {
String szOu = encodeSafeText(ou.getName(), GlobalIds.OU_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(Config.getInstance().getProperty(USER_OBJECT_CLASS));
filterbuf.append(")(");
filterbuf.append(SchemaConstants.OU_AT);
filterbuf.append("=");
filterbuf.append(szOu);
filterbuf.append("))");
int maxLimit;
if (limitSize) {
maxLimit = 10;
} else {
maxLimit = 0;
}
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), defaultAtrs, false, maxLimit);
long sequence = 0;
while (searchResults.next()) {
userList.add(unloadLdapEntry(searchResults.getEntry(), sequence++, ou.getContextId()));
}
} 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 CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userList;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class UserDAO method getAuthorizedUsers.
/**
* @param role
* @return
* @throws FinderException
*/
List<User> getAuthorizedUsers(Role role) throws FinderException {
List<User> userList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(role.getContextId(), GlobalIds.USER_ROOT);
try {
String roleVal = encodeSafeText(role.getName(), GlobalIds.USERID_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(USERS_AUX_OBJECT_CLASS_NAME);
filterbuf.append(")(");
Set<String> roles = RoleUtil.getInstance().getDescendants(role.getName(), role.getContextId());
if (CollectionUtils.isNotEmpty(roles)) {
filterbuf.append("|(");
filterbuf.append(GlobalIds.USER_ROLE_ASSIGN);
filterbuf.append("=");
filterbuf.append(roleVal);
filterbuf.append(")");
for (String uRole : roles) {
filterbuf.append("(");
filterbuf.append(GlobalIds.USER_ROLE_ASSIGN);
filterbuf.append("=");
filterbuf.append(uRole);
filterbuf.append(")");
}
filterbuf.append(")");
} else {
filterbuf.append(GlobalIds.USER_ROLE_ASSIGN);
filterbuf.append("=");
filterbuf.append(roleVal);
filterbuf.append(")");
}
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++, role.getContextId()));
}
} catch (LdapException e) {
String warning = "getAuthorizedUsers role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "getAuthorizedUsers role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userList;
}
Aggregations