public DefaultCacheUserProvider(UserCache cache, KeycloakSession session) { this.cache = cache; this.session = session; session.getTransaction().enlistAfterCompletion(getTransaction()); }
public DefaultCacheRealmProvider(RealmCache cache, KeycloakSession session) { this.cache = cache; this.session = session; session.getTransaction().enlistAfterCompletion(getTransaction()); }
public InfinispanUserSessionProvider(KeycloakSession session, Cache<String, SessionEntity> sessionCache, Cache<String, SessionEntity> offlineSessionCache, Cache<LoginFailureKey, LoginFailureEntity> loginFailureCache) { this.session = session; this.sessionCache = sessionCache; this.offlineSessionCache = offlineSessionCache; this.loginFailureCache = loginFailureCache; this.tx = new InfinispanKeycloakTransaction(); session.getTransaction().enlistAfterCompletion(tx); }
@Override public JpaConnectionProvider create(KeycloakSession session) { lazyInit(session); EntityManager em = emf.createEntityManager(); em = PersistenceExceptionConverter.create(em); session.getTransaction().enlist(new JpaKeycloakTransaction(em)); return new DefaultJpaConnectionProvider(em); }
protected void deleteInvalidUser(RealmModel realm, UserModel user) { KeycloakSession tx = session.getKeycloakSessionFactory().create(); try { tx.getTransaction().begin(); RealmModel realmModel = tx.realms().getRealm(realm.getId()); if (realmModel == null) return; UserModel deletedUser = tx.userStorage().getUserById(user.getId(), realmModel); tx.userStorage().removeUser(realmModel, deletedUser); logger.debugf("Removed invalid user '%s'", user.getUsername()); tx.getTransaction().commit(); } finally { tx.close(); } }
ProviderSession providerSession = providerSessionFactory.createSession(); KeycloakSession session = providerSession.getProvider(KeycloakSession.class); KeycloakTransaction transaction = session.getTransaction(); try { transaction.begin(); session.getTransaction().rollback();
/** * Wrap given runnable job into KeycloakTransaction. * * @param factory * @param task */ public static void runJobInTransaction(KeycloakSessionFactory factory, KeycloakSessionTask task) { KeycloakSession session = factory.create(); KeycloakTransaction tx = session.getTransaction(); try { tx.begin(); task.run(session); if (tx.isActive()) { if (tx.getRollbackOnly()) { tx.rollback(); } else { tx.commit(); } } } catch (RuntimeException re) { if (tx.isActive()) { tx.rollback(); } throw re; } finally { session.close(); } }