Search in sources :

Example 6 with ActionExecutionException

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

the class RemoveProperty method process.

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

Example 7 with ActionExecutionException

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

the class ForAuthorizable method process.

public ActionResult process(final Context context) {
    ActionResult actionResult = context.createActionResult();
    try {
        if (shouldBeGroup) {
            Group group = context.getAuthorizableManager().getGroup(id);
            context.setCurrentAuthorizable(group);
            actionResult.logMessage("Group with id: " + group.getID() + " set as current authorizable");
        } else {
            User user = context.getAuthorizableManager().getUser(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.apm.api.actions.ActionResult) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 8 with ActionExecutionException

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

the class CheckAuthorizableExists method process.

public ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    try {
        Authorizable authorizable = null;
        if (shouldBeGroup) {
            authorizable = context.getAuthorizableManager().getGroupIfExists(id);
        } else {
            authorizable = context.getAuthorizableManager().getUserIfExists(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.apm.api.actions.ActionResult) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 9 with ActionExecutionException

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

the class AuthorizableManagerImpl method getAuthorizable.

private <T extends Authorizable> T getAuthorizable(Class<T> authorizableClass, String id) throws ActionExecutionException, RepositoryException {
    if (checkIfRemoved(id)) {
        throw new ActionExecutionException(format("%s with id %s not found", authorizableClass.getSimpleName(), id));
    }
    Authorizable authorizable = existingAuthorizables.get(id);
    if (authorizable == null) {
        authorizable = userManager.getAuthorizable(id);
    }
    if (authorizable == null) {
        throw new ActionExecutionException(format("%s with id %s not found", authorizableClass.getSimpleName(), id));
    }
    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 10 with ActionExecutionException

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

the class CheckIncludes method checkMembers.

private boolean checkMembers(final Context context, final ActionResult actionResult, final Group authorizable, final List<String> errors) {
    boolean checkFailed = false;
    for (String id : groupIds) {
        try {
            Authorizable group = context.getAuthorizableManager().getAuthorizable(id);
            if (!authorizable.isMember(group)) {
                actionResult.logError(id + " is excluded from group " + authorizableId);
                checkFailed = true;
            }
            actionResult.logMessage(id + " is a member of group " + authorizableId);
        } catch (RepositoryException | ActionExecutionException e) {
            errors.add(MessagingUtils.createMessage(e));
        }
    }
    return checkFailed;
}
Also used : 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