Search in sources :

Example 26 with AuthToken

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

the class PersistentTokenRepositoryDefaultImpl method removeUserTokens.

@Override
public void removeUserTokens(String username) {
    try {
        User user = userService.getUserByEmail(username);
        List<AuthToken> authTokens = authTokenService.findUserAuthTokens(user.getUuid());
        for (AuthToken authToken : authTokens) {
            authTokenService.deleteAuthToken(authToken.getUuid());
        }
    } catch (Throwable e) {
        throw new RuntimeException("Failed to delete user auth tokens", e);
    }
}
Also used : User(org.summerb.users.api.dto.User) AuthToken(org.summerb.users.api.dto.AuthToken)

Example 27 with AuthToken

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

the class PersistentTokenRepositoryDefaultImpl method getTokenForSeries.

@Override
public PersistentRememberMeToken getTokenForSeries(String seriesId) {
    try {
        AuthToken authToken = authTokenService.getAuthTokenByUuid(seriesId);
        User user = userService.getUserByUuid(authToken.getUserUuid());
        return new PersistentRememberMeToken(user.getEmail(), authToken.getUuid(), authToken.getTokenValue(), new Date(authToken.getLastVerifiedAt()));
    } catch (Throwable e) {
        log.info("Persistent auth token wasn't found for seriesId " + seriesId);
        return null;
    }
}
Also used : PersistentRememberMeToken(org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken) User(org.summerb.users.api.dto.User) AuthToken(org.summerb.users.api.dto.AuthToken) Date(java.util.Date)

Example 28 with AuthToken

use of org.summerb.users.api.dto.AuthToken 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)

Aggregations

AuthToken (org.summerb.users.api.dto.AuthToken)28 Test (org.junit.Test)12 User (org.summerb.users.api.dto.User)11 Transactional (org.springframework.transaction.annotation.Transactional)3 UserNotFoundException (org.summerb.users.api.exceptions.UserNotFoundException)3 UserServiceUnexpectedException (org.summerb.users.api.exceptions.UserServiceUnexpectedException)3 FieldValidationException (org.summerb.validation.FieldValidationException)3 File (java.io.File)2 Date (java.util.Date)2 AuthTokenNotFoundException (org.summerb.users.api.exceptions.AuthTokenNotFoundException)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 PersistentRememberMeToken (org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken)1 PagerParams (org.summerb.easycrud.api.dto.PagerParams)1 PaginatedList (org.summerb.easycrud.api.dto.PaginatedList)1