Search in sources :

Example 11 with UserServiceUnexpectedException

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

the class PermissionServiceImpl method findUserPermissionsForSubject.

@Override
public List<String> findUserPermissionsForSubject(String optionalDomainName, String userUuid, String optionalSubjectId) {
    Preconditions.checkArgument(StringUtils.hasText(userUuid));
    String domainName = getOptionalParamValue(optionalDomainName);
    String subjectId = getOptionalParamValue(optionalSubjectId);
    try {
        return permissionDao.getUserPermissionsForSubject(domainName, userUuid, subjectId);
    } catch (Throwable t) {
        String msg = String.format("Failed to get user '%s' permissions for subject '%s' in domain '%s'", userUuid, subjectId, domainName);
        throw new UserServiceUnexpectedException(msg, t);
    }
}
Also used : UserServiceUnexpectedException(org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException)

Example 12 with UserServiceUnexpectedException

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

the class PermissionServiceImpl method findSubjectsUserHasPermissionsFor.

@Override
public List<String> findSubjectsUserHasPermissionsFor(String optionalDomainName, String userUuid, String optionalRequiredPermission) {
    Preconditions.checkArgument(StringUtils.hasText(userUuid));
    String domainName = getOptionalParamValue(optionalDomainName);
    try {
        if (!StringUtils.hasText(optionalRequiredPermission)) {
            return permissionDao.getSubjectsUserHasPermissionFor(domainName, userUuid);
        } else {
            return permissionDao.getSubjectsUserHasPermissionForFiltered(domainName, userUuid, optionalRequiredPermission);
        }
    } catch (Throwable t) {
        String msg = String.format("Failed to get subject list user '%s' has permissions (optional = '%s') for in domain '%s'", userUuid, optionalRequiredPermission, domainName);
        throw new UserServiceUnexpectedException(msg, t);
    }
}
Also used : UserServiceUnexpectedException(org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException)

Example 13 with UserServiceUnexpectedException

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

the class UserServiceImpl method getUserByEmail.

@Override
public User getUserByEmail(String userEmail) throws FieldValidationException, UserNotFoundException {
    Assert.notNull(userEmail, "user email must be provided");
    validateEmail(userEmail);
    User foundUser;
    try {
        foundUser = userDao.findUserByEmail(userEmail);
    } catch (Throwable t) {
        String msg = String.format("Failed to find user by email '%s'", userEmail);
        throw new UserServiceUnexpectedException(msg, t);
    }
    if (foundUser == null) {
        throw new UserNotFoundException(userEmail);
    }
    return foundUser;
}
Also used : UserNotFoundException(org.summerb.microservices.users.api.exceptions.UserNotFoundException) User(org.summerb.microservices.users.api.dto.User) UserServiceUnexpectedException(org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException)

Example 14 with UserServiceUnexpectedException

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

the class UsersServiceFacadeImpl method resetPassword.

@Transactional(rollbackFor = Throwable.class)
@Override
public void resetPassword(String email, String passwordResetToken, PasswordReset resetPasswordRequest) throws UserNotFoundException, FieldValidationException {
    try {
        String userUuid = assertPasswordResetOperationValid(email, passwordResetToken, resetPasswordRequest);
        passwordService.setUserPassword(userUuid, resetPasswordRequest.getPassword());
        // generate new token in order to invalidate current
        passwordService.getNewRestorationTokenForUser(userUuid);
        // If account requires activation, do it
        if (isAccountRequiresActivation(userUuid)) {
            activateAccount(userUuid);
        }
    } 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) UserServiceUnexpectedException(org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with UserServiceUnexpectedException

use of org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException 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)

Aggregations

UserServiceUnexpectedException (org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException)27 Transactional (org.springframework.transaction.annotation.Transactional)18 FieldValidationException (org.summerb.approaches.validation.FieldValidationException)11 User (org.summerb.microservices.users.api.dto.User)11 UserNotFoundException (org.summerb.microservices.users.api.exceptions.UserNotFoundException)9 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3 AuthToken (org.summerb.microservices.users.api.dto.AuthToken)3 AuthTokenNotFoundException (org.summerb.microservices.users.api.exceptions.AuthTokenNotFoundException)3 InvalidPasswordException (org.summerb.microservices.users.api.exceptions.InvalidPasswordException)2 DuplicateUserValidationError (org.summerb.microservices.users.api.validation.DuplicateUserValidationError)2 Password (org.summerb.microservices.users.impl.dom.Password)2 Date (java.util.Date)1 UserStatus (org.summerb.approaches.springmvc.security.dto.UserStatus)1 RegistrationAlreadyRequestedValidationError (org.summerb.approaches.springmvc.security.ve.RegistrationAlreadyRequestedValidationError)1 ValidationError (org.summerb.approaches.validation.ValidationError)1 FieldRequiredValidationError (org.summerb.approaches.validation.errors.FieldRequiredValidationError)1