use of org.summerb.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.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.users.api.dto.AuthToken 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);
}
use of org.summerb.users.api.dto.AuthToken in project summerb by skarpushin.
the class AuthTokenDaoImplTest method testIsAuthTokenValid_expectTokenMustBeValidRightAfterCreation.
@Test
public void testIsAuthTokenValid_expectTokenMustBeValidRightAfterCreation() 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);
}
use of org.summerb.users.api.dto.AuthToken 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);
}
Aggregations