Search in sources :

Example 11 with ActionExecutionException

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

the class CheckPermissions method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    try {
        final Authorizable authorizable = context.getAuthorizableManager().getAuthorizable(authorizableId);
        final Set<Principal> authorizablesToCheck = getAuthorizablesToCheck(authorizable, context);
        final CqActions actions = new CqActions(context.getSession());
        final List<String> privilegesToCheck = preparePrivilegesToCheck();
        if (StringUtils.isBlank(glob)) {
            if (checkPermissionsForPath(authorizablesToCheck, actions, privilegesToCheck, path)) {
                logFailure(execute, actionResult, authorizable, path);
            } else {
                actionResult.logMessage("All required privileges are set for " + authorizable.getID() + " on " + path);
            }
        } else {
            checkPermissionsForGlob(context.getSession(), execute, actionResult, authorizable, authorizablesToCheck, actions, privilegesToCheck);
        }
    } catch (final PathNotFoundException e) {
        actionResult.logError("Path " + path + " not found");
    } catch (RepositoryException | ActionExecutionException | LoginException 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) CqActions(com.day.cq.security.util.CqActions) LoginException(org.apache.sling.api.resource.LoginException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException) Principal(java.security.Principal)

Example 12 with ActionExecutionException

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

the class CheckProperty method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    try {
        Authorizable authorizable = context.getAuthorizableManager().getAuthorizable(authorizableId);
        if (!checkIfAuthHasProperty(execute, actionResult, authorizable)) {
            return actionResult;
        }
        if (checkPropertyExists(authorizable)) {
            return actionResult;
        }
        actionResult.logError("Authorizable " + authorizableId + ": unexpected value of property: " + propertyName);
        if (execute) {
            actionResult.logError(ActionUtils.ASSERTION_FAILED_MSG);
        }
    } catch (final 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 13 with ActionExecutionException

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

the class Allow 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("Adding 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(), true);
        }
        actionResult.logMessage("Added allow privilege for " + authorizable.getID() + " on " + path);
        if (permissions.contains("MODIFY")) {
            String preparedGlob = recalculateGlob(restrictions.getGlob());
            new Allow(path, Collections.singletonList("MODIFY_PAGE"), 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");
            return actionResult;
        }
    } catch (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) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 14 with ActionExecutionException

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

the class Purge 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("Purging privileges for authorizable with id = %s under path = %s", authorizable.getID(), path));
        if (execute) {
            purge(context, actionResult);
        }
        actionResult.logMessage("Purged 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 15 with ActionExecutionException

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

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