Search in sources :

Example 26 with ActionExecutionException

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

the class AuthorizablesUtils method getGroupIfExists.

// *************************** GROUP UTILS *************************************
public static Group getGroupIfExists(Context context, String id) throws RepositoryException, ActionExecutionException {
    if (checkIfRemoved(context, id)) {
        return null;
    }
    Authorizable authorizable = context.getAuthorizables().get(id);
    if (authorizable == null) {
        authorizable = context.getUserManager().getAuthorizable(id);
    }
    if (authorizable == null) {
        return null;
    }
    if (authorizable instanceof User) {
        throw new ActionExecutionException("Authorizable with id " + id + " exists but is a user not a group");
    }
    context.getAuthorizables().put(id, authorizable);
    return (Group) authorizable;
}
Also used : MockGroup(com.cognifide.cq.cqsm.foundation.actions.MockGroup) Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) MockUser(com.cognifide.cq.cqsm.foundation.actions.MockUser) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 27 with ActionExecutionException

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

the class AuthorizablesUtils method getUser.

public static User getUser(Context context, String id) throws ActionExecutionException, RepositoryException {
    if (checkIfRemoved(context, id)) {
        throw new ActionExecutionException("User with id " + id + " not found");
    }
    Authorizable authorizable = context.getAuthorizables().get(id);
    if (authorizable == null) {
        authorizable = context.getUserManager().getAuthorizable(id);
    }
    if (authorizable == null) {
        throw new ActionExecutionException("User with id " + id + " not found");
    }
    if (authorizable instanceof Group) {
        throw new ActionExecutionException("Authorizable with id " + id + " exists but is a group not a user");
    }
    context.getAuthorizables().put(id, authorizable);
    return (User) authorizable;
}
Also used : MockGroup(com.cognifide.cq.cqsm.foundation.actions.MockGroup) Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) MockUser(com.cognifide.cq.cqsm.foundation.actions.MockUser) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) 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