Search in sources :

Example 16 with ActionExecutionException

use of com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException in project APM by Cognifide.

the class DestroyUser method simulate.

@Override
public ActionResult simulate(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.simulate(context);
        ActionResult removeFromGroupsResult = removeFromGroups.execute(context);
        ActionResult removeResult = remove.simulate(context);
        actionResult = new CompositeActionResult(purgeResult, removeFromGroupsResult, removeResult);
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult = new ActionResult();
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Action(com.cognifide.cq.cqsm.api.actions.Action) User(org.apache.jackrabbit.api.security.user.User) RemoveUser(com.cognifide.cq.cqsm.foundation.actions.removeuser.RemoveUser) CompositeActionResult(com.cognifide.cq.cqsm.foundation.actions.CompositeActionResult) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) RemoveFromGroup(com.cognifide.cq.cqsm.foundation.actions.removefromgroup.RemoveFromGroup) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException) CompositeActionResult(com.cognifide.cq.cqsm.foundation.actions.CompositeActionResult)

Example 17 with ActionExecutionException

use of com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException in project APM by Cognifide.

the class Exclude method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    Group group = null;
    try {
        group = context.getCurrentGroup();
        actionResult.setAuthorizable(group.getID());
        LOGGER.info(String.format("Removing authorizables %s from 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.getAuthorizableIfExists(context, authorizableId);
            if (authorizable == null) {
                actionResult.logWarning(MessagingUtils.authorizableNotExists(authorizableId));
                continue;
            }
            if (execute) {
                group.removeMember(authorizable);
            }
            actionResult.logMessage(MessagingUtils.removedFromGroup(authorizableId, group.getID()));
        } catch (RepositoryException e) {
            errors.add(MessagingUtils.createMessage(e));
        }
    }
    if (!errors.isEmpty()) {
        for (String error : errors) {
            actionResult.logError(error);
        }
        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 18 with ActionExecutionException

use of com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException in project APM by Cognifide.

the class ForAuthorizable method process.

public ActionResult process(final Context context) {
    ActionResult actionResult = new ActionResult();
    try {
        if (shouldBeGroup) {
            Group group = AuthorizablesUtils.getGroup(context, id);
            context.setCurrentAuthorizable(group);
            actionResult.logMessage("Group with id: " + group.getID() + " set as current authorizable");
        } else {
            User user = AuthorizablesUtils.getUser(context, id);
            context.setCurrentAuthorizable(user);
            actionResult.logMessage("User with id: " + user.getID() + " set as current authorizable");
        }
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 19 with ActionExecutionException

use of com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException in project APM by Cognifide.

the class Purge method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    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;
}
Also used : ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 20 with ActionExecutionException

use of com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException in project APM by Cognifide.

the class RemoveAll method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    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;
}
Also used : ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) 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