Search in sources :

Example 21 with ActionResult

use of com.cognifide.cq.cqsm.api.actions.ActionResult 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 22 with ActionResult

use of com.cognifide.cq.cqsm.api.actions.ActionResult 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 23 with ActionResult

use of com.cognifide.cq.cqsm.api.actions.ActionResult in project APM by Cognifide.

the class Purge method purge.

private void purge(final Context context, final ActionResult actionResult) throws RepositoryException, ActionExecutionException {
    NodeIterator iterator = getPermissions(context);
    String normalizedPath = normalizePath(path);
    while (iterator != null && iterator.hasNext()) {
        Node node = iterator.nextNode();
        if (node.hasProperty(PermissionConstants.REP_ACCESS_CONTROLLED_PATH)) {
            String parentPath = node.getProperty(PermissionConstants.REP_ACCESS_CONTROLLED_PATH).getString();
            String normalizedParentPath = normalizePath(parentPath);
            boolean isUsersPermission = parentPath.startsWith(context.getCurrentAuthorizable().getPath());
            if (StringUtils.startsWith(normalizedParentPath, normalizedPath) && !isUsersPermission) {
                RemoveAll removeAll = new RemoveAll(parentPath);
                ActionResult removeAllResult = removeAll.execute(context);
                if (Status.ERROR.equals(removeAllResult.getStatus())) {
                    actionResult.logError(removeAllResult);
                }
            }
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) Node(javax.jcr.Node) RemoveAll(com.cognifide.cq.cqsm.foundation.actions.removeall.RemoveAll)

Example 24 with ActionResult

use of com.cognifide.cq.cqsm.api.actions.ActionResult 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 25 with ActionResult

use of com.cognifide.cq.cqsm.api.actions.ActionResult 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

ActionResult (com.cognifide.cq.cqsm.api.actions.ActionResult)30 RepositoryException (javax.jcr.RepositoryException)22 ActionExecutionException (com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)21 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)16 ArrayList (java.util.ArrayList)10 Group (org.apache.jackrabbit.api.security.user.Group)10 User (org.apache.jackrabbit.api.security.user.User)5 PathNotFoundException (javax.jcr.PathNotFoundException)3 Action (com.cognifide.cq.cqsm.api.actions.Action)2 SessionSavingPolicy (com.cognifide.cq.cqsm.core.sessions.SessionSavingPolicy)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 ActionDescriptor (com.cognifide.cq.cqsm.api.actions.ActionDescriptor)1 ExecutionException (com.cognifide.cq.cqsm.api.exceptions.ExecutionException)1 Context (com.cognifide.cq.cqsm.api.executors.Context)1 Progress (com.cognifide.cq.cqsm.api.logger.Progress)1 ActionExecutor (com.cognifide.cq.cqsm.core.actions.executor.ActionExecutor)1