Search in sources :

Example 6 with AccessToken

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

the class ServerTokenStoreImpl method storeAccessTokenToDatabase.

protected void storeAccessTokenToDatabase(String tokenValue, byte[] accessTokenBytes, String authenticationKey, byte[] authenticationBytes, Date tokenExpiry, String userLogin, @Nullable Locale locale, @Nullable String refreshTokenValue) {
    try (Transaction tx = persistence.getTransaction()) {
        EntityManager em = persistence.getEntityManager();
        AccessToken accessToken = metadata.create(AccessToken.class);
        accessToken.setCreateTs(timeSource.currentTimestamp());
        accessToken.setTokenValue(tokenValue);
        accessToken.setTokenBytes(accessTokenBytes);
        accessToken.setAuthenticationKey(authenticationKey);
        accessToken.setAuthenticationBytes(authenticationBytes);
        accessToken.setExpiry(tokenExpiry);
        accessToken.setUserLogin(userLogin);
        accessToken.setLocale(locale != null ? locale.toString() : null);
        accessToken.setRefreshTokenValue(refreshTokenValue);
        em.persist(accessToken);
        tx.commit();
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) 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