use of org.apache.sling.jackrabbit.usermanager.CreateGroup in project sling by apache.
the class CreateGroupServlet 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);
String principalName = request.getParameter(SlingPostConstants.RP_NODE_NAME);
Group group = createGroup(session, principalName, request.getRequestParameterMap(), changes);
String groupPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PREFIX + group.getID();
response.setPath(groupPath);
response.setLocation(externalizePath(request, groupPath));
response.setParentLocation(externalizePath(request, AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PATH));
}
use of org.apache.sling.jackrabbit.usermanager.CreateGroup in project sling by apache.
the class CreateGroupServlet method createGroup.
/* (non-Javadoc)
* @see org.apache.sling.jackrabbit.usermanager.CreateGroup#createGroup(javax.jcr.Session, java.lang.String, java.util.Map, java.util.List)
*/
public Group createGroup(Session jcrSession, final String name, Map<String, ?> properties, List<Modification> changes) throws RepositoryException {
// check that the parameter values have valid values.
if (jcrSession == null) {
throw new IllegalArgumentException("JCR Session not found");
}
if (name == null || name.length() == 0) {
throw new IllegalArgumentException("Group name was not supplied");
}
UserManager userManager = AccessControlUtil.getUserManager(jcrSession);
Authorizable authorizable = userManager.getAuthorizable(name);
Group group = null;
if (authorizable != null) {
// principal already exists!
throw new RepositoryException("A group already exists with the requested name: " + name);
} else {
group = userManager.createGroup(new Principal() {
public String getName() {
return name;
}
});
String groupPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PREFIX + group.getID();
Collection<RequestProperty> reqProperties = collectContent(properties);
changes.add(Modification.onCreated(groupPath));
// 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(AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PATH);
updateGroupMembership(baseResource, properties, group, changes);
} catch (LoginException e) {
throw new RepositoryException(e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
}
return group;
}
Aggregations