Search in sources :

Example 11 with User

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

the class UserServiceCachedImpl method afterPropertiesSet.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void afterPropertiesSet() throws Exception {
    CacheBuilder cacheBuilder = (CacheBuilder) CacheBuilder.newBuilder().maximumSize(1000).recordStats();
    cacheByEmail = new TransactionBoundCache<String, User>("UserCacheByEmail", cacheBuilder, loaderByEmail);
    cacheByUuid = new TransactionBoundCache<String, User>("UserCacheByUuid", cacheBuilder, loaderByUuid);
    eventBus.register(this);
}
Also used : User(org.summerb.microservices.users.api.dto.User) CacheBuilder(com.google.common.cache.CacheBuilder)

Example 12 with User

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

Example 13 with User

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

the class AuthTokenDaoImplTest method testFindExpiredAuthTokens_expect2Tokens.

@Test
public void testFindExpiredAuthTokens_expect2Tokens() throws Exception {
    User user = userService.createUser(UserFactory.createNewUserTemplate());
    passwordService.setUserPassword(user.getUuid(), "aaa");
    AuthToken authToken1 = authTokenService.authenticate(user.getEmail(), "aaa", "LOCAL");
    assertNotNull(authToken1);
    Thread.sleep(501);
    AuthToken authToken2 = authTokenService.authenticate(user.getEmail(), "aaa", "LOCAL");
    assertNotNull(authToken2);
    Thread.sleep(501);
    List<AuthToken> tokens = authTokenService.findUserAuthTokens(user.getUuid());
    assertEquals(2, tokens.size());
}
Also used : User(org.summerb.microservices.users.api.dto.User) AuthToken(org.summerb.microservices.users.api.dto.AuthToken) Test(org.junit.Test)

Example 14 with User

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

the class AuthTokenDaoImplTest method testDeleteAuthToken_expectDeletedAuthTokenMustNotBeValid.

@Test
public void testDeleteAuthToken_expectDeletedAuthTokenMustNotBeValid() throws Exception {
    User user = userService.createUser(UserFactory.createNewUserTemplate());
    passwordService.setUserPassword(user.getUuid(), "aaa");
    AuthToken authToken = authTokenService.authenticate(user.getEmail(), "aaa", "LOCAL");
    assertNotNull(authToken);
    AuthToken result = authTokenService.isAuthTokenValid(user.getUuid(), authToken.getUuid(), authToken.getTokenValue());
    assertNotNull(result);
    authTokenService.deleteAuthToken(authToken.getUuid());
    result = authTokenService.isAuthTokenValid(user.getUuid(), authToken.getUuid(), authToken.getTokenValue());
    assertNull(result);
}
Also used : User(org.summerb.microservices.users.api.dto.User) AuthToken(org.summerb.microservices.users.api.dto.AuthToken) Test(org.junit.Test)

Example 15 with User

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

the class AuthTokenDaoImplTest method testCreateAuthToken_expectOk.

@Test
public void testCreateAuthToken_expectOk() throws Exception {
    User user = userService.createUser(UserFactory.createNewUserTemplate());
    passwordService.setUserPassword(user.getUuid(), "aaa");
    AuthToken authToken = authTokenService.authenticate(user.getEmail(), "aaa", "LOCAL");
    assertNotNull(authToken);
}
Also used : User(org.summerb.microservices.users.api.dto.User) AuthToken(org.summerb.microservices.users.api.dto.AuthToken) 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