use of org.summerb.microservices.users.api.dto.AuthToken in project summerb by skarpushin.
the class AuthTokenDaoInMemoryImpl method findAuthTokensByUser.
@Override
public synchronized List<AuthToken> findAuthTokensByUser(String userUuid) {
Collection<AuthToken> data = idxByUser.get(userUuid);
List<AuthToken> ret = new ArrayList<AuthToken>(data.size());
for (AuthToken d : data) {
ret.add(clone(d));
}
return ret;
}
use of org.summerb.microservices.users.api.dto.AuthToken in project summerb by skarpushin.
the class AuthTokenDaoInMemoryImpl method createAuthToken.
@Override
public synchronized void createAuthToken(AuthToken authToken) {
AuthToken clonned = clone(authToken);
internalAddToken(clonned);
}
use of org.summerb.microservices.users.api.dto.AuthToken in project summerb by skarpushin.
the class AuthTokenDaoInMemoryImpl method deleteAuthToken.
@Override
public synchronized void deleteAuthToken(String authTokenUuid) {
AuthToken token = tokens.remove(authTokenUuid);
if (token == null) {
return;
}
idxByUser.get(token.getUserUuid()).remove(token);
}
use of org.summerb.microservices.users.api.dto.AuthToken in project summerb by skarpushin.
the class AuthTokenDaoInMemoryImpl method loadPersistedTokens.
private void loadPersistedTokens() {
try {
if (pathNameToPersistedTokens == null) {
log.info("No pathNameToPersistedTokens configured, no tokens will be loaded");
return;
}
File file = new File(pathNameToPersistedTokens);
if (!file.exists()) {
log.warn("pathNameToPersistedTokens configured, but file nto found, no tokens will be loaded");
return;
}
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
long now = System.currentTimeMillis();
log.info("Loaded tokens from: " + file.getAbsolutePath());
for (String line; (line = br.readLine()) != null; ) {
AuthToken token = tryParseToken(line);
if (token == null || token.getExpiresAt() < now) {
continue;
}
internalAddToken(token);
}
log.info("Loaded tokens count: " + tokens.size());
}
} catch (Throwable t) {
log.error("Failed to load persisted tokens", t);
}
}
use of org.summerb.microservices.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());
}
Aggregations