Search in sources :

Example 21 with User

use of org.summerb.users.api.dto.User in project summerb by skarpushin.

the class UsersServiceFacadeImpl method getNewPasswordResetToken.

@Transactional(rollbackFor = Throwable.class)
@Override
public String getNewPasswordResetToken(String email) throws FieldValidationException {
    try {
        validateUserIsEligableForPasswordReset(email);
        User user = userService.getUserByEmail(email);
        String passwordResetToken = passwordService.getNewRestorationTokenForUser(user.getUuid());
        if (passwordResetArmedHandler != null) {
            passwordResetArmedHandler.onPasswordResetRequested(user, passwordResetToken);
        }
        return passwordResetToken;
    } catch (Throwable e) {
        Throwables.throwIfInstanceOf(e, FieldValidationException.class);
        throw new UserServiceUnexpectedException("Failed to arrange password reset", e);
    }
}
Also used : FieldValidationException(org.summerb.validation.FieldValidationException) User(org.summerb.users.api.dto.User) UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with User

use of org.summerb.users.api.dto.User 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.validation.FieldValidationException) User(org.summerb.users.api.dto.User) GenericException(org.summerb.utils.exceptions.GenericException)

Example 23 with User

use of org.summerb.users.api.dto.User 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);
    }
}
Also used : FieldValidationException(org.summerb.validation.FieldValidationException) User(org.summerb.users.api.dto.User) UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException)

Example 24 with User

use of org.summerb.users.api.dto.User in project summerb by skarpushin.

the class LocaleResolverUserBasedImpl method updateUserProfileWithNewLocale.

private void updateUserProfileWithNewLocale(String newLocale) throws UserNotFoundException, FieldValidationException {
    User user = securityContextResolver.getUser();
    if (user.getLocale().equalsIgnoreCase(newLocale)) {
        return;
    }
    user.setLocale(newLocale);
    userService.updateUser(user);
}
Also used : User(org.summerb.users.api.dto.User)

Example 25 with User

use of org.summerb.users.api.dto.User in project summerb by skarpushin.

the class LocaleResolverUserBasedImpl method resolveLocale.

@Override
public Locale resolveLocale(HttpServletRequest request) {
    try {
        boolean isRegisteredUser = securityContextResolver.hasRole(SecurityConstants.ROLE_USER);
        if (isRegisteredUser) {
            User user = securityContextResolver.getUser();
            Locale userLocale = StringUtils.parseLocaleString(user.getLocale());
            return userLocale;
        }
    } catch (Throwable t) {
        log.warn("Failed to resolve locale based on user data", t);
    }
    return super.resolveLocale(request);
}
Also used : Locale(java.util.Locale) User(org.summerb.users.api.dto.User)

Aggregations

User (org.summerb.users.api.dto.User)61 Test (org.junit.Test)33 UserNotFoundException (org.summerb.users.api.exceptions.UserNotFoundException)13 AuthToken (org.summerb.users.api.dto.AuthToken)11 UserServiceUnexpectedException (org.summerb.users.api.exceptions.UserServiceUnexpectedException)11 FieldValidationException (org.summerb.validation.FieldValidationException)11 Transactional (org.springframework.transaction.annotation.Transactional)8 Date (java.util.Date)4 PagerParams (org.summerb.easycrud.api.dto.PagerParams)4 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3 InvalidPasswordException (org.summerb.users.api.exceptions.InvalidPasswordException)3 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 GenericException (org.summerb.utils.exceptions.GenericException)2 ValidationContext (org.summerb.validation.ValidationContext)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 EventBus (com.google.common.eventbus.EventBus)1 Locale (java.util.Locale)1 Secured (org.springframework.security.access.annotation.Secured)1 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)1