use of com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException in project APM by Cognifide.
the class AuthorizablesUtils method getAuthorizable.
public static Authorizable getAuthorizable(Context context, String id) throws ActionExecutionException, RepositoryException {
if (checkIfRemoved(context, id)) {
throw new ActionExecutionException("Authorizable with id " + id + " not found");
}
Authorizable authorizable = context.getAuthorizables().get(id);
if (authorizable == null) {
authorizable = context.getUserManager().getAuthorizable(id);
}
if (authorizable == null) {
throw new ActionExecutionException("Authorizable with id " + id + " not found");
}
context.getAuthorizables().put(id, authorizable);
return authorizable;
}
use of com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException in project APM by Cognifide.
the class AuthorizablesUtils method getGroup.
public static Group getGroup(Context context, String id) throws ActionExecutionException, RepositoryException {
if (checkIfRemoved(context, id)) {
throw new ActionExecutionException("Group with id " + id + " not found");
}
Authorizable authorizable = context.getAuthorizables().get(id);
if (authorizable == null) {
authorizable = context.getUserManager().getAuthorizable(id);
}
if (authorizable == null) {
throw new ActionExecutionException("Group with id " + id + " not found");
}
if (authorizable instanceof User) {
throw new ActionExecutionException("Authorizable with id " + id + " exists but is a user not a group");
}
context.getAuthorizables().put(id, authorizable);
return (Group) authorizable;
}
use of com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException in project APM by Cognifide.
the class AddToGroup method process.
private ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = new ActionResult();
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 = AuthorizablesUtils.getGroup(context, 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.cq.cqsm.api.exceptions.ActionExecutionException 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.api.exceptions.ActionExecutionException in project APM by Cognifide.
the class CheckIncludes method checkMembers.
private boolean checkMembers(final Context context, final ActionResult actionResult, final Group authorizable, final List<String> errors) {
boolean checkFailed = false;
for (String id : groupIds) {
try {
Authorizable group = AuthorizablesUtils.getAuthorizable(context, id);
if (!authorizable.isMember(group)) {
actionResult.logError(id + " is excluded from group " + authorizableId);
checkFailed = true;
}
actionResult.logMessage(id + " is a member of group " + authorizableId);
} catch (RepositoryException | ActionExecutionException e) {
errors.add(MessagingUtils.createMessage(e));
}
}
return checkFailed;
}
Aggregations