Search in sources :

Example 26 with User

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

the class ElevationStrategyUserBasedImpl method getAuthentication.

private Authentication getAuthentication() {
    if (authentication == null) {
        try {
            User user = userService.getUserByEmail(userEmail);
            List<String> permissions = permissionService.findUserPermissionsForSubject(SecurityConstants.DOMAIN, user.getUuid(), null);
            UserDetailsImpl userDetails = new UserDetailsImpl(user, "[NO PASSWORD]", permissions, null);
            UsernamePasswordAuthenticationToken ret = new UsernamePasswordAuthenticationToken(userDetails, "[NO PASSWORD]", userDetails.getAuthorities());
            // NOTE: No details for this kind of authentication
            authentication = ret;
        } catch (Throwable t) {
            throw new RuntimeException("Failed to build Authnetication", t);
        }
    }
    return authentication;
}
Also used : UserDetailsImpl(org.summerb.webappboilerplate.security.impls.UserDetailsImpl) User(org.summerb.users.api.dto.User) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 27 with User

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

the class LoginRestController method processPasswordChangeForm.

@Secured({ "ROLE_USER" })
@RequestMapping(method = RequestMethod.POST, value = "change")
public User processPasswordChangeForm(@RequestBody PasswordChange passwordChange) throws UserNotFoundException, FieldValidationException {
    User user = securityContextResolver.getUser();
    usersServiceFacade.changePassword(user.getEmail(), passwordChange);
    return user;
}
Also used : User(org.summerb.users.api.dto.User) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with User

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

Example 29 with User

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

the class UserServiceImpl method getUserByUuid.

@Override
public User getUserByUuid(String userUuid) throws UserNotFoundException {
    Assert.hasText(userUuid, "userUuid must be provided");
    User foundUser;
    try {
        foundUser = userDao.findUserByUuid(userUuid);
    } catch (Throwable t) {
        String msg = String.format("Failed to find user '%s'", userUuid);
        throw new UserServiceUnexpectedException(msg, t);
    }
    if (foundUser == null) {
        throw new UserNotFoundException(userUuid);
    }
    return foundUser;
}
Also used : UserNotFoundException(org.summerb.users.api.exceptions.UserNotFoundException) User(org.summerb.users.api.dto.User) UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException)

Example 30 with User

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

the class UserServiceImpl method deleteUserByUuid.

@Override
@Transactional(rollbackFor = Throwable.class)
public void deleteUserByUuid(String userUuid) throws UserNotFoundException {
    Preconditions.checkArgument(userUuid != null, "User uuid required");
    Preconditions.checkArgument(StringUtils.hasText(userUuid), "User uuid must be provided");
    boolean isDeletedSucceessfully = false;
    try {
        User userToDelete = userDao.findUserByUuid(userUuid);
        if (userToDelete != null) {
            isDeletedSucceessfully = userDao.deleteUser(userUuid);
            // NOTE: Assumed, that all related stuff will be deleted
            // automatically using CASCADE DELETE in the database
            eventBus.post(EntityChangedEvent.removedObject(userToDelete));
        }
    } catch (Throwable t) {
        String msg = String.format("Failed to delete user '%s'", userUuid);
        throw new UserServiceUnexpectedException(msg, t);
    }
    if (!isDeletedSucceessfully) {
        throw new UserNotFoundException(userUuid);
    }
}
Also used : UserNotFoundException(org.summerb.users.api.exceptions.UserNotFoundException) User(org.summerb.users.api.dto.User) UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

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