Search in sources :

Example 21 with ActionResult

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

the class Deny method process.

private ActionResult process(final Context context, boolean simulate) {
    ActionResult actionResult = context.createActionResult();
    try {
        Authorizable authorizable = context.getCurrentAuthorizable();
        actionResult.setAuthorizable(authorizable.getID());
        context.getSession().getNode(path);
        final PermissionActionHelper permissionActionHelper = new PermissionActionHelper(context.getValueFactory(), path, permissions, restrictions);
        LOGGER.info(String.format("Denying permissions %s for authorizable with id = %s for path = %s %s", permissions.toString(), context.getCurrentAuthorizable().getID(), path, restrictions));
        if (simulate) {
            permissionActionHelper.checkPermissions(context.getAccessControlManager());
        } else {
            permissionActionHelper.applyPermissions(context.getAccessControlManager(), authorizable.getPrincipal(), false);
        }
        actionResult.logMessage("Added deny privilege for " + authorizable.getID() + " on " + path);
        if (permissions.contains("MODIFY")) {
            List<String> globModifyPermission = new ArrayList<>();
            globModifyPermission.add("MODIFY_PAGE");
            String preparedGlob = recalculateGlob(restrictions.getGlob());
            new Deny(path, globModifyPermission, preparedGlob + "*/jcr:content*", restrictions.getNtNames(), restrictions.getItemNames(), ignoreNonExistingPaths).process(context, simulate);
        }
    } catch (final PathNotFoundException e) {
        if (ignoreNonExistingPaths) {
            actionResult.logWarning("Path " + path + " not found");
        } else {
            actionResult.logError("Path " + path + " not found");
        }
    } catch (final RepositoryException | PermissionException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : PermissionException(com.cognifide.apm.main.permissions.exceptions.PermissionException) ActionResult(com.cognifide.apm.api.actions.ActionResult) PermissionActionHelper(com.cognifide.apm.main.permissions.PermissionActionHelper) ArrayList(java.util.ArrayList) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 22 with ActionResult

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

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

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

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

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