Search in sources :

Example 1 with AccessToken

use of com.haulmont.cuba.core.entity.AccessToken in project cuba by cuba-platform.

the class ServerTokenStoreImpl method getAccessTokenByAuthentication.

@Override
public byte[] getAccessTokenByAuthentication(String authenticationKey) {
    byte[] accessTokenBytes;
    accessTokenBytes = getAccessTokenByAuthenticationFromMemory(authenticationKey);
    if (accessTokenBytes == null && serverConfig.getRestStoreTokensInDb()) {
        AccessToken accessToken = getAccessTokenByAuthenticationKeyFromDatabase(authenticationKey);
        if (accessToken != null) {
            accessTokenBytes = accessToken.getTokenBytes();
            restoreAccessTokenIntoMemory(accessToken);
        }
    }
    return accessTokenBytes;
}
Also used : AccessToken(com.haulmont.cuba.core.entity.AccessToken)

Example 2 with AccessToken

use of com.haulmont.cuba.core.entity.AccessToken in project cuba by cuba-platform.

the class ServerTokenStoreImpl method getAccessTokenByAuthenticationKeyFromDatabase.

@Nullable
protected AccessToken getAccessTokenByAuthenticationKeyFromDatabase(String authenticationKey) {
    AccessToken accessToken;
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        accessToken = em.createQuery("select e from sys$AccessToken e where e.authenticationKey = :authenticationKey", AccessToken.class).setParameter("authenticationKey", authenticationKey).setViewName(View.LOCAL).getFirstResult();
        tx.commit();
        return accessToken;
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) AccessToken(com.haulmont.cuba.core.entity.AccessToken) Nullable(javax.annotation.Nullable)

Example 3 with AccessToken

use of com.haulmont.cuba.core.entity.AccessToken in project cuba by cuba-platform.

the class ServerTokenStoreImpl method getAccessTokenByTokenValueFromDatabase.

@Nullable
protected AccessToken getAccessTokenByTokenValueFromDatabase(String accessTokenValue) {
    AccessToken accessToken;
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        accessToken = em.createQuery("select e from sys$AccessToken e where e.tokenValue = :tokenValue", AccessToken.class).setParameter("tokenValue", accessTokenValue).setViewName(View.LOCAL).getFirstResult();
        tx.commit();
        return accessToken;
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) AccessToken(com.haulmont.cuba.core.entity.AccessToken) Nullable(javax.annotation.Nullable)

Example 4 with AccessToken

use of com.haulmont.cuba.core.entity.AccessToken in project cuba by cuba-platform.

the class ServerTokenStoreImpl method getAccessTokenByTokenValue.

@Override
public byte[] getAccessTokenByTokenValue(String accessTokenValue) {
    byte[] accessTokenBytes;
    accessTokenBytes = getAccessTokenByTokenValueFromMemory(accessTokenValue);
    if (accessTokenBytes == null && serverConfig.getRestStoreTokensInDb()) {
        AccessToken accessToken = getAccessTokenByTokenValueFromDatabase(accessTokenValue);
        if (accessToken != null) {
            accessTokenBytes = accessToken.getTokenBytes();
            restoreAccessTokenIntoMemory(accessToken);
        }
    }
    return accessTokenBytes;
}
Also used : AccessToken(com.haulmont.cuba.core.entity.AccessToken)

Example 5 with AccessToken

use of com.haulmont.cuba.core.entity.AccessToken in project cuba by cuba-platform.

the class ServerTokenStoreImpl method getAuthenticationByTokenValue.

@Override
public byte[] getAuthenticationByTokenValue(String tokenValue) {
    byte[] authenticationBytes;
    authenticationBytes = getAuthenticationByTokenValueFromMemory(tokenValue);
    if (authenticationBytes == null && serverConfig.getRestStoreTokensInDb()) {
        AccessToken accessToken = getAccessTokenByTokenValueFromDatabase(tokenValue);
        if (accessToken != null) {
            authenticationBytes = accessToken.getAuthenticationBytes();
            restoreAccessTokenIntoMemory(accessToken);
        }
    }
    return authenticationBytes;
}
Also used : AccessToken(com.haulmont.cuba.core.entity.AccessToken)

Aggregations

AccessToken (com.haulmont.cuba.core.entity.AccessToken)6 EntityManager (com.haulmont.cuba.core.EntityManager)3 Transaction (com.haulmont.cuba.core.Transaction)3 Nullable (javax.annotation.Nullable)2