Search in sources :

Example 21 with ActionExecutionException

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

the class RemoveFromGroup method process.

public ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    List<String> errors = new ArrayList<>();
    Authorizable authorizable = null;
    try {
        authorizable = context.getCurrentAuthorizable();
        actionResult.setAuthorizable(authorizable.getID());
        LOGGER.info(String.format("Removing authorizable with id = %s from groups %s", authorizable.getID(), groupIds));
    } catch (ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
        return actionResult;
    } catch (RepositoryException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
        return actionResult;
    }
    for (String id : groupIds) {
        try {
            Group group = AuthorizablesUtils.getGroup(context, id);
            if (execute) {
                group.removeMember(authorizable);
            }
            actionResult.logMessage(MessagingUtils.removedFromGroup(authorizable.getID(), id));
        } catch (RepositoryException | ActionExecutionException e) {
            errors.add(MessagingUtils.createMessage(e));
        }
    }
    if (!errors.isEmpty()) {
        for (String error : errors) {
            actionResult.logError(error);
        }
        actionResult.logError("Execution interrupted");
    }
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) ArrayList(java.util.ArrayList) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 22 with ActionExecutionException

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

the class RemoveGroup method process.

private ActionResult process(final Context context, boolean execute) {
    List<String> errors = new ArrayList<>();
    ActionResult actionResult = new ActionResult();
    LOGGER.info(String.format("Removing groups with ids = %s", StringUtils.join(ids, ", ")));
    for (String id : ids) {
        try {
            Group group = AuthorizablesUtils.getGroupIfExists(context, id);
            if (group != null) {
                AuthorizablesUtils.markAuthorizableAsRemoved(context, group);
                if (execute) {
                    AuthorizablesUtils.removeGroup(context, group);
                }
                actionResult.logMessage("Group with id: " + id + " removed");
            }
        } catch (RepositoryException | ActionExecutionException e) {
            errors.add(MessagingUtils.createMessage(e));
        }
    }
    if (!errors.isEmpty()) {
        for (String error : errors) {
            actionResult.logError(error);
        }
        actionResult.logError("Execution interrupted");
    }
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 23 with ActionExecutionException

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

the class SetPassword method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    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.cq.cqsm.api.actions.ActionResult) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 24 with ActionExecutionException

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

the class SetProperty method process.

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

Example 25 with ActionExecutionException

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

the class AuthorizablesUtils method getUserIfExists.

// *************************** USER UTILS **************************************
public static User getUserIfExists(Context context, String id) throws ActionExecutionException, RepositoryException {
    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 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