Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.sling.jackrabbit.usermanager.impl.post;
 
 import java.util.List;
 import java.util.Map;
 
 

Sling Post Operation implementation for updating a user in the jackrabbit UserManager.

Rest Service Description

Updates a users properties. Maps on to nodes of resourceType sling/users like /rep:system/rep:userManager/rep:users mapped to a resource url /system/userManager/user/ieb. This servlet responds at /system/userManager/user/ieb.update.html

Methods

  • POST

Post Parameters

*
Any additional parameters become properties of the user node (optional)
*@Delete
Delete the property eg prop3@Delete means prop3 will be deleted (optional)

Response

200
Success, a redirect is sent to the users resource locator. The redirect comes with HTML describing the status.
404
The resource was not found
500
Failure

Example

curl -Fprop1=value2 -Fproperty1=value1 http://localhost:8080/system/userManager/user/ieb.update.html

Scr.component:
metatype="no" immediate="true"
Scr.service:
interface="javax.servlet.Servlet"
Scr.property:
name="sling.servlet.resourceTypes" value="sling/user"
Scr.property:
name="sling.servlet.methods" value="POST"
Scr.property:
name="sling.servlet.selectors" value="update"
 
 public class UpdateUserServlet extends AbstractUserPostServlet {
     private static final long serialVersionUID = 5874621724096106496L;
 
     /*
      * (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,
             HtmlResponse htmlResponseList<Modificationchanges)
             throws RepositoryException {
         Authorizable authorizable = null;
         Resource resource = request.getResource();
         if (resource != null) {
             authorizable = resource.adaptTo(Authorizable.class);
         }
 
        // check that the group was located.
        if (authorizable == null) {
            throw new ResourceNotFoundException(
                "User to update could not be determined");
        }
        Session session = request.getResourceResolver().adaptTo(Session.class);
        if (session == null) {
            throw new RepositoryException("JCR Session not found");
        }
        
            + authorizable.getID();
        Map<StringRequestPropertyreqProperties = collectContent(request,
            htmlResponseuserPath);
        try {
            // cleanup any old content (@Delete parameters)
            processDeletes(authorizablereqPropertieschanges);
            // write content from form
            writeContent(sessionauthorizablereqPropertieschanges);
        } catch (RepositoryException re) {
            throw new RepositoryException("Failed to update user."re);
        }
    }
New to GrepCode? Check out our FAQ X