Search in sources :

Example 6 with ActionResult

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

the class CreateAuthorizable method process.

public ActionResult process(final Context context, boolean simulate) {
    ActionResult actionResult = context.createActionResult();
    try {
        Authorizable authorizable = context.getAuthorizableManager().getAuthorizableIfExists(id);
        LOGGER.info("Creating authorizable with id = " + id);
        if (authorizable != null) {
            logMessage(actionResult, authorizable);
        } else {
            authorizable = createStrategy.create(id, password, path, context, actionResult, simulate);
        }
        context.setCurrentAuthorizable(authorizable);
    } catch (RepositoryException 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)

Example 7 with ActionResult

use of com.cognifide.apm.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 = 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 8 with ActionResult

use of com.cognifide.apm.api.actions.ActionResult 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 9 with ActionResult

use of com.cognifide.apm.api.actions.ActionResult 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)

Example 10 with ActionResult

use of com.cognifide.apm.api.actions.ActionResult 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)

Aggregations

ActionResult (com.cognifide.apm.api.actions.ActionResult)30 RepositoryException (javax.jcr.RepositoryException)23 ActionExecutionException (com.cognifide.apm.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 Action (com.cognifide.apm.api.actions.Action)4 PathNotFoundException (javax.jcr.PathNotFoundException)3 Context (com.cognifide.apm.api.actions.Context)2 SessionSavingPolicy (com.cognifide.apm.api.actions.SessionSavingPolicy)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 SessionSavingMode (com.cognifide.apm.api.actions.SessionSavingMode)1 ActionCreationException (com.cognifide.apm.api.exceptions.ActionCreationException)1 ExecutionException (com.cognifide.apm.api.exceptions.ExecutionException)1 ActionDescriptor (com.cognifide.apm.core.actions.ActionDescriptor)1 ActionExecutor (com.cognifide.apm.core.actions.executor.ActionExecutor)1 ScriptRunner (com.cognifide.apm.core.grammar.ScriptRunner)1