Search in sources :

Example 21 with ActionExecutionException

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

the class RemoveUser method process.

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

Example 22 with ActionExecutionException

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

the class RemoveChildren method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    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 = context.getAuthorizableManager().getAuthorizableIfExists(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.apm.api.actions.ActionResult) ArrayList(java.util.ArrayList) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 23 with ActionExecutionException

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

the class ClearFromGroupDetacher method detachAuthorizableFromParents.

public ActionResult detachAuthorizableFromParents() {
    ActionResult actionResult = context.createActionResult();
    try {
        Authorizable currentAuthorizable = context.getCurrentAuthorizable();
        Iterator<Group> groups = getGroupParents(actionResult, currentAuthorizable);
        LOGGER.info(String.format("Removing all memberships of authorizable with id = %s", currentAuthorizable.getID()));
        detachFromParents(actionResult, currentAuthorizable, groups);
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ActionResult(com.cognifide.apm.api.actions.ActionResult) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 24 with ActionExecutionException

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

the class ClearFromGroupDetacher method detachMembersFromGroup.

public ActionResult detachMembersFromGroup() {
    ActionResult actionResult = context.createActionResult();
    try {
        Authorizable authorizable = context.getCurrentAuthorizable();
        if (authorizable.isGroup()) {
            final Group group = context.getCurrentGroup();
            LOGGER.info(String.format("Removing all members of group with id = %s", group.getID()));
            Iterator<Authorizable> groupMembers = getGroupMembers(actionResult, group);
            detachAllMembers(actionResult, group, groupMembers);
        } else {
            actionResult.logError("Child members can only be removed from groups");
        }
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ActionResult(com.cognifide.apm.api.actions.ActionResult) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Aggregations

ActionExecutionException (com.cognifide.apm.api.exceptions.ActionExecutionException)24 RepositoryException (javax.jcr.RepositoryException)22 ActionResult (com.cognifide.apm.api.actions.ActionResult)21 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)18 Group (org.apache.jackrabbit.api.security.user.Group)8 ArrayList (java.util.ArrayList)7 User (org.apache.jackrabbit.api.security.user.User)5 PathNotFoundException (javax.jcr.PathNotFoundException)3 Action (com.cognifide.apm.api.actions.Action)2 RemoveParents (com.cognifide.apm.main.actions.removeparents.RemoveParents)2 PermissionActionHelper (com.cognifide.apm.main.permissions.PermissionActionHelper)2 PermissionException (com.cognifide.apm.main.permissions.exceptions.PermissionException)2 Context (com.cognifide.apm.api.actions.Context)1 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