Search in sources :

Example 6 with ActionResult

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

the class Deny 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("Denying 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(), false);
        }
        actionResult.logMessage("Added deny privilege for " + authorizable.getID() + " on " + path);
        if (permissions.contains("MODIFY")) {
            List<String> globModifyPermission = new ArrayList<>();
            globModifyPermission.add("MODIFY_PAGE");
            String preparedGlob = "";
            if (!StringUtils.isBlank(glob)) {
                preparedGlob = glob;
                if (StringUtils.endsWith(glob, "*")) {
                    preparedGlob = StringUtils.substring(glob, 0, StringUtils.lastIndexOf(glob, '*'));
                }
            }
            new Deny(path, preparedGlob + "*/jcr:content*", ignoreUnexistingPaths, globModifyPermission).process(context, simulate);
        }
    } catch (final PathNotFoundException e) {
        if (ignoreUnexistingPaths) {
            actionResult.logWarning("Path " + path + " not found");
        } else {
            actionResult.logError("Path " + path + " not found");
        }
    } catch (final 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) ArrayList(java.util.ArrayList) 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 7 with ActionResult

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

the class DestroyUser method execute.

@Override
public ActionResult execute(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.execute(context);
        ActionResult removeFromGroupsResult = removeFromGroups.execute(context);
        ActionResult removeResult = remove.execute(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 8 with ActionResult

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

the class Import method execute.

@Override
public ActionResult execute(Context context) {
    ActionResult actionResult = new ActionResult();
    actionResult.logMessage("Script included properly");
    return actionResult;
}
Also used : ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult)

Example 9 with ActionResult

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

the class Include method process.

private ActionResult process(Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    Group group = null;
    try {
        group = context.getCurrentGroup();
        actionResult.setAuthorizable(group.getID());
        LOGGER.info(String.format("Adding authorizables %s to 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.getAuthorizable(context, authorizableId);
            if (authorizable.isGroup()) {
                ActionUtils.checkCyclicRelations(group, (Group) authorizable);
            }
            if (execute) {
                group.addMember(authorizable);
            }
            actionResult.logMessage(MessagingUtils.addedToGroup(authorizableId, group.getID()));
        } 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 : 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 10 with ActionResult

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

the class RemoveProperty method process.

private ActionResult process(final Context context, boolean simulate) {
    ActionResult actionResult = new ActionResult();
    try {
        Authorizable authorizable = context.getCurrentAuthorizable();
        actionResult.setAuthorizable(authorizable.getID());
        LOGGER.info(String.format("Removing property %s from authorizable with id = %s", nameProperty, authorizable.getID()));
        if (!simulate) {
            authorizable.removeProperty(nameProperty);
        }
        actionResult.logMessage("Property " + nameProperty + " for " + authorizable.getID() + " removed");
    } 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