Search in sources :

Example 21 with ResourceNotFoundException

use of org.apache.sling.api.resource.ResourceNotFoundException 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)

Example 22 with ResourceNotFoundException

use of org.apache.sling.api.resource.ResourceNotFoundException 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));
}
Also used : User(org.apache.jackrabbit.api.security.user.User) DeleteUser(org.apache.sling.jackrabbit.usermanager.DeleteUser) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ResourceNotFoundException(org.apache.sling.api.resource.ResourceNotFoundException)

Aggregations

ResourceNotFoundException (org.apache.sling.api.resource.ResourceNotFoundException)22 RepositoryException (javax.jcr.RepositoryException)10 Resource (org.apache.sling.api.resource.Resource)10 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)6 UserManager (org.apache.jackrabbit.api.security.user.UserManager)5 ArrayList (java.util.ArrayList)4 Session (javax.jcr.Session)4 Group (org.apache.jackrabbit.api.security.user.Group)4 User (org.apache.jackrabbit.api.security.user.User)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Item (javax.jcr.Item)3 ServletException (javax.servlet.ServletException)3 InputStream (java.io.InputStream)2 PrintWriter (java.io.PrintWriter)2 Principal (java.security.Principal)2 LinkedHashMap (java.util.LinkedHashMap)2 Entry (java.util.Map.Entry)2