use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class UserDAO method getAuthorizedUsers.
/**
* @param role
* @param limit
* @return
* @throws FinderException
*/
List<String> getAuthorizedUsers(Role role, int limit) 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, false, limit);
while (searchResults.next()) {
Entry entry = searchResults.getEntry();
userList.add(getAttribute(entry, SchemaConstants.UID_AT));
}
} 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;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class UserDAO method getUserRoles.
List<UserRole> getUserRoles(Role role, RCType rcType, String paSetName) throws FinderException {
List<UserRole> userRoleList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(role.getContextId(), GlobalIds.USER_ROOT);
try {
String roleVal = encodeSafeText(role.getName(), GlobalIds.ROLE_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(")");
filterbuf.append("(");
filterbuf.append(GlobalIds.USER_ROLE_DATA);
filterbuf.append("=");
filterbuf.append(this.getFilterForRoleConstraint(role.getName(), rcType, paSetName));
filterbuf.append(")");
filterbuf.append(")");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), defaultAtrs, false, GlobalIds.BATCH_SIZE);
while (searchResults.next()) {
userRoleList.addAll(this.unloadUserRoles(searchResults.getEntry(), getAttribute(searchResults.getEntry(), SchemaConstants.UID_AT), role.getContextId(), role.getName()));
}
} 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 userRoleList;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class PermDAO method findPermissions.
/**
* @param user
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
List<Permission> findPermissions(User user) throws FinderException {
List<Permission> permList = new ArrayList<>();
LdapConnection ld = null;
String permRoot = getRootDn(user.getContextId(), GlobalIds.PERM_ROOT);
try {
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(PERM_OP_OBJECT_CLASS_NAME);
filterbuf.append(")(|");
Set<String> roles = RoleUtil.getInstance().getInheritedRoles(user.getRoles(), user.getContextId());
if (CollectionUtils.isNotEmpty(roles)) {
for (String uRole : roles) {
filterbuf.append("(");
filterbuf.append(ROLES);
filterbuf.append("=");
filterbuf.append(encodeSafeText(uRole, GlobalIds.ROLE_LEN));
filterbuf.append(")");
}
}
filterbuf.append("(");
filterbuf.append(USERS);
filterbuf.append("=");
filterbuf.append(user.getUserId());
filterbuf.append(")))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, permRoot, SearchScope.SUBTREE, filterbuf.toString(), PERMISSION_OP_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
permList.add(unloadPopLdapEntry(searchResults.getEntry(), sequence++, false));
}
} catch (LdapException e) {
String error = "findPermissions user [" + user.getUserId() + "] caught LdapException in PermDAO.findPermissions=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_USER_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findPermissions user [" + user.getUserId() + "] caught CursorException in PermDAO.findPermissions=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_USER_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return permList;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class PermDAO method findPermissionAttributes.
Set<PermissionAttribute> findPermissionAttributes(PermissionAttributeSet paSet) throws FinderException {
Set<PermissionAttribute> paList = new HashSet<PermissionAttribute>();
LdapConnection ld = null;
String permRoot = getRootDn(paSet.getContextId());
try {
String paSetVal = encodeSafeText(paSet.getName(), GlobalIds.PERM_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(PERMISSION_ATTRIBUTE_OBJECT_CLASS_NAME);
filterbuf.append(")(");
filterbuf.append(GlobalIds.FT_PERMISSION_ATTRIBUTE_SET);
filterbuf.append("=");
filterbuf.append(paSetVal);
filterbuf.append("))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, permRoot, SearchScope.SUBTREE, filterbuf.toString(), PERMISION_ATTRIBUTE_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
paList.add(unloadPALdapEntry(searchResults.getEntry(), sequence++));
}
} catch (LdapException e) {
String error = "findPermissionAttributes caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findPermissionAttributes caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return paList;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class PermDAO method findUserPermissions.
/**
* @param user
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
List<Permission> findUserPermissions(User user) throws FinderException {
List<Permission> permList = new ArrayList<>();
LdapConnection ld = null;
String permRoot = getRootDn(user.getContextId(), GlobalIds.PERM_ROOT);
try {
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(PERM_OP_OBJECT_CLASS_NAME);
filterbuf.append(")(");
filterbuf.append(USERS);
filterbuf.append("=");
filterbuf.append(user.getUserId());
filterbuf.append("))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, permRoot, SearchScope.SUBTREE, filterbuf.toString(), PERMISSION_OP_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
permList.add(unloadPopLdapEntry(searchResults.getEntry(), sequence++, false));
}
} catch (LdapException e) {
String error = "findUserPermissions user [" + user.getUserId() + "] caught LdapException in PermDAO.findPermissions=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_USER_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findUserPermissions user [" + user.getUserId() + "] caught CursorException in PermDAO.findPermissions=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_USER_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return permList;
}
Aggregations