use of org.apache.directory.fortress.core.FinderException 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.fortress.core.FinderException in project directory-fortress-core by apache.
the class PermDAO method revoke.
/**
* @param pOp
* @param user
* @throws org.apache.directory.fortress.core.UpdateException
*
* @throws org.apache.directory.fortress.core.FinderException
*/
void revoke(Permission pOp, User user) throws UpdateException, FinderException {
LdapConnection ld = null;
String dn = getDn(pOp, pOp.getContextId());
try {
List<Modification> mods = new ArrayList<Modification>();
mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, USERS, user.getUserId()));
ld = getAdminConnection();
modify(ld, dn, mods, pOp);
} catch (LdapNoSuchAttributeException e) {
String warning = "revoke perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] userId [" + user.getUserId() + "] assignment does not exist.";
throw new FinderException(GlobalErrIds.PERM_USER_NOT_EXIST, warning);
} catch (LdapException e) {
String error = "revoke perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] userId [" + user.getUserId() + "] caught LdapException=" + e.getMessage();
throw new UpdateException(GlobalErrIds.PERM_REVOKE_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
}
use of org.apache.directory.fortress.core.FinderException 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;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class PermDAO method findPermissions.
/**
* Search will return a list of matching permissions that are assigned to a given RBAC or Admin role name.
* Will search the Admin perms if the "isAdmin" boolean flag is "true", otherwise it will search RBAC perm tree.
*
* @param role contains the RBAC or Admin Role name targeted for search.
* @param noInheritance if true will NOT include inherited roles in the search.
* @return List of type Permission containing fully populated matching Permission entities.
* @throws org.apache.directory.fortress.core.FinderException in the event of DAO search error.
*/
List<Permission> findPermissions(Role role, boolean noInheritance) throws FinderException {
List<Permission> permList = new ArrayList<>();
LdapConnection ld = null;
String permRoot;
boolean isAdmin = false;
if (role.getClass().equals(AdminRole.class)) {
permRoot = getRootDn(role.getContextId(), GlobalIds.ADMIN_PERM_ROOT);
isAdmin = true;
} else {
permRoot = getRootDn(role.getContextId(), GlobalIds.PERM_ROOT);
}
try {
String roleVal = encodeSafeText(role.getName(), GlobalIds.ROLE_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(PERM_OP_OBJECT_CLASS_NAME);
filterbuf.append(")(");
Set<String> roles = null;
if (!noInheritance) {
if (role.getClass().equals(AdminRole.class)) {
roles = AdminRoleUtil.getAscendants(role.getName(), role.getContextId());
} else {
roles = RoleUtil.getInstance().getAscendants(role.getName(), role.getContextId());
}
}
if (CollectionUtils.isNotEmpty(roles)) {
filterbuf.append("|(");
filterbuf.append(ROLES);
filterbuf.append("=");
filterbuf.append(roleVal);
filterbuf.append(")");
for (String uRole : roles) {
filterbuf.append("(");
filterbuf.append(ROLES);
filterbuf.append("=");
filterbuf.append(uRole);
filterbuf.append(")");
}
filterbuf.append(")");
} else {
filterbuf.append(ROLES);
filterbuf.append("=");
filterbuf.append(roleVal);
filterbuf.append(")");
}
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++, isAdmin));
}
} catch (LdapException e) {
String error = "findPermissions caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_ROLE_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findPermissions caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_ROLE_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return permList;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class PermDAO method findPermissions.
/**
* @param ou
* @return
* @throws FinderException
*/
List<PermObj> findPermissions(OrgUnit ou, boolean limitSize) throws FinderException {
List<PermObj> permList = new ArrayList<>();
LdapConnection ld = null;
String permRoot = getRootDn(ou.getContextId(), GlobalIds.PERM_ROOT);
try {
String ouVal = encodeSafeText(ou.getName(), GlobalIds.OU_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(PERM_OBJ_OBJECT_CLASS_NAME);
filterbuf.append(")(");
filterbuf.append(SchemaConstants.OU_AT);
filterbuf.append("=");
filterbuf.append(ouVal);
filterbuf.append("*))");
int maxLimit;
if (limitSize) {
maxLimit = 10;
} else {
maxLimit = 0;
}
ld = getAdminConnection();
SearchCursor searchResults = search(ld, permRoot, SearchScope.SUBTREE, filterbuf.toString(), PERMISION_OBJ_ATRS, false, maxLimit);
long sequence = 0;
while (searchResults.next()) {
permList.add(unloadPobjLdapEntry(searchResults.getEntry(), sequence++, false));
}
} catch (LdapException e) {
String error = "findPermissions caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findPermissions caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return permList;
}
Aggregations