use of org.summerb.approaches.validation.FieldValidationException in project summerb by skarpushin.
the class UsersServiceFacadeImpl method assertPasswordResetOperationValid.
protected String assertPasswordResetOperationValid(String email, String passwordResetToken, PasswordReset resetPasswordRequest) throws FieldValidationException, UserNotFoundException, GenericException {
validatePasswordReset(resetPasswordRequest);
try {
validateUserIsEligableForPasswordReset(email);
} catch (FieldValidationException fve) {
throw new GenericException(CommonMessageCodes.ERROR_UNEXPECTED, fve);
}
User user = userService.getUserByEmail(email);
String userUuid = user.getUuid();
boolean isValid = passwordService.isRestorationTokenValid(userUuid, passwordResetToken);
if (!isValid) {
throw new GenericException(SecurityMessageCodes.INVALID_PASSWORD_RESET_TOKEN);
}
return userUuid;
}
use of org.summerb.approaches.validation.FieldValidationException in project summerb by skarpushin.
the class UsersServiceFacadeImpl method changePassword.
@Override
public void changePassword(String email, PasswordChange passwordChange) throws UserNotFoundException, FieldValidationException {
try {
User user = validatePasswordChangeRequestValid(email, passwordChange);
passwordService.setUserPassword(user.getUuid(), passwordChange.getPassword());
} catch (Throwable e) {
Throwables.throwIfInstanceOf(e, FieldValidationException.class);
throw new UserServiceUnexpectedException("Failed to arrange password reset", e);
}
}
use of org.summerb.approaches.validation.FieldValidationException in project summerb by skarpushin.
the class AuthTokenServiceImpl method createAuthToken.
@Override
@Transactional(rollbackFor = Throwable.class)
public AuthToken createAuthToken(String userEmail, String clientIp, String tokenUuid, String tokenValueUuid) throws UserNotFoundException, FieldValidationException {
Preconditions.checkArgument(userEmail != null);
Preconditions.checkArgument(clientIp != null);
Preconditions.checkArgument(StringUtils.hasText(tokenUuid));
Preconditions.checkArgument(StringUtils.hasText(tokenValueUuid));
try {
User user = userService.getUserByEmail(userEmail);
AuthToken authToken = buildNewAuthToken(user, clientIp, tokenUuid, tokenValueUuid);
authTokenDao.createAuthToken(authToken);
return authToken;
} catch (Throwable t) {
Throwables.throwIfInstanceOf(t, UserNotFoundException.class);
Throwables.throwIfInstanceOf(t, FieldValidationException.class);
String msg = String.format("Failed to create auth otken for user '%s'", userEmail);
throw new UserServiceUnexpectedException(msg, t);
}
}
use of org.summerb.approaches.validation.FieldValidationException in project summerb by skarpushin.
the class AuthTokenServiceImpl method validateAndGetUser.
private User validateAndGetUser(String userEmail, String passwordPlain) throws UserNotFoundException, FieldValidationException, InvalidPasswordException {
try {
User user = userService.getUserByEmail(userEmail);
boolean isPasswordValid = passwordService.isUserPasswordValid(user.getUuid(), passwordPlain);
if (!isPasswordValid) {
throw new InvalidPasswordException();
}
return user;
} catch (Throwable t) {
Throwables.throwIfInstanceOf(t, UserNotFoundException.class);
Throwables.throwIfInstanceOf(t, FieldValidationException.class);
Throwables.throwIfInstanceOf(t, InvalidPasswordException.class);
String msg = String.format("Failed to validate user '%s' and password '%s'", userEmail, passwordPlain);
throw new UserServiceUnexpectedException(msg, t);
}
}
use of org.summerb.approaches.validation.FieldValidationException in project summerb by skarpushin.
the class UserServiceImpl method validateUser.
private void validateUser(User user) throws FieldValidationException {
ValidationContext ctx = new ValidationContext();
validateEmail(user.getEmail(), ctx);
ctx.validateDataLengthLessOrEqual(user.getDisplayName(), User.FN_DISPLAY_NAME_SIZE, User.FN_DISPLAY_NAME);
if (ctx.getHasErrors()) {
throw new FieldValidationException(ctx.getErrors());
}
}
Aggregations