use of org.summerb.users.api.dto.AuthToken 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.users.api.dto.AuthToken in project summerb by skarpushin.
the class AuthTokenDaoImplTest method testUpdateToken_expectValueWillBeUpdated.
@Test
public void testUpdateToken_expectValueWillBeUpdated() throws Exception {
User user = userService.createUser(UserFactory.createNewUserTemplate());
passwordService.setUserPassword(user.getUuid(), "aaa");
AuthToken authToken = authTokenService.createAuthToken(user.getEmail(), "LOCAL", "tUuid1", "tValue1");
assertNotNull(authToken);
authTokenDao.updateToken(authToken.getUuid(), new Date().getTime() + 1, "newValue2");
authToken = authTokenService.getAuthTokenByUuid(authToken.getUuid());
assertEquals("newValue2", authToken.getTokenValue());
}
use of org.summerb.users.api.dto.AuthToken in project summerb by skarpushin.
the class AuthTokenServiceImpl method buildNewAuthToken.
private AuthToken buildNewAuthToken(User user, String clientIp, String tokenUuid, String tokenValueUuid) {
long now = getNow();
AuthToken ret = new AuthToken();
ret.setClientIp(clientIp);
ret.setCreatedAt(now);
ret.setExpiresAt(calculateAuthTokenExpirationPoint(now));
ret.setLastVerifiedAt(now);
ret.setUserUuid(user.getUuid());
ret.setUuid(tokenUuid);
ret.setTokenValue(tokenValueUuid);
return ret;
}
use of org.summerb.users.api.dto.AuthToken in project summerb by skarpushin.
the class AuthTokenServiceImpl method updateToken.
@Override
@Transactional(rollbackFor = Throwable.class)
public void updateToken(String authTokenUuid, long lastVerifiedAt, String newTokenValue) throws AuthTokenNotFoundException, FieldValidationException {
Preconditions.checkArgument(authTokenUuid != null);
Preconditions.checkArgument(StringUtils.hasText(newTokenValue), "TokenValue is mandatory");
try {
// First - check token itself
AuthToken authToken = getAuthTokenByUuid(authTokenUuid);
if (newTokenValue.equals(authToken.getTokenValue())) {
throw new FieldValidationException(new ValidationError("validation.newValueExpected", "newTokenValue"));
}
// Now we need to update time when token was checked
authTokenDao.updateToken(authTokenUuid, lastVerifiedAt, newTokenValue);
} catch (Throwable t) {
Throwables.throwIfInstanceOf(t, FieldValidationException.class);
Throwables.throwIfInstanceOf(t, AuthTokenNotFoundException.class);
String msg = String.format("Failed to update token '%s'", authTokenUuid);
throw new UserServiceUnexpectedException(msg, t);
}
}
use of org.summerb.users.api.dto.AuthToken in project summerb by skarpushin.
the class AuthTokenServiceDbImplTest method testIsAuthTokenValid_blackbox_expectOkForExistentToken.
@Test
public void testIsAuthTokenValid_blackbox_expectOkForExistentToken() throws Exception {
AuthTokenServiceImpl fixture = AuthTokenServiceDbImplFactory.createAuthTokenServiceDbImpl();
AuthToken result = fixture.isAuthTokenValid(UserFactory.EXISTENT_USER, AuthTokenFactory.AUTH_TOKEN_EXISTENT, AuthTokenFactory.AUTH_TOKEN_EXISTENT_VALUE);
assertNotNull(result);
}
Aggregations