public static EntityManager getSessionEntityManager(KeycloakSession session, String entityManagerFactoryJndiName) { EntityManagerFactory factory = null; try { factory = (EntityManagerFactory)new InitialContext().lookup(entityManagerFactoryJndiName); } catch (NamingException e) { throw new RuntimeException(e); } EntityManager em = factory.createEntityManager(); session.getTransactionManager().enlist(new JpaKeycloakTransaction(em)); return em; } }
void addInvalidation(String cacheKey) { if (!transactionEnlisted) { session.getTransactionManager().enlistAfterCompletion(getAfterTransaction()); transactionEnlisted = true; } this.invalidations.add(cacheKey); }
public InfinispanActionTokenStoreProvider(KeycloakSession session, Cache<ActionTokenReducedKey, ActionTokenValueEntity> actionKeyCache) { this.session = session; this.actionKeyCache = actionKeyCache; this.tx = new InfinispanKeycloakTransaction(); session.getTransactionManager().enlistAfterCompletion(tx); }
public InfinispanAuthenticationSessionProvider(KeycloakSession session, InfinispanKeyGenerator keyGenerator, Cache<String, RootAuthenticationSessionEntity> cache) { this.session = session; this.cache = cache; this.keyGenerator = keyGenerator; this.tx = new InfinispanKeycloakTransaction(); this.clusterEventsSenderTx = new SessionEventsSenderTransaction(session); session.getTransactionManager().enlistAfterCompletion(tx); session.getTransactionManager().enlistAfterCompletion(clusterEventsSenderTx); }
public RealmCacheSession(RealmCacheManager cache, KeycloakSession session) { this.cache = cache; this.session = session; this.startupRevision = cache.getCurrentCounter(); session.getTransactionManager().enlistPrepare(getPrepareTransaction()); session.getTransactionManager().enlistAfterCompletion(getAfterTransaction()); }
@Path("{id}") @DELETE @NoCache public Response delete(final @Context UriInfo uriInfo, final @PathParam("id") String id) { auth.checkManageBeer(); BeerEntity beer = find(id); em.remove(beer); em.flush(); adminEvent .operation(OperationType.DELETE) // .resource(ResourceType.of("BEER")) .resourcePath(uriInfo) .success(); if (session.getTransactionManager().isActive()) { session.getTransactionManager().commit(); } return Response.noContent().build(); }
@Override public JpaConnectionProvider create(KeycloakSession session) { logger.trace("Create JpaConnectionProvider"); lazyInit(session); EntityManager em; if (!jtaEnabled) { logger.trace("enlisting EntityManager in JpaKeycloakTransaction"); em = emf.createEntityManager(); } else { em = emf.createEntityManager(SynchronizationType.SYNCHRONIZED); } em = PersistenceExceptionConverter.create(em); if (!jtaEnabled) session.getTransactionManager().enlist(new JpaKeycloakTransaction(em)); return new DefaultJpaConnectionProvider(em); }
public UserCacheSession(UserCacheManager cache, KeycloakSession session) { this.cache = cache; this.session = session; this.startupRevision = cache.getCurrentCounter(); session.getTransactionManager().enlistAfterCompletion(getTransaction()); }
this.keyGenerator = keyGenerator; session.getTransactionManager().enlistAfterCompletion(clusterEventsSenderTx); session.getTransactionManager().enlistAfterCompletion(sessionTx); session.getTransactionManager().enlistAfterCompletion(offlineSessionTx); session.getTransactionManager().enlistAfterCompletion(clientSessionTx); session.getTransactionManager().enlistAfterCompletion(offlineClientSessionTx); session.getTransactionManager().enlistAfterCompletion(loginFailuresTx);
private void tryCreateMasterRealmAdminUser() { KeycloakSession session = getSessionFactory().create(); ApplianceBootstrap applianceBootstrap = new ApplianceBootstrap(session); AdminUser admin = keycloakServerProperties.getAdminUser(); try { session.getTransactionManager().begin(); applianceBootstrap.createMasterRealmUser(admin.getUsername(), admin.getPassword()); session.getTransactionManager().commit(); } catch (Exception ex) { LOG.warn("Couldn't create keycloak master admin user: {}", ex.getMessage()); session.getTransactionManager().rollback(); } session.close(); }
keycloakSession.getTransactionManager().begin(); try { RealmModel realm = keycloakSession.realms().getRealmByName(hostname); keycloakSession.getTransactionManager().commit();
@Path("{id}") @PUT @Consumes(MediaType.APPLICATION_JSON) public Response update(final @Context UriInfo uriInfo, final @PathParam("id") String id, final BeerRepresentation rep) { auth.checkManageBeer(); BeerEntity beer = find(id); if (rep.getName() != null) beer.setName(rep.getName()); if (rep.getType() != null) beer.setType(rep.getType()); if (rep.getAbv() != null) beer.setAbv(rep.getAbv()); em.flush(); adminEvent .operation(OperationType.UPDATE) // .resource(ResourceType.of("BEER")) .resourcePath(uriInfo) .representation(rep) .success(); if (session.getTransactionManager().isActive()) { session.getTransactionManager().commit(); } return Response.noContent().build(); }
@Override public MongoConnectionProvider create(KeycloakSession session) { lazyInit(session); TransactionMongoStoreInvocationContext invocationContext = new TransactionMongoStoreInvocationContext(mongoStore); session.getTransactionManager().enlist(new MongoKeycloakTransaction(invocationContext)); return new DefaultMongoConnectionProvider(db, mongoStore, invocationContext); }
public StoreFactoryCacheSession(StoreFactoryCacheManager cache, KeycloakSession session) { this.cache = cache; this.startupRevision = cache.getCurrentCounter(); this.session = session; this.resourceServerCache = new ResourceServerCache(); this.scopeCache = new ScopeCache(); this.resourceCache = new ResourceCache(); this.policyCache = new PolicyCache(); this.permissionTicketCache = new PermissionTicketCache(); session.getTransactionManager().enlistPrepare(getPrepareTransaction()); session.getTransactionManager().enlistAfterCompletion(getAfterTransaction()); }
.success(); if (session.getTransactionManager().isActive()) { session.getTransactionManager().commit(); if (session.getTransactionManager().isActive()) { session.getTransactionManager().setRollbackOnly();
private Set<String> getPasswordHashAlgorithms() { Set<String> hashAlgos = new HashSet<>(); boolean enmasseRealmsFound = false; KeycloakSession keycloakSession = keycloakSessionFactory.create(); KeycloakTransactionManager transactionManager = keycloakSession.getTransactionManager(); transactionManager.begin(); try { List<RealmModel> realms = keycloakSession.realms().getRealms(); for(RealmModel realm : realms) { if(realm.getAttribute("enmasse-realm",Boolean.FALSE)) { enmasseRealmsFound = true; hashAlgos.add(realm.getPasswordPolicy().getHashAlgorithm()); } } } finally { transactionManager.commit(); keycloakSession.close(); } if(!enmasseRealmsFound) { LOG.warn("No realms with attribute \"enmasse-realm\" found, only universally accepted SASL mechanisms will be offered"); } return hashAlgos; }
keycloakSession.getTransactionManager().begin(); try { keycloakSession.getTransactionManager().commit(); keycloakSession.close();
KeycloakTransactionManager transactionManager = keycloakSession.getTransactionManager(); transactionManager.begin(); try {