use of com.haulmont.cuba.core.EntityManager 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.EntityManager 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.EntityManager 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.EntityManager in project cuba by cuba-platform.
the class AuthenticationManagerBean method substituteUser.
@Nonnull
@Override
public UserSession substituteUser(User substitutedUser) {
UserSession currentSession = userSessionSource.getUserSession();
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
User user;
if (currentSession.getUser().equals(substitutedUser)) {
user = em.find(User.class, substitutedUser.getId());
if (user == null) {
throw new NoResultException("User not found");
}
} else {
user = loadSubstitutedUser(substitutedUser, currentSession, em);
}
UserSession session = userSessionManager.createSession(currentSession, user);
withSecurityContext(new SecurityContext(serverSession), () -> publishUserSubstitutedEvent(currentSession, session));
tx.commit();
userSessions.remove(currentSession);
userSessionManager.clearPermissionsOnUser(session);
userSessions.add(session);
return session;
}
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class RememberMeAuthenticationProvider method loadRememberMeToken.
@Nullable
protected RememberMeToken loadRememberMeToken(User user, String rememberMeToken) {
EntityManager em = persistence.getEntityManager();
TypedQuery<RememberMeToken> query = em.createQuery("select rt from sec$RememberMeToken rt where rt.token = :token and rt.user.id = :userId", RememberMeToken.class);
query.setParameter("token", rememberMeToken);
query.setParameter("userId", user.getId());
return query.getFirstResult();
}
Aggregations