Search in sources :

Example 21 with Transaction

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();
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction)

Example 22 with Transaction

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;
    }
}
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 23 with Transaction

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;
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) AccessToken(com.haulmont.cuba.core.entity.AccessToken) Nullable(javax.annotation.Nullable)

Example 24 with Transaction

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;
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) AccessToken(com.haulmont.cuba.core.entity.AccessToken) Nullable(javax.annotation.Nullable)

Example 25 with Transaction

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);
    }
}
Also used : Transaction(com.haulmont.cuba.core.Transaction) SecurityContext(com.haulmont.cuba.core.sys.SecurityContext) AppContext.withSecurityContext(com.haulmont.cuba.core.sys.AppContext.withSecurityContext) Nonnull(javax.annotation.Nonnull)

Aggregations

Transaction (com.haulmont.cuba.core.Transaction)211 EntityManager (com.haulmont.cuba.core.EntityManager)138 Test (org.junit.Test)44 User (com.haulmont.cuba.security.entity.User)30 Query (com.haulmont.cuba.core.Query)26 View (com.haulmont.cuba.core.global.View)21 Before (org.junit.Before)15 Group (com.haulmont.cuba.security.entity.Group)13 TypedQuery (com.haulmont.cuba.core.TypedQuery)11 MetaClass (com.haulmont.chile.core.model.MetaClass)9 SendingMessage (com.haulmont.cuba.core.entity.SendingMessage)8 Entity (com.haulmont.cuba.core.entity.Entity)7 List (java.util.List)6 Role (com.haulmont.cuba.security.entity.Role)5 UserRole (com.haulmont.cuba.security.entity.UserRole)5 SoftDeleteOneToOneA (com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneA)5 UUID (java.util.UUID)5 Nullable (javax.annotation.Nullable)5 AppFolder (com.haulmont.cuba.core.entity.AppFolder)4 IdentityEntity (com.haulmont.cuba.testmodel.primary_keys.IdentityEntity)4