Search in sources :

Example 1 with ActionExecutionException

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

the class AuthorizableManagerImpl method getAuthorizableIfExists.

private <T extends Authorizable> T getAuthorizableIfExists(Class<T> authorizableClass, String id) throws ActionExecutionException, RepositoryException {
    if (checkIfRemoved(id)) {
        return null;
    }
    Authorizable authorizable = existingAuthorizables.get(id);
    if (authorizable == null) {
        authorizable = userManager.getAuthorizable(id);
    }
    if (authorizable == null) {
        return null;
    }
    if (!authorizableClass.isInstance(authorizable)) {
        throw new ActionExecutionException(format("Authorizable with id %s exists but is a ", authorizableClass.getSimpleName()));
    }
    existingAuthorizables.put(id, authorizable);
    return authorizableClass.cast(authorizable);
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 2 with ActionExecutionException

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

the class AddChildren method process.

private ActionResult process(Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    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 = context.getAuthorizableManager().getAuthorizable(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.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 3 with ActionExecutionException

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

the class DestroyUser method execute.

@Override
public ActionResult execute(Context context) throws ActionExecutionException {
    ActionResult actionResult;
    try {
        User user = context.getAuthorizableManager().getUser(userId);
        // local context is used here to not override current authorizable in given context
        Context localContext = context.newContext();
        localContext.setCurrentAuthorizable(user);
        Action removeFromGroups = new RemoveParents(getGroups(user));
        ActionResult purgeResult = purge.execute(localContext);
        ActionResult removeFromGroupsResult = removeFromGroups.execute(localContext);
        ActionResult removeResult = remove.execute(localContext);
        actionResult = purgeResult.merge(removeFromGroupsResult, removeResult);
        actionResult.setAuthorizable(context.getCurrentAuthorizable().getID() + " (ignored)");
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult = context.createActionResult();
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Context(com.cognifide.apm.api.actions.Context) Action(com.cognifide.apm.api.actions.Action) User(org.apache.jackrabbit.api.security.user.User) RemoveParents(com.cognifide.apm.main.actions.removeparents.RemoveParents) ActionResult(com.cognifide.apm.api.actions.ActionResult) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 4 with ActionExecutionException

use of com.cognifide.apm.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 = context.getAuthorizableManager().getUser(userId);
        context.setCurrentAuthorizable(user);
        Action removeFromGroups = new RemoveParents(getGroups(user));
        ActionResult purgeResult = purge.simulate(context);
        ActionResult removeFromGroupsResult = removeFromGroups.execute(context);
        ActionResult removeResult = remove.simulate(context);
        actionResult = purgeResult.merge(removeFromGroupsResult, removeResult);
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult = context.createActionResult();
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Action(com.cognifide.apm.api.actions.Action) User(org.apache.jackrabbit.api.security.user.User) RemoveParents(com.cognifide.apm.main.actions.removeparents.RemoveParents) ActionResult(com.cognifide.apm.api.actions.ActionResult) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 5 with ActionExecutionException

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

the class RemoveParents method process.

public ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    List<String> errors = new ArrayList<>();
    Authorizable authorizable = null;
    try {
        authorizable = context.getCurrentAuthorizable();
        actionResult.setAuthorizable(authorizable.getID());
        LOGGER.info(String.format("Removing authorizable with id = %s from groups %s", authorizable.getID(), groupIds));
    } catch (ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
        return actionResult;
    } catch (RepositoryException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
        return actionResult;
    }
    for (String id : groupIds) {
        try {
            Group group = context.getAuthorizableManager().getGroup(id);
            if (execute) {
                group.removeMember(authorizable);
            }
            actionResult.logMessage(MessagingUtils.removedFromGroup(authorizable.getID(), id));
        } 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.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)

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