use of org.summerb.approaches.validation.errors.FieldRequiredValidationError in project summerb by skarpushin.
the class PasswordServiceImpl method setUserPassword.
@Override
@Transactional(rollbackFor = Throwable.class)
public void setUserPassword(String userUuid, String newPasswordPlain) throws UserNotFoundException, FieldValidationException {
Preconditions.checkArgument(userUuid != null);
Preconditions.checkArgument(newPasswordPlain != null);
assertUserExists(userUuid);
if (!StringUtils.hasText(newPasswordPlain)) {
throw new FieldValidationException(new FieldRequiredValidationError(FN_PASSWORD));
}
String newPasswordHash = null;
try {
newPasswordHash = encodePassword(newPasswordPlain);
// sanity check
if (!isPasswordMatch(newPasswordPlain, newPasswordHash)) {
throw new RuntimeException("Password doesn't match just created hash");
}
// set user password
int updateResult = passwordDao.updateUserPassword(userUuid, newPasswordHash);
if (updateResult < 1) {
throw new RuntimeException("updateUserPassword returned unexpected result = " + updateResult);
}
} catch (Throwable t) {
String msg = String.format("Failed to set user '%s' passwordHash '%s'", userUuid, newPasswordHash);
throw new UserServiceUnexpectedException(msg, t);
}
}
Aggregations