Search in sources :

Example 1 with GenericException

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();
}
Also used : PasswordReset(org.summerb.approaches.springmvc.security.dto.PasswordReset) GenericException(org.summerb.utils.exceptions.GenericException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with GenericException

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);
    }
}
Also used : User(org.summerb.microservices.users.api.dto.User) GenericException(org.summerb.utils.exceptions.GenericException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with GenericException

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;
}
Also used : FieldValidationException(org.summerb.approaches.validation.FieldValidationException) User(org.summerb.microservices.users.api.dto.User) GenericException(org.summerb.utils.exceptions.GenericException)

Aggregations

GenericException (org.summerb.utils.exceptions.GenericException)3 User (org.summerb.microservices.users.api.dto.User)2 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 PasswordReset (org.summerb.approaches.springmvc.security.dto.PasswordReset)1 FieldValidationException (org.summerb.approaches.validation.FieldValidationException)1