use of org.summerb.users.api.dto.AuthToken in project summerb by skarpushin.
the class AuthTokenDaoInMemoryImpl method tryParseToken.
private AuthToken tryParseToken(String line) {
try {
if (!StringUtils.hasText(line) || line.indexOf('\t') < 0) {
return null;
}
String[] parts = line.split("\t");
if (parts.length != 7) {
return null;
}
AuthToken ret = new AuthToken();
ret.setClientIp(parts[0]);
ret.setCreatedAt(Long.valueOf(parts[1]));
ret.setExpiresAt(Long.valueOf(parts[2]));
ret.setLastVerifiedAt(Long.valueOf(parts[3]));
ret.setTokenValue(parts[4]);
ret.setUserUuid(parts[5]);
ret.setUuid(parts[6]);
return ret;
} catch (Throwable t) {
log.warn("Failed to parse token from line: " + line, t);
return null;
}
}
use of org.summerb.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.users.api.dto.AuthToken in project summerb by skarpushin.
the class AuthTokenDaoInMemoryImpl method persistTokens.
private void persistTokens() {
try {
if (pathNameToPersistedTokens == null) {
log.info("No pathNameToPersistedTokens configured, no tokens will be persisted");
return;
}
File file = new File(pathNameToPersistedTokens);
Preconditions.checkState(!file.exists() || file.delete(), "Failed to ensure file is not exist before we start writing new one");
try (PrintWriter output = new PrintWriter(new FileWriter(file, true))) {
long now = System.currentTimeMillis();
for (AuthToken token : tokens.values()) {
if (token.getExpiresAt() < now) {
continue;
}
output.printf("%s%s", formatToken(token), System.getProperty("line.separator"));
output.flush();
}
}
log.info("Tokens persisted: " + file.getAbsolutePath());
} catch (Throwable t) {
log.error("Failed to persist tokens", t);
}
}
use of org.summerb.users.api.dto.AuthToken in project summerb by skarpushin.
the class AuthTokenDaoInMemoryImpl method clone.
private AuthToken clone(AuthToken b) {
AuthToken a = new AuthToken();
a.setClientIp(b.getClientIp());
a.setCreatedAt(b.getCreatedAt());
a.setExpiresAt(b.getExpiresAt());
a.setLastVerifiedAt(b.getLastVerifiedAt());
a.setTokenValue(b.getTokenValue());
a.setUserUuid(b.getUserUuid());
a.setUuid(b.getUuid());
return a;
}
use of org.summerb.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);
}
Aggregations