Search in sources :

Example 16 with ActionExecutionException

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

the class AddParents method process.

private 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());
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
        return actionResult;
    }
    for (String id : groupIds) {
        try {
            Group group = context.getAuthorizableManager().getGroup(id);
            if (authorizable.isGroup()) {
                ActionUtils.checkCyclicRelations(group, (Group) authorizable);
            }
            LOGGER.info(String.format("Adding Authorizable with id = %s to group with id = %s", authorizable.getID(), group.getID()));
            if (execute) {
                group.addMember(authorizable);
            }
            actionResult.logMessage(MessagingUtils.addedToGroup(authorizable.getID(), id));
        } catch (RepositoryException | ActionExecutionException e) {
            errors.add(MessagingUtils.createMessage(e));
        }
    }
    if (!errors.isEmpty()) {
        ActionUtils.logErrors(errors, actionResult);
        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 17 with ActionExecutionException

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

the class SetPassword method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    try {
        User user = context.getCurrentUser();
        actionResult.setAuthorizable(user.getID());
        LOGGER.info(String.format("Setting password for user with id = %s", user.getID()));
        if (execute) {
            user.changePassword(password);
        }
        actionResult.logMessage(MessagingUtils.newPasswordSet(user.getID()));
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : 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 18 with ActionExecutionException

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

the class SetProperty 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("Setting property %s for authorizable with id = %s", nameProperty, authorizable.getID()));
        final Value value = context.getValueFactory().createValue(valueProperty);
        if (!simulate) {
            authorizable.setProperty(nameProperty, value);
        }
        actionResult.logMessage("Property " + nameProperty + " for " + authorizable.getID() + " added vith value: " + valueProperty);
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : ActionResult(com.cognifide.apm.api.actions.ActionResult) Value(javax.jcr.Value) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 19 with ActionExecutionException

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

the class RemoveAll method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    try {
        Authorizable authorizable = context.getCurrentAuthorizable();
        actionResult.setAuthorizable(authorizable.getID());
        LOGGER.info(String.format("Removing all priveleges for authorizable with id = %s on path = %s", authorizable.getID(), path));
        if (execute) {
            removeAll(context, authorizable);
        }
        actionResult.logMessage("Removed all privileges for " + authorizable.getID() + " on " + path);
    } 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 20 with ActionExecutionException

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

the class DeleteGroup method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    List<String> errors = new ArrayList<>();
    LOGGER.info(String.format("Removing groups with ids = %s", StringUtils.join(ids, ", ")));
    for (String id : ids) {
        try {
            Group group = context.getAuthorizableManager().getGroupIfExists(id);
            if (group != null) {
                context.getAuthorizableManager().markAuthorizableAsRemoved(group);
                if (execute) {
                    context.getAuthorizableManager().removeGroup(group);
                }
                actionResult.logMessage("Group 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 : Group(org.apache.jackrabbit.api.security.user.Group) ActionResult(com.cognifide.apm.api.actions.ActionResult) ArrayList(java.util.ArrayList) 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