Search in sources :

Example 1 with UpdateUser

use of org.apache.sling.jackrabbit.usermanager.UpdateUser in project sling by apache.

the class UpdateUserServlet method updateUser.

/* (non-Javadoc)
     * @see org.apache.sling.jackrabbit.usermanager.UpdateUser#updateUser(javax.jcr.Session, java.lang.String, java.util.Map, java.util.List)
     */
public User updateUser(Session jcrSession, String name, Map<String, ?> properties, 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 update could not be determined");
    }
    Collection<RequestProperty> reqProperties = collectContent(properties);
    try {
        // cleanup any old content (@Delete parameters)
        processDeletes(user, reqProperties, changes);
        // write content from form
        writeContent(jcrSession, user, reqProperties, changes);
        //SLING-2072 set the user as enabled or disabled if the request
        // has supplied the relevant properties
        String disabledParam = convertToString(properties.get(":disabled"));
        if ("true".equalsIgnoreCase(disabledParam)) {
            //set the user as disabled
            String disabledReason = convertToString(properties.get(":disabledReason"));
            if (disabledReason == null) {
                disabledReason = "";
            }
            user.disable(disabledReason);
        } else if ("false".equalsIgnoreCase(disabledParam)) {
            //re-enable a disabled user
            user.disable(null);
        }
    } catch (RepositoryException re) {
        throw new RepositoryException("Failed to update user.", re);
    }
    return user;
}
Also used : UpdateUser(org.apache.sling.jackrabbit.usermanager.UpdateUser) User(org.apache.jackrabbit.api.security.user.User) RequestProperty(org.apache.sling.servlets.post.impl.helper.RequestProperty) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ResourceNotFoundException(org.apache.sling.api.resource.ResourceNotFoundException)

Aggregations

RepositoryException (javax.jcr.RepositoryException)1 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)1 User (org.apache.jackrabbit.api.security.user.User)1 UserManager (org.apache.jackrabbit.api.security.user.UserManager)1 ResourceNotFoundException (org.apache.sling.api.resource.ResourceNotFoundException)1 UpdateUser (org.apache.sling.jackrabbit.usermanager.UpdateUser)1 RequestProperty (org.apache.sling.servlets.post.impl.helper.RequestProperty)1