@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(); }
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 RealmCacheSession(RealmCacheManager cache, KeycloakSession session) { this.cache = cache; this.session = session; this.startupRevision = cache.getCurrentCounter(); session.getTransactionManager().enlistPrepare(getPrepareTransaction()); session.getTransactionManager().enlistAfterCompletion(getAfterTransaction()); }
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(); }
.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; }
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()); }
KeycloakSession keycloakSession = keycloakSessionFactory.create(); KeycloakTransactionManager transactionManager = keycloakSession.getTransactionManager(); transactionManager.begin(); try { final RealmModel realm = keycloakSession.realms().getRealmByName(hostname); transactionManager.commit(); keycloakSession.close();
public InfinispanActionTokenStoreProvider(KeycloakSession session, Cache<ActionTokenReducedKey, ActionTokenValueEntity> actionKeyCache) { this.session = session; this.actionKeyCache = actionKeyCache; this.tx = new InfinispanKeycloakTransaction(); session.getTransactionManager().enlistAfterCompletion(tx); }
@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 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 DefaultCacheUserProvider(UserCache cache, KeycloakSession session) { this.cache = cache; this.session = session; session.getTransaction().enlistAfterCompletion(getTransaction()); }
@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(); } }
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); }
@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 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); }