use of com.cognifide.apm.main.permissions.PermissionActionHelper in project APM by Cognifide.
the class Allow method process.
private ActionResult process(final Context context, boolean simulate) {
ActionResult actionResult = context.createActionResult();
try {
Authorizable authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
context.getSession().getNode(path);
final PermissionActionHelper permissionActionHelper = new PermissionActionHelper(context.getValueFactory(), path, permissions, restrictions);
LOGGER.info(String.format("Adding permissions %s for authorizable with id = %s for path = %s %s", permissions.toString(), context.getCurrentAuthorizable().getID(), path, restrictions));
if (simulate) {
permissionActionHelper.checkPermissions(context.getAccessControlManager());
} else {
permissionActionHelper.applyPermissions(context.getAccessControlManager(), authorizable.getPrincipal(), true);
}
actionResult.logMessage("Added allow privilege for " + authorizable.getID() + " on " + path);
if (permissions.contains("MODIFY")) {
String preparedGlob = recalculateGlob(restrictions.getGlob());
new Allow(path, Collections.singletonList("MODIFY_PAGE"), preparedGlob + "*/jcr:content*", restrictions.getNtNames(), restrictions.getItemNames(), ignoreNonExistingPaths).process(context, simulate);
}
} catch (final PathNotFoundException e) {
if (ignoreNonExistingPaths) {
actionResult.logWarning("Path " + path + " not found");
} else {
actionResult.logError("Path " + path + " not found");
return actionResult;
}
} catch (RepositoryException | PermissionException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
use of com.cognifide.apm.main.permissions.PermissionActionHelper in project APM by Cognifide.
the class Deny method process.
private ActionResult process(final Context context, boolean simulate) {
ActionResult actionResult = context.createActionResult();
try {
Authorizable authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
context.getSession().getNode(path);
final PermissionActionHelper permissionActionHelper = new PermissionActionHelper(context.getValueFactory(), path, permissions, restrictions);
LOGGER.info(String.format("Denying permissions %s for authorizable with id = %s for path = %s %s", permissions.toString(), context.getCurrentAuthorizable().getID(), path, restrictions));
if (simulate) {
permissionActionHelper.checkPermissions(context.getAccessControlManager());
} else {
permissionActionHelper.applyPermissions(context.getAccessControlManager(), authorizable.getPrincipal(), false);
}
actionResult.logMessage("Added deny privilege for " + authorizable.getID() + " on " + path);
if (permissions.contains("MODIFY")) {
List<String> globModifyPermission = new ArrayList<>();
globModifyPermission.add("MODIFY_PAGE");
String preparedGlob = recalculateGlob(restrictions.getGlob());
new Deny(path, globModifyPermission, preparedGlob + "*/jcr:content*", restrictions.getNtNames(), restrictions.getItemNames(), ignoreNonExistingPaths).process(context, simulate);
}
} catch (final PathNotFoundException e) {
if (ignoreNonExistingPaths) {
actionResult.logWarning("Path " + path + " not found");
} else {
actionResult.logError("Path " + path + " not found");
}
} catch (final RepositoryException | PermissionException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
Aggregations