User user = securityService.getUser();
if (!SecurityUtils.userHasRole(user, SystemRole.SITEADMIN) && !user.getLogin().equals(login))
return Response.status(Status.FORBIDDEN).build();
JpaAccount account = null;
Site site = getSite(request);
try {
account = directory.getAccount(site, login);
if (account == null)
return Response.status(Status.NOT_FOUND).build();
// Hash the password
if (StringUtils.isNotBlank(password)) {
logger.debug("Hashing password for user '{}@{}' using md5", login, site.getIdentifier());
String digestPassword = PasswordEncoder.encode(StringUtils.trim(password));
account.setPassword(digestPassword);
}
account.setFirstname(StringUtils.trimToNull(firstname));
account.setLastname(StringUtils.trimToNull(lastname));
account.setInitials(StringUtils.trimToNull(initials));
account.setEmail(StringUtils.trimToNull(email));
// The language
if (StringUtils.isNotBlank(language)) {
try {
account.setLanguage(LanguageUtils.getLanguage(language));
} catch (UnknownLanguageException e) {
return Response.status(Status.BAD_REQUEST).build();
}
} else {
account.setLanguage(null);
}
// Hash the response
if (StringUtils.isNotBlank(response)) {
logger.debug("Hashing response for user '{}@{}' using md5", login, site.getIdentifier());
String digestResponse = PasswordEncoder.encode(StringUtils.trim(response));
account.setResponse(digestResponse);
}
directory.updateAccount(account);