use of com.cognifide.cq.cqsm.api.actions.ActionResult 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;
}
use of com.cognifide.cq.cqsm.api.actions.ActionResult in project APM by Cognifide.
the class DestroyUser method execute.
@Override
public ActionResult execute(Context context) throws ActionExecutionException {
ActionResult actionResult;
try {
User user = AuthorizablesUtils.getUser(context, userId);
context.setCurrentAuthorizable(user);
Action removeFromGroups = new RemoveFromGroup(getGroups(user));
ActionResult purgeResult = purge.execute(context);
ActionResult removeFromGroupsResult = removeFromGroups.execute(context);
ActionResult removeResult = remove.execute(context);
actionResult = new CompositeActionResult(purgeResult, removeFromGroupsResult, removeResult);
} catch (RepositoryException | ActionExecutionException e) {
actionResult = new ActionResult();
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
use of com.cognifide.cq.cqsm.api.actions.ActionResult in project APM by Cognifide.
the class Import method execute.
@Override
public ActionResult execute(Context context) {
ActionResult actionResult = new ActionResult();
actionResult.logMessage("Script included properly");
return actionResult;
}
use of com.cognifide.cq.cqsm.api.actions.ActionResult in project APM by Cognifide.
the class Include method process.
private ActionResult process(Context context, boolean execute) {
ActionResult actionResult = new ActionResult();
Group group = null;
try {
group = context.getCurrentGroup();
actionResult.setAuthorizable(group.getID());
LOGGER.info(String.format("Adding authorizables %s to group with id = %s", StringUtils.join(authorizableIds, ", "), group.getID()));
} catch (ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
return actionResult;
} catch (RepositoryException e) {
actionResult.logError(MessagingUtils.createMessage(e));
return actionResult;
}
List<String> errors = new ArrayList<>();
for (String authorizableId : authorizableIds) {
try {
Authorizable authorizable = AuthorizablesUtils.getAuthorizable(context, authorizableId);
if (authorizable.isGroup()) {
ActionUtils.checkCyclicRelations(group, (Group) authorizable);
}
if (execute) {
group.addMember(authorizable);
}
actionResult.logMessage(MessagingUtils.addedToGroup(authorizableId, group.getID()));
} catch (RepositoryException | ActionExecutionException e) {
errors.add(MessagingUtils.createMessage(e));
}
}
if (!errors.isEmpty()) {
for (String error : errors) {
actionResult.logError(error);
}
actionResult.logError("Execution interrupted");
}
return actionResult;
}
use of com.cognifide.cq.cqsm.api.actions.ActionResult in project APM by Cognifide.
the class RemoveProperty method process.
private ActionResult process(final Context context, boolean simulate) {
ActionResult actionResult = new ActionResult();
try {
Authorizable authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
LOGGER.info(String.format("Removing property %s from authorizable with id = %s", nameProperty, authorizable.getID()));
if (!simulate) {
authorizable.removeProperty(nameProperty);
}
actionResult.logMessage("Property " + nameProperty + " for " + authorizable.getID() + " removed");
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
Aggregations