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;
}
Aggregations