Search in sources :

Example 1 with RefreshToken

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

the class ServerTokenStoreImpl method getRefreshTokenByTokenValue.

@Override
public byte[] getRefreshTokenByTokenValue(String tokenValue) {
    byte[] tokenBytes = getRefreshTokenByTokenValueFromMemory(tokenValue);
    if (tokenBytes == null && serverConfig.getRestStoreTokensInDb()) {
        RefreshToken refreshToken = getRefreshTokenByTokenValueFromDatabase(tokenValue);
        if (refreshToken != null) {
            tokenBytes = refreshToken.getTokenBytes();
            restoreRefreshTokenIntoMemory(refreshToken);
        }
    }
    return tokenBytes;
}
Also used : RefreshToken(com.haulmont.cuba.core.entity.RefreshToken)

Example 2 with RefreshToken

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

the class ServerTokenStoreImpl method getRefreshTokenByTokenValueFromDatabase.

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

Example 3 with RefreshToken

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

the class ServerTokenStoreImpl method storeRefreshTokenToDatabase.

protected void storeRefreshTokenToDatabase(String tokenValue, byte[] tokenBytes, byte[] authenticationBytes, Date tokenExpiry, String userLogin) {
    try (Transaction tx = persistence.getTransaction()) {
        EntityManager em = persistence.getEntityManager();
        RefreshToken refreshToken = metadata.create(RefreshToken.class);
        refreshToken.setCreateTs(timeSource.currentTimestamp());
        refreshToken.setTokenValue(tokenValue);
        refreshToken.setTokenBytes(tokenBytes);
        refreshToken.setAuthenticationBytes(authenticationBytes);
        refreshToken.setExpiry(tokenExpiry);
        refreshToken.setUserLogin(userLogin);
        em.persist(refreshToken);
        tx.commit();
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) RefreshToken(com.haulmont.cuba.core.entity.RefreshToken) Transaction(com.haulmont.cuba.core.Transaction)

Aggregations

RefreshToken (com.haulmont.cuba.core.entity.RefreshToken)3 EntityManager (com.haulmont.cuba.core.EntityManager)2 Transaction (com.haulmont.cuba.core.Transaction)2 Nullable (javax.annotation.Nullable)1