Search in sources :

Example 6 with AuthToken

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;
    }
}
Also used : AuthToken(org.summerb.users.api.dto.AuthToken)

Example 7 with AuthToken

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);
}
Also used : AuthToken(org.summerb.users.api.dto.AuthToken)

Example 8 with AuthToken

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);
    }
}
Also used : FileWriter(java.io.FileWriter) AuthToken(org.summerb.users.api.dto.AuthToken) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 9 with AuthToken

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;
}
Also used : AuthToken(org.summerb.users.api.dto.AuthToken)

Example 10 with AuthToken

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);
}
Also used : AuthToken(org.summerb.users.api.dto.AuthToken)

Aggregations

AuthToken (org.summerb.users.api.dto.AuthToken)28 Test (org.junit.Test)12 User (org.summerb.users.api.dto.User)11 Transactional (org.springframework.transaction.annotation.Transactional)3 UserNotFoundException (org.summerb.users.api.exceptions.UserNotFoundException)3 UserServiceUnexpectedException (org.summerb.users.api.exceptions.UserServiceUnexpectedException)3 FieldValidationException (org.summerb.validation.FieldValidationException)3 File (java.io.File)2 Date (java.util.Date)2 AuthTokenNotFoundException (org.summerb.users.api.exceptions.AuthTokenNotFoundException)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 PersistentRememberMeToken (org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken)1 PagerParams (org.summerb.easycrud.api.dto.PagerParams)1 PaginatedList (org.summerb.easycrud.api.dto.PaginatedList)1