Search in sources :

Example 11 with UserNotFoundException

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

Example 12 with UserNotFoundException

use of org.summerb.users.api.exceptions.UserNotFoundException in project summerb by skarpushin.

the class UserCachedTest method testDeleteUser_expectUserNotFoundException.

// (expected=UserNotFoundException.class)
@Test
public void testDeleteUser_expectUserNotFoundException() throws Exception {
    User userToCreate = UserFactory.createNewUserTemplate();
    userToCreate = userService.createUser(userToCreate);
    userService.getUserByUuid(userToCreate.getUuid());
    userService.deleteUserByUuid(userToCreate.getUuid());
    try {
        userService.getUserByUuid(userToCreate.getUuid());
        fail();
    } catch (UserNotFoundException e) {
    }
}
Also used : UserNotFoundException(org.summerb.users.api.exceptions.UserNotFoundException) User(org.summerb.users.api.dto.User) Test(org.junit.Test)

Example 13 with UserNotFoundException

use of org.summerb.users.api.exceptions.UserNotFoundException in project summerb by skarpushin.

the class UserDetailsServiceDefaultImpl method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String userEmail) throws UsernameNotFoundException {
    try {
        User user = userService.getUserByEmail(userEmail);
        List<String> permissions = permissionService.findUserPermissionsForSubject(SecurityConstants.DOMAIN, user.getUuid(), null);
        AuthToken authToken = null;
        UserDetailsImpl ret = new UserDetailsImpl(user, null, permissions, authToken);
        return ret;
    } catch (UserNotFoundException e) {
        throw new UsernameNotFoundException("User not found", e);
    } catch (FieldValidationException e) {
        throw new UsernameNotFoundException("Email provided in invalid format", e);
    } catch (Throwable t) {
        throw new UsernameNotFoundException("Failed to get user by email", t);
    }
}
Also used : UserNotFoundException(org.summerb.users.api.exceptions.UserNotFoundException) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) FieldValidationException(org.summerb.validation.FieldValidationException) User(org.summerb.users.api.dto.User) AuthToken(org.summerb.users.api.dto.AuthToken)

Example 14 with UserNotFoundException

use of org.summerb.users.api.exceptions.UserNotFoundException in project summerb by skarpushin.

the class UsersServiceFacadeImpl method getUserStatusByEmail.

@Override
public UserStatus getUserStatusByEmail(String email) throws FieldValidationException {
    ValidationContext ctx = new ValidationContext();
    ctx.validateNotEmpty(email, LoginParams.FN_EMAIL);
    ctx.throwIfHasErrors();
    // Check if user have record
    User user = null;
    try {
        user = userService.getUserByEmail(email);
    } catch (UserNotFoundException nfe) {
        return UserStatus.NotExists;
    }
    // Check if user has ROLE_USER
    List<String> permissions = permissionService.findUserPermissionsForSubject(SecurityConstants.DOMAIN, user.getUuid(), null);
    if (permissions.contains(SecurityConstants.ROLE_USER)) {
        return UserStatus.NormalUser;
    }
    if (permissions.contains(SecurityConstants.MARKER_AWAITING_ACTIVATION)) {
        return UserStatus.AwaitingActivation;
    }
    return UserStatus.Provisioned;
}
Also used : UserNotFoundException(org.summerb.users.api.exceptions.UserNotFoundException) User(org.summerb.users.api.dto.User) ValidationContext(org.summerb.validation.ValidationContext)

Aggregations

UserNotFoundException (org.summerb.users.api.exceptions.UserNotFoundException)14 User (org.summerb.users.api.dto.User)13 UserServiceUnexpectedException (org.summerb.users.api.exceptions.UserServiceUnexpectedException)9 FieldValidationException (org.summerb.validation.FieldValidationException)7 Transactional (org.springframework.transaction.annotation.Transactional)6 AuthToken (org.summerb.users.api.dto.AuthToken)3 InvalidPasswordException (org.summerb.users.api.exceptions.InvalidPasswordException)3 Test (org.junit.Test)2 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)1 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 AuthTokenNotFoundException (org.summerb.users.api.exceptions.AuthTokenNotFoundException)1 DuplicateUserValidationError (org.summerb.users.api.validation.DuplicateUserValidationError)1 ValidationContext (org.summerb.validation.ValidationContext)1 UserStatus (org.summerb.webappboilerplate.security.dto.UserStatus)1 PasswordInvalidValidationError (org.summerb.webappboilerplate.security.ve.PasswordInvalidValidationError)1 RegistrationAlreadyRequestedValidationError (org.summerb.webappboilerplate.security.ve.RegistrationAlreadyRequestedValidationError)1 UserNotFoundValidationError (org.summerb.webappboilerplate.security.ve.UserNotFoundValidationError)1