Search in sources :

Example 1 with ActionExecutionException

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;
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 2 with ActionExecutionException

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;
}
Also used : MockGroup(com.cognifide.cq.cqsm.foundation.actions.MockGroup) Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) MockUser(com.cognifide.cq.cqsm.foundation.actions.MockUser) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 3 with ActionExecutionException

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;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) ArrayList(java.util.ArrayList) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 4 with ActionExecutionException

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;
}
Also used : PermissionException(com.cognifide.cq.cqsm.foundation.permissions.exceptions.PermissionException) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) PermissionActionHelper(com.cognifide.cq.cqsm.foundation.permissions.PermissionActionHelper) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 5 with ActionExecutionException

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;
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Aggregations

ActionExecutionException (com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)27 RepositoryException (javax.jcr.RepositoryException)22 ActionResult (com.cognifide.cq.cqsm.api.actions.ActionResult)21 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)21 Group (org.apache.jackrabbit.api.security.user.Group)12 User (org.apache.jackrabbit.api.security.user.User)9 ArrayList (java.util.ArrayList)7 MockGroup (com.cognifide.cq.cqsm.foundation.actions.MockGroup)4 MockUser (com.cognifide.cq.cqsm.foundation.actions.MockUser)4 PathNotFoundException (javax.jcr.PathNotFoundException)3 Action (com.cognifide.cq.cqsm.api.actions.Action)2 CompositeActionResult (com.cognifide.cq.cqsm.foundation.actions.CompositeActionResult)2 RemoveFromGroup (com.cognifide.cq.cqsm.foundation.actions.removefromgroup.RemoveFromGroup)2 RemoveUser (com.cognifide.cq.cqsm.foundation.actions.removeuser.RemoveUser)2 PermissionActionHelper (com.cognifide.cq.cqsm.foundation.permissions.PermissionActionHelper)2 PermissionException (com.cognifide.cq.cqsm.foundation.permissions.exceptions.PermissionException)2 CqActions (com.day.cq.security.util.CqActions)1 Principal (java.security.Principal)1 Value (javax.jcr.Value)1 LoginException (org.apache.sling.api.resource.LoginException)1