Search in sources :

Example 11 with ActionExecutionException

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

the class CheckAuthorizableExists method process.

public ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    try {
        Authorizable authorizable = null;
        if (shouldBeGroup) {
            authorizable = AuthorizablesUtils.getGroupIfExists(context, id);
        } else {
            authorizable = AuthorizablesUtils.getUserIfExists(context, id);
        }
        if (checkIfAuthIsNull(execute, actionResult, authorizable)) {
            return actionResult;
        }
        checkPath(actionResult, authorizable, execute);
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 12 with ActionExecutionException

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

the class CheckPermissions method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    try {
        final Authorizable authorizable = AuthorizablesUtils.getAuthorizable(context, 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.cq.cqsm.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.cq.cqsm.api.exceptions.ActionExecutionException) Principal(java.security.Principal)

Example 13 with ActionExecutionException

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

the class CheckProperty method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    try {
        Authorizable authorizable = AuthorizablesUtils.getAuthorizable(context, 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.cq.cqsm.api.actions.ActionResult) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 14 with ActionExecutionException

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

the class ClearFromGroupDetacher method detachMembersFromGroup.

public ActionResult detachMembersFromGroup() {
    ActionResult actionResult = new ActionResult();
    try {
        Authorizable authorizable = context.getCurrentAuthorizable();
        if (authorizable.isGroup()) {
            final Group group = context.getCurrentGroup();
            LOGGER.info(String.format("Removing all members of group with id = %s", group.getID()));
            Iterator<Authorizable> groupMembers = getGroupMembers(actionResult, group);
            detachAllMembers(actionResult, group, groupMembers);
        } else {
            actionResult.logError("Child members can only be removed from groups");
        }
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 15 with ActionExecutionException

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

the class ClearFromGroupDetacher method detachAuthorizableFromParents.

public ActionResult detachAuthorizableFromParents() {
    ActionResult actionResult = new ActionResult();
    try {
        Authorizable currentAuthorizable = context.getCurrentAuthorizable();
        Iterator<Group> groups = getGroupParents(actionResult, currentAuthorizable);
        LOGGER.info(String.format("Removing all memberships of authorizable with id = %s", currentAuthorizable.getID()));
        detachFromParents(actionResult, currentAuthorizable, groups);
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Aggregations

ActionExecutionException (com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)27 RepositoryException (javax.jcr.RepositoryException)22 ActionResult (com.cognifide.cq.cqsm.api.actions.ActionResult)21 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)21 Group (org.apache.jackrabbit.api.security.user.Group)12 User (org.apache.jackrabbit.api.security.user.User)9 ArrayList (java.util.ArrayList)7 MockGroup (com.cognifide.cq.cqsm.foundation.actions.MockGroup)4 MockUser (com.cognifide.cq.cqsm.foundation.actions.MockUser)4 PathNotFoundException (javax.jcr.PathNotFoundException)3 Action (com.cognifide.cq.cqsm.api.actions.Action)2 CompositeActionResult (com.cognifide.cq.cqsm.foundation.actions.CompositeActionResult)2 RemoveFromGroup (com.cognifide.cq.cqsm.foundation.actions.removefromgroup.RemoveFromGroup)2 RemoveUser (com.cognifide.cq.cqsm.foundation.actions.removeuser.RemoveUser)2 PermissionActionHelper (com.cognifide.cq.cqsm.foundation.permissions.PermissionActionHelper)2 PermissionException (com.cognifide.cq.cqsm.foundation.permissions.exceptions.PermissionException)2 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