Search in sources :

Example 1 with DeleteGroup

use of org.apache.sling.jackrabbit.usermanager.DeleteGroup in project sling by apache.

the class DeleteAuthorizableServlet method deleteGroup.

/* (non-Javadoc)
     * @see org.apache.sling.jackrabbit.usermanager.DeleteGroup#deleteGroup(javax.jcr.Session, java.lang.String, java.util.List)
     */
public void deleteGroup(Session jcrSession, String name, List<Modification> changes) throws RepositoryException {
    Group group;
    UserManager userManager = AccessControlUtil.getUserManager(jcrSession);
    Authorizable authorizable = userManager.getAuthorizable(name);
    if (authorizable instanceof Group) {
        group = (Group) authorizable;
    } else {
        throw new ResourceNotFoundException("Group to delete could not be determined");
    }
    String groupPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PREFIX + group.getID();
    group.remove();
    changes.add(Modification.onDeleted(groupPath));
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) DeleteGroup(org.apache.sling.jackrabbit.usermanager.DeleteGroup) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ResourceNotFoundException(org.apache.sling.api.resource.ResourceNotFoundException)

Example 2 with DeleteGroup

use of org.apache.sling.jackrabbit.usermanager.DeleteGroup in project sling by apache.

the class DeleteAuthorizableServlet method handleOperation.

/*
     * (non-Javadoc)
     * @see
     * org.apache.sling.jackrabbit.usermanager.post.AbstractAuthorizablePostServlet
     * #handleOperation(org.apache.sling.api.SlingHttpServletRequest,
     * org.apache.sling.api.servlets.HtmlResponse, java.util.List)
     */
@Override
protected void handleOperation(SlingHttpServletRequest request, AbstractPostResponse response, List<Modification> changes) throws RepositoryException {
    Session session = request.getResourceResolver().adaptTo(Session.class);
    Resource resource = request.getResource();
    String[] applyTo = request.getParameterValues(SlingPostConstants.RP_APPLY_TO);
    if (applyTo != null) {
        deleteAuthorizables(session, resource, applyTo, changes);
    } else {
        Authorizable item = resource.adaptTo(Authorizable.class);
        if (item == null) {
            String msg = "Missing source " + resource.getPath() + " for delete";
            response.setStatus(HttpServletResponse.SC_NOT_FOUND, msg);
            throw new ResourceNotFoundException(msg);
        } else {
            if (item instanceof User) {
                deleteUser(session, item.getID(), changes);
            } else if (item instanceof Group) {
                deleteGroup(session, item.getID(), changes);
            }
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) DeleteGroup(org.apache.sling.jackrabbit.usermanager.DeleteGroup) User(org.apache.jackrabbit.api.security.user.User) DeleteUser(org.apache.sling.jackrabbit.usermanager.DeleteUser) Resource(org.apache.sling.api.resource.Resource) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ResourceNotFoundException(org.apache.sling.api.resource.ResourceNotFoundException) Session(javax.jcr.Session)

Aggregations

Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)2 Group (org.apache.jackrabbit.api.security.user.Group)2 ResourceNotFoundException (org.apache.sling.api.resource.ResourceNotFoundException)2 DeleteGroup (org.apache.sling.jackrabbit.usermanager.DeleteGroup)2 Session (javax.jcr.Session)1 User (org.apache.jackrabbit.api.security.user.User)1 UserManager (org.apache.jackrabbit.api.security.user.UserManager)1 Resource (org.apache.sling.api.resource.Resource)1 DeleteUser (org.apache.sling.jackrabbit.usermanager.DeleteUser)1