Search in sources :

Example 41 with User

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

Example 42 with User

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

the class UsersServiceFacadeImpl method runUserRegisteredHandler.

protected void runUserRegisteredHandler(final User user) {
    if (userRegisteredHandler == null) {
        return;
    }
    List<String> perms = permissionService.findUserPermissionsForSubject(SecurityConstants.DOMAIN, user.getUuid(), null);
    ElevationRunnerImpl runAs = new ElevationRunnerImpl(new ElevationStrategyRunAsUserImpl<User>(user, perms));
    runAs.runElevated(new Runnable() {

        @Override
        public void run() {
            userRegisteredHandler.onUserRegistered(user);
        }
    });
}
Also used : User(org.summerb.microservices.users.api.dto.User) ElevationRunnerImpl(org.summerb.approaches.springmvc.security.elevation.ElevationRunnerImpl)

Example 43 with User

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

Example 44 with User

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

the class UserServiceImplTest method testCreateUser_blackbox_expectValidationExceptionOnInvalidEmail1.

@Test(expected = FieldValidationException.class)
public void testCreateUser_blackbox_expectValidationExceptionOnInvalidEmail1() throws Exception {
    UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
    User user = UserFactory.createNewUserTemplate();
    user.setEmail(null);
    fixture.createUser(user);
    fail();
}
Also used : User(org.summerb.microservices.users.api.dto.User) Test(org.junit.Test)

Example 45 with User

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

the class UserServiceImplTest method testUpdateUser_blackbox_fveOnFailedValidation.

@Test(expected = FieldValidationException.class)
public void testUpdateUser_blackbox_fveOnFailedValidation() throws Exception {
    UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
    User user = UserFactory.createExistingUser();
    user.setEmail("asdasd");
    when(fixture.getUserDao().updateUser(any(User.class))).thenReturn(true);
    fixture.updateUser(user);
    fail();
}
Also used : User(org.summerb.microservices.users.api.dto.User) Test(org.junit.Test)

Aggregations

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