Search in sources :

Example 1 with UpdateGroup

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

the class UpdateGroupServlet method updateGroup.

/* (non-Javadoc)
     * @see org.apache.sling.jackrabbit.usermanager.UpdateGroup#updateGroup(javax.jcr.Session, java.lang.String, java.util.Map, java.util.List)
     */
public Group updateGroup(Session jcrSession, String name, Map<String, ?> properties, List<Modification> changes) throws RepositoryException {
    Group group = null;
    UserManager userManager = AccessControlUtil.getUserManager(jcrSession);
    Authorizable authorizable = userManager.getAuthorizable(name);
    if (authorizable instanceof Group) {
        group = (Group) authorizable;
    } else {
        throw new ResourceNotFoundException("Group to update could not be determined");
    }
    String groupPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PREFIX + group.getID();
    Collection<RequestProperty> reqProperties = collectContent(properties);
    try {
        // cleanup any old content (@Delete parameters)
        processDeletes(group, reqProperties, changes);
        // write content from form
        writeContent(jcrSession, group, reqProperties, changes);
        // update the group memberships
        ResourceResolver resourceResolver = null;
        try {
            //create a resource resolver to resolve the relative paths used for group membership values
            final Map<String, Object> authInfo = new HashMap<String, Object>();
            authInfo.put(org.apache.sling.jcr.resource.api.JcrResourceConstants.AUTHENTICATION_INFO_SESSION, jcrSession);
            resourceResolver = resourceResolverFactory.getResourceResolver(authInfo);
            Resource baseResource = resourceResolver.getResource(groupPath);
            updateGroupMembership(baseResource, properties, group, changes);
        } catch (LoginException e) {
            throw new RepositoryException(e);
        } finally {
            if (resourceResolver != null) {
                resourceResolver.close();
            }
        }
    } catch (RepositoryException re) {
        throw new RepositoryException("Failed to update group.", re);
    }
    return group;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) UpdateGroup(org.apache.sling.jackrabbit.usermanager.UpdateGroup) HashMap(java.util.HashMap) Resource(org.apache.sling.api.resource.Resource) RepositoryException(javax.jcr.RepositoryException) RequestProperty(org.apache.sling.servlets.post.impl.helper.RequestProperty) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) LoginException(org.apache.sling.api.resource.LoginException) ResourceNotFoundException(org.apache.sling.api.resource.ResourceNotFoundException)

Aggregations

HashMap (java.util.HashMap)1 RepositoryException (javax.jcr.RepositoryException)1 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)1 Group (org.apache.jackrabbit.api.security.user.Group)1 UserManager (org.apache.jackrabbit.api.security.user.UserManager)1 LoginException (org.apache.sling.api.resource.LoginException)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceNotFoundException (org.apache.sling.api.resource.ResourceNotFoundException)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 UpdateGroup (org.apache.sling.jackrabbit.usermanager.UpdateGroup)1 RequestProperty (org.apache.sling.servlets.post.impl.helper.RequestProperty)1