use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.
the class CheckPermissions method process.
private ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
try {
final Authorizable authorizable = context.getAuthorizableManager().getAuthorizable(authorizableId);
final Set<Principal> authorizablesToCheck = getAuthorizablesToCheck(authorizable, context);
final CqActions actions = new CqActions(context.getSession());
final List<String> privilegesToCheck = preparePrivilegesToCheck();
if (StringUtils.isBlank(glob)) {
if (checkPermissionsForPath(authorizablesToCheck, actions, privilegesToCheck, path)) {
logFailure(execute, actionResult, authorizable, path);
} else {
actionResult.logMessage("All required privileges are set for " + authorizable.getID() + " on " + path);
}
} else {
checkPermissionsForGlob(context.getSession(), execute, actionResult, authorizable, authorizablesToCheck, actions, privilegesToCheck);
}
} catch (final PathNotFoundException e) {
actionResult.logError("Path " + path + " not found");
} catch (RepositoryException | ActionExecutionException | LoginException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.
the class CheckProperty method process.
private ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
try {
Authorizable authorizable = context.getAuthorizableManager().getAuthorizable(authorizableId);
if (!checkIfAuthHasProperty(execute, actionResult, authorizable)) {
return actionResult;
}
if (checkPropertyExists(authorizable)) {
return actionResult;
}
actionResult.logError("Authorizable " + authorizableId + ": unexpected value of property: " + propertyName);
if (execute) {
actionResult.logError(ActionUtils.ASSERTION_FAILED_MSG);
}
} catch (final RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.
the class CompositeAction method execute.
@Override
public ActionResult execute(Context context) throws ActionExecutionException {
ActionResult result = context.createActionResult();
List<ActionResult> actionResults = Lists.newArrayListWithCapacity(actions.size());
for (Action action : actions) {
actionResults.add(action.execute(context));
}
return result.merge(actionResults);
}
use of com.cognifide.apm.api.actions.ActionResult 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.api.actions.ActionResult in project APM by Cognifide.
the class Purge method process.
private ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
try {
Authorizable authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
LOGGER.info(String.format("Purging privileges for authorizable with id = %s under path = %s", authorizable.getID(), path));
if (execute) {
purge(context, actionResult);
}
actionResult.logMessage("Purged privileges for " + authorizable.getID() + " on " + path);
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
Aggregations