use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.
the class ServerTokenStoreImpl method removeRefreshTokenFromDatabase.
protected void removeRefreshTokenFromDatabase(String refreshTokenValue) {
try (Transaction tx = persistence.getTransaction()) {
EntityManager em = persistence.getEntityManager();
em.createQuery("delete from sys$RefreshToken t where t.tokenValue = :tokenValue").setParameter("tokenValue", refreshTokenValue).executeUpdate();
tx.commit();
}
}
use of com.haulmont.cuba.core.Transaction 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.Transaction 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;
}
}
use of com.haulmont.cuba.core.Transaction 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;
}
}
use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.
the class AuthenticationManagerBean method authenticate.
@Override
@Nonnull
public AuthenticationDetails authenticate(Credentials credentials) throws LoginException {
checkNotNullArgument(credentials, "credentials should not be null");
SecurityContext previousSecurityContext = AppContext.getSecurityContext();
AppContext.setSecurityContext(new SecurityContext(serverSession));
try (Transaction tx = persistence.createTransaction()) {
AuthenticationDetails authenticationDetails = authenticateInternal(credentials);
tx.commit();
userSessionManager.clearPermissionsOnUser(authenticationDetails.getSession());
return authenticationDetails;
} finally {
AppContext.setSecurityContext(previousSecurityContext);
}
}
Aggregations