Search in sources :

Example 1 with PermissionActionHelper

use of com.cognifide.cq.cqsm.foundation.permissions.PermissionActionHelper in project APM by Cognifide.

the class Allow method process.

private ActionResult process(final Context context, boolean simulate) {
    ActionResult actionResult = new ActionResult();
    try {
        Authorizable authorizable = context.getCurrentAuthorizable();
        actionResult.setAuthorizable(authorizable.getID());
        context.getSession().getNode(path);
        final PermissionActionHelper permissionActionHelper = new PermissionActionHelper(context.getValueFactory(), path, glob, permissions);
        LOGGER.info(String.format("Adding permissions %s for authorizable with id = %s for path = %s %s", permissions.toString(), context.getCurrentAuthorizable().getID(), path, StringUtils.isEmpty(glob) ? "" : ("glob = " + glob)));
        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 = "";
            if (!StringUtils.isBlank(glob)) {
                preparedGlob = glob;
                if (StringUtils.endsWith(glob, "*")) {
                    preparedGlob = StringUtils.substring(glob, 0, StringUtils.lastIndexOf(glob, '*'));
                }
            }
            new Allow(path, preparedGlob + "*/jcr:content*", ignoreInexistingPaths, Collections.singletonList("MODIFY_PAGE")).process(context, simulate);
        }
    } catch (final PathNotFoundException e) {
        if (ignoreInexistingPaths) {
            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.cq.cqsm.foundation.permissions.exceptions.PermissionException) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) PermissionActionHelper(com.cognifide.cq.cqsm.foundation.permissions.PermissionActionHelper) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 2 with PermissionActionHelper

use of com.cognifide.cq.cqsm.foundation.permissions.PermissionActionHelper in project APM by Cognifide.

the class Deny method process.

private ActionResult process(final Context context, boolean simulate) {
    ActionResult actionResult = new ActionResult();
    try {
        Authorizable authorizable = context.getCurrentAuthorizable();
        actionResult.setAuthorizable(authorizable.getID());
        context.getSession().getNode(path);
        final PermissionActionHelper permissionActionHelper = new PermissionActionHelper(context.getValueFactory(), path, glob, permissions);
        LOGGER.info(String.format("Denying permissions %s for authorizable with id = %s for path = %s %s", permissions.toString(), context.getCurrentAuthorizable().getID(), path, StringUtils.isEmpty(glob) ? "" : ("glob = " + glob)));
        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 = "";
            if (!StringUtils.isBlank(glob)) {
                preparedGlob = glob;
                if (StringUtils.endsWith(glob, "*")) {
                    preparedGlob = StringUtils.substring(glob, 0, StringUtils.lastIndexOf(glob, '*'));
                }
            }
            new Deny(path, preparedGlob + "*/jcr:content*", ignoreUnexistingPaths, globModifyPermission).process(context, simulate);
        }
    } catch (final PathNotFoundException e) {
        if (ignoreUnexistingPaths) {
            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.cq.cqsm.foundation.permissions.exceptions.PermissionException) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) PermissionActionHelper(com.cognifide.cq.cqsm.foundation.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.cq.cqsm.api.exceptions.ActionExecutionException)

Aggregations

ActionResult (com.cognifide.cq.cqsm.api.actions.ActionResult)2 ActionExecutionException (com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)2 PermissionActionHelper (com.cognifide.cq.cqsm.foundation.permissions.PermissionActionHelper)2 PermissionException (com.cognifide.cq.cqsm.foundation.permissions.exceptions.PermissionException)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 RepositoryException (javax.jcr.RepositoryException)2 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)2 ArrayList (java.util.ArrayList)1