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;
}
Aggregations