use of com.cognifide.cq.cqsm.foundation.permissions.PermissionActionHelper in project APM by Cognifide.
the class Allow method process.
private ActionResult process(final Context context, boolean simulate) {
ActionResult actionResult = new ActionResult();
try {
Authorizable authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
context.getSession().getNode(path);
final PermissionActionHelper permissionActionHelper = new PermissionActionHelper(context.getValueFactory(), path, glob, permissions);
LOGGER.info(String.format("Adding permissions %s for authorizable with id = %s for path = %s %s", permissions.toString(), context.getCurrentAuthorizable().getID(), path, StringUtils.isEmpty(glob) ? "" : ("glob = " + glob)));
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 = "";
if (!StringUtils.isBlank(glob)) {
preparedGlob = glob;
if (StringUtils.endsWith(glob, "*")) {
preparedGlob = StringUtils.substring(glob, 0, StringUtils.lastIndexOf(glob, '*'));
}
}
new Allow(path, preparedGlob + "*/jcr:content*", ignoreInexistingPaths, Collections.singletonList("MODIFY_PAGE")).process(context, simulate);
}
} catch (final PathNotFoundException e) {
if (ignoreInexistingPaths) {
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.cq.cqsm.foundation.permissions.PermissionActionHelper in project APM by Cognifide.
the class Deny method process.
private ActionResult process(final Context context, boolean simulate) {
ActionResult actionResult = new ActionResult();
try {
Authorizable authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
context.getSession().getNode(path);
final PermissionActionHelper permissionActionHelper = new PermissionActionHelper(context.getValueFactory(), path, glob, permissions);
LOGGER.info(String.format("Denying permissions %s for authorizable with id = %s for path = %s %s", permissions.toString(), context.getCurrentAuthorizable().getID(), path, StringUtils.isEmpty(glob) ? "" : ("glob = " + glob)));
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 = "";
if (!StringUtils.isBlank(glob)) {
preparedGlob = glob;
if (StringUtils.endsWith(glob, "*")) {
preparedGlob = StringUtils.substring(glob, 0, StringUtils.lastIndexOf(glob, '*'));
}
}
new Deny(path, preparedGlob + "*/jcr:content*", ignoreUnexistingPaths, globModifyPermission).process(context, simulate);
}
} catch (final PathNotFoundException e) {
if (ignoreUnexistingPaths) {
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