Search in sources :

Example 11 with ActionResult

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

the class RemoveUser method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    List<String> errors = new ArrayList<>();
    LOGGER.info(String.format("Removing users with ids = %s", StringUtils.join(ids, ", ")));
    for (String id : ids) {
        try {
            User user = AuthorizablesUtils.getUserIfExists(context, id);
            if (user != null) {
                AuthorizablesUtils.markAuthorizableAsRemoved(context, user);
                if (execute) {
                    AuthorizablesUtils.removeUser(context, user);
                }
                actionResult.logMessage("User with id: " + id + " removed");
            }
        } 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;
}
Also used : User(org.apache.jackrabbit.api.security.user.User) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 12 with ActionResult

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

the class CheckExcludes method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    Group group = tryGetGroup(context, actionResult);
    if (group == null) {
        return actionResult;
    }
    List<String> errors = new ArrayList<>();
    boolean checkFailed = checkMembers(context, actionResult, group, errors);
    if (execute && checkFailed) {
        actionResult.logError(ActionUtils.ASSERTION_FAILED_MSG);
        return actionResult;
    }
    ActionUtils.logErrors(errors, actionResult);
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) ArrayList(java.util.ArrayList)

Example 13 with ActionResult

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

the class CheckAuthorizableExists method process.

public ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    try {
        Authorizable authorizable = null;
        if (shouldBeGroup) {
            authorizable = AuthorizablesUtils.getGroupIfExists(context, id);
        } else {
            authorizable = AuthorizablesUtils.getUserIfExists(context, id);
        }
        if (checkIfAuthIsNull(execute, actionResult, authorizable)) {
            return actionResult;
        }
        checkPath(actionResult, authorizable, execute);
    } 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 14 with ActionResult

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

the class CheckPermissions method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    try {
        final Authorizable authorizable = AuthorizablesUtils.getAuthorizable(context, authorizableId);
        final Set<Principal> authorizablesToCheck = getAuthorizablesToCheck(authorizable, context);
        final CqActions actions = new CqActions(context.getSession());
        final List<String> privilegesToCheck = preparePrivilegesToCheck();
        if (StringUtils.isBlank(glob)) {
            if (checkPermissionsForPath(authorizablesToCheck, actions, privilegesToCheck, path)) {
                logFailure(execute, actionResult, authorizable, path);
            } else {
                actionResult.logMessage("All required privileges are set for " + authorizable.getID() + " on " + path);
            }
        } else {
            checkPermissionsForGlob(context.getSession(), execute, actionResult, authorizable, authorizablesToCheck, actions, privilegesToCheck);
        }
    } catch (final PathNotFoundException e) {
        actionResult.logError("Path " + path + " not found");
    } catch (RepositoryException | ActionExecutionException | LoginException 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) CqActions(com.day.cq.security.util.CqActions) LoginException(org.apache.sling.api.resource.LoginException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException) Principal(java.security.Principal)

Example 15 with ActionResult

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

the class CheckProperty method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    try {
        Authorizable authorizable = AuthorizablesUtils.getAuthorizable(context, authorizableId);
        if (!checkIfAuthHasProperty(execute, actionResult, authorizable)) {
            return actionResult;
        }
        if (checkPropertyExists(authorizable)) {
            return actionResult;
        }
        actionResult.logError("Authorizable " + authorizableId + ": unexpected value of property: " + propertyName);
        if (execute) {
            actionResult.logError(ActionUtils.ASSERTION_FAILED_MSG);
        }
    } catch (final 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