use of com.cognifide.apm.api.actions.ActionResult 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;
}
use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.
the class AddParents method process.
private ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
List<String> errors = new ArrayList<>();
Authorizable authorizable = null;
try {
authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
return actionResult;
}
for (String id : groupIds) {
try {
Group group = context.getAuthorizableManager().getGroup(id);
if (authorizable.isGroup()) {
ActionUtils.checkCyclicRelations(group, (Group) authorizable);
}
LOGGER.info(String.format("Adding Authorizable with id = %s to group with id = %s", authorizable.getID(), group.getID()));
if (execute) {
group.addMember(authorizable);
}
actionResult.logMessage(MessagingUtils.addedToGroup(authorizable.getID(), id));
} catch (RepositoryException | ActionExecutionException e) {
errors.add(MessagingUtils.createMessage(e));
}
}
if (!errors.isEmpty()) {
ActionUtils.logErrors(errors, actionResult);
actionResult.logError("Execution interrupted");
}
return actionResult;
}
use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.
the class SetPassword method process.
private ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
try {
User user = context.getCurrentUser();
actionResult.setAuthorizable(user.getID());
LOGGER.info(String.format("Setting password for user with id = %s", user.getID()));
if (execute) {
user.changePassword(password);
}
actionResult.logMessage(MessagingUtils.newPasswordSet(user.getID()));
} catch (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 SetProperty method process.
private ActionResult process(final Context context, boolean simulate) {
ActionResult actionResult = context.createActionResult();
try {
Authorizable authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
LOGGER.info(String.format("Setting property %s for authorizable with id = %s", nameProperty, authorizable.getID()));
final Value value = context.getValueFactory().createValue(valueProperty);
if (!simulate) {
authorizable.setProperty(nameProperty, value);
}
actionResult.logMessage("Property " + nameProperty + " for " + authorizable.getID() + " added vith value: " + valueProperty);
} catch (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 RemoveAll 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("Removing all priveleges for authorizable with id = %s on path = %s", authorizable.getID(), path));
if (execute) {
removeAll(context, authorizable);
}
actionResult.logMessage("Removed all privileges for " + authorizable.getID() + " on " + path);
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
Aggregations