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;
}
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;
}
}
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();
}
}
Aggregations