use of org.summerb.utils.exceptions.GenericException in project summerb by skarpushin.
the class LoginController method getPasswordResetForm.
@RequestMapping(method = RequestMethod.GET, value = SecurityActionsUrlsProviderDefaultImpl.RESET_PASSWORD)
public String getPasswordResetForm(@PathVariable(ATTR_PASSWORD_RESET_TOKEN) String passwordResetToken, @RequestParam(User.FN_EMAIL) String email, Model model, HttpServletRequest request) throws UserNotFoundException, FieldValidationException, GenericException {
// Check if token valid
if (!usersServiceFacade.isPasswordResetTokenValid(email, passwordResetToken)) {
auditEvents.report(AUDIT_PASSWORD_RESET_TOKEN_INVALID, ScalarValue.forV(passwordResetToken));
throw new GenericException(SecurityMessageCodes.INVALID_PASSWORD_RESET_TOKEN);
}
// Now let's show password reset form
model.addAttribute(ATTR_PASSWORD_RESET, new PasswordReset());
model.addAttribute(User.FN_EMAIL, email);
model.addAttribute(ATTR_PASSWORD_RESET_TOKEN, passwordResetToken);
return views.resetPassword();
}
use of org.summerb.utils.exceptions.GenericException in project summerb by skarpushin.
the class UsersServiceFacadeImpl method activateRegistration.
@Transactional(rollbackFor = Throwable.class)
@Override
public void activateRegistration(String userUuid) throws GenericException {
try {
// Validate
if (!StringUtils.hasText(userUuid)) {
throw new GenericException(SecurityMessageCodes.NEED_ACTIVATION_TOKEN);
}
// Search user
User user = userService.getUserByUuid(userUuid);
boolean awaitingActivation = isAccountRequiresActivation(userUuid);
if (awaitingActivation) {
activateAccount(user.getUuid());
} else {
throw new GenericException(SecurityMessageCodes.ALREADY_ACTIVATED);
}
if (registrationActivatedHandler != null) {
registrationActivatedHandler.onRegistrationActivated(user);
}
} catch (Throwable e) {
log.error("Failed to activate registration", e);
throw new GenericException(SecurityMessageCodes.FAILED_TO_ACTIVATE_REGISTRATION, e);
}
}
use of org.summerb.utils.exceptions.GenericException 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;
}
Aggregations