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);
}
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;
}
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());
}
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);
}
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);
}
Aggregations