use of org.apache.sling.jackrabbit.usermanager.DeleteUser 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);
}
}
}
}
use of org.apache.sling.jackrabbit.usermanager.DeleteUser in project sling by apache.
the class DeleteAuthorizableServlet method deleteUser.
/* (non-Javadoc)
* @see org.apache.sling.jackrabbit.usermanager.DeleteUser#deleteUser(javax.jcr.Session, java.lang.String, java.util.List)
*/
public void deleteUser(Session jcrSession, String name, List<Modification> changes) throws RepositoryException {
User user;
UserManager userManager = AccessControlUtil.getUserManager(jcrSession);
Authorizable authorizable = userManager.getAuthorizable(name);
if (authorizable instanceof User) {
user = (User) authorizable;
} else {
throw new ResourceNotFoundException("User to delete could not be determined");
}
String userPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_USER_PREFIX + user.getID();
user.remove();
changes.add(Modification.onDeleted(userPath));
}
Aggregations