Search in sources :

Example 6 with ClusterProvider

use of org.keycloak.cluster.ClusterProvider in project keycloak by keycloak.

the class InfinispanPublicKeyStorageProvider method clearCache.

@Override
public void clearCache() {
    keys.clear();
    ClusterProvider cluster = session.getProvider(ClusterProvider.class);
    cluster.notify(InfinispanPublicKeyStorageProviderFactory.KEYS_CLEAR_CACHE_EVENTS, new ClearCacheEvent(), true, ClusterProvider.DCNotify.ALL_DCS);
}
Also used : ClearCacheEvent(org.keycloak.models.cache.infinispan.ClearCacheEvent) ClusterProvider(org.keycloak.cluster.ClusterProvider)

Example 7 with ClusterProvider

use of org.keycloak.cluster.ClusterProvider in project keycloak by keycloak.

the class InfinispanPublicKeyStorageProvider method runInvalidations.

protected void runInvalidations() {
    ClusterProvider cluster = session.getProvider(ClusterProvider.class);
    for (String cacheKey : invalidations) {
        keys.remove(cacheKey);
        cluster.notify(InfinispanPublicKeyStorageProviderFactory.PUBLIC_KEY_STORAGE_INVALIDATION_EVENT, PublicKeyStorageInvalidationEvent.create(cacheKey), true, ClusterProvider.DCNotify.ALL_DCS);
    }
}
Also used : ClusterProvider(org.keycloak.cluster.ClusterProvider)

Example 8 with ClusterProvider

use of org.keycloak.cluster.ClusterProvider in project keycloak by keycloak.

the class DefaultInfinispanConnectionProviderFactory method registerSystemWideListeners.

private void registerSystemWideListeners(KeycloakSession session) {
    KeycloakSessionFactory sessionFactory = session.getKeycloakSessionFactory();
    ClusterProvider cluster = session.getProvider(ClusterProvider.class);
    cluster.registerListener(REALM_CLEAR_CACHE_EVENTS, (ClusterEvent event) -> {
        if (event instanceof ClearCacheEvent) {
            sessionFactory.invalidate(ObjectType._ALL_);
        }
    });
    cluster.registerListener(REALM_INVALIDATION_EVENTS, (ClusterEvent event) -> {
        if (event instanceof RealmUpdatedEvent) {
            RealmUpdatedEvent rr = (RealmUpdatedEvent) event;
            sessionFactory.invalidate(ObjectType.REALM, rr.getId());
        } else if (event instanceof RealmRemovedEvent) {
            RealmRemovedEvent rr = (RealmRemovedEvent) event;
            sessionFactory.invalidate(ObjectType.REALM, rr.getId());
        }
    });
}
Also used : ClusterEvent(org.keycloak.cluster.ClusterEvent) ClearCacheEvent(org.keycloak.models.cache.infinispan.ClearCacheEvent) ClusterProvider(org.keycloak.cluster.ClusterProvider) RealmRemovedEvent(org.keycloak.models.cache.infinispan.events.RealmRemovedEvent) KeycloakSessionFactory(org.keycloak.models.KeycloakSessionFactory) RealmUpdatedEvent(org.keycloak.models.cache.infinispan.events.RealmUpdatedEvent)

Example 9 with ClusterProvider

use of org.keycloak.cluster.ClusterProvider in project keycloak by keycloak.

the class InfinispanPublicKeyStorageProviderFactory method lazyInit.

private void lazyInit(KeycloakSession session) {
    if (keysCache == null) {
        synchronized (this) {
            if (keysCache == null) {
                this.keysCache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.KEYS_CACHE_NAME);
                ClusterProvider cluster = session.getProvider(ClusterProvider.class);
                cluster.registerListener(PUBLIC_KEY_STORAGE_INVALIDATION_EVENT, (ClusterEvent event) -> {
                    PublicKeyStorageInvalidationEvent invalidationEvent = (PublicKeyStorageInvalidationEvent) event;
                    keysCache.remove(invalidationEvent.getCacheKey());
                });
                cluster.registerListener(KEYS_CLEAR_CACHE_EVENTS, (ClusterEvent event) -> {
                    keysCache.clear();
                });
            }
        }
    }
}
Also used : ClusterEvent(org.keycloak.cluster.ClusterEvent) ClusterProvider(org.keycloak.cluster.ClusterProvider)

Example 10 with ClusterProvider

use of org.keycloak.cluster.ClusterProvider in project keycloak by keycloak.

the class ClusterProviderTaskCommand method doRunCommand.

@Override
protected void doRunCommand(KeycloakSession session) {
    String taskName = getArg(0);
    int taskTimeout = getIntArg(1);
    int sleepTime = getIntArg(2);
    ClusterProvider cluster = session.getProvider(ClusterProvider.class);
    Future future = cluster.executeIfNotExecutedAsync(taskName, taskTimeout, () -> {
        log.infof("Started sleeping for " + sleepTime + " seconds");
        Thread.sleep(sleepTime * 1000);
        log.infof("Stopped sleeping");
        return null;
    });
    log.info("I've retrieved future successfully");
    executors.execute(() -> {
        try {
            future.get();
            log.info("Successfully finished future!");
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}
Also used : ClusterProvider(org.keycloak.cluster.ClusterProvider) Future(java.util.concurrent.Future)

Aggregations

ClusterProvider (org.keycloak.cluster.ClusterProvider)22 ClusterEvent (org.keycloak.cluster.ClusterEvent)5 KeycloakSession (org.keycloak.models.KeycloakSession)5 InfinispanConnectionProvider (org.keycloak.connections.infinispan.InfinispanConnectionProvider)4 KeycloakSessionFactory (org.keycloak.models.KeycloakSessionFactory)4 Revisioned (org.keycloak.models.cache.infinispan.entities.Revisioned)3 InvalidationEvent (org.keycloak.models.cache.infinispan.events.InvalidationEvent)3 RealmRemovedSessionEvent (org.keycloak.models.sessions.infinispan.events.RealmRemovedSessionEvent)3 UserStorageProvider (org.keycloak.storage.UserStorageProvider)3 UserStorageProviderFactory (org.keycloak.storage.UserStorageProviderFactory)3 ImportSynchronization (org.keycloak.storage.user.ImportSynchronization)3 KeycloakSessionTask (org.keycloak.models.KeycloakSessionTask)2 ClearCacheEvent (org.keycloak.models.cache.infinispan.ClearCacheEvent)2 ClientRemovedSessionEvent (org.keycloak.models.sessions.infinispan.events.ClientRemovedSessionEvent)2 SynchronizationResult (org.keycloak.storage.user.SynchronizationResult)2 Future (java.util.concurrent.Future)1 UserLoginFailureProvider (org.keycloak.models.UserLoginFailureProvider)1 UserSessionProvider (org.keycloak.models.UserSessionProvider)1 RealmRemovedEvent (org.keycloak.models.cache.infinispan.events.RealmRemovedEvent)1 RealmUpdatedEvent (org.keycloak.models.cache.infinispan.events.RealmUpdatedEvent)1