Search in sources :

Example 1 with ClusterEvent

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

the class InfinispanUserCacheProviderFactory method lazyInit.

private void lazyInit(KeycloakSession session) {
    if (userCache == null) {
        synchronized (this) {
            if (userCache == null) {
                Cache<String, Revisioned> cache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.USER_CACHE_NAME);
                Cache<String, Long> revisions = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.USER_REVISIONS_CACHE_NAME);
                userCache = new UserCacheManager(cache, revisions);
                ClusterProvider cluster = session.getProvider(ClusterProvider.class);
                cluster.registerListener(USER_INVALIDATION_EVENTS, (ClusterEvent event) -> {
                    InvalidationEvent invalidationEvent = (InvalidationEvent) event;
                    userCache.invalidationEventReceived(invalidationEvent);
                });
                cluster.registerListener(USER_CLEAR_CACHE_EVENTS, (ClusterEvent event) -> {
                    userCache.clear();
                });
                log.debug("Registered cluster listeners");
            }
        }
    }
}
Also used : ClusterEvent(org.keycloak.cluster.ClusterEvent) Revisioned(org.keycloak.models.cache.infinispan.entities.Revisioned) ClusterProvider(org.keycloak.cluster.ClusterProvider) InfinispanConnectionProvider(org.keycloak.connections.infinispan.InfinispanConnectionProvider) InvalidationEvent(org.keycloak.models.cache.infinispan.events.InvalidationEvent)

Example 2 with ClusterEvent

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

the class InfinispanCacheStoreFactoryProviderFactory method lazyInit.

private void lazyInit(KeycloakSession session) {
    if (storeCache == null) {
        synchronized (this) {
            if (storeCache == null) {
                Cache<String, Revisioned> cache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.AUTHORIZATION_CACHE_NAME);
                Cache<String, Long> revisions = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.AUTHORIZATION_REVISIONS_CACHE_NAME);
                storeCache = new StoreFactoryCacheManager(cache, revisions);
                ClusterProvider cluster = session.getProvider(ClusterProvider.class);
                cluster.registerListener(AUTHORIZATION_INVALIDATION_EVENTS, (ClusterEvent event) -> {
                    InvalidationEvent invalidationEvent = (InvalidationEvent) event;
                    storeCache.invalidationEventReceived(invalidationEvent);
                });
                cluster.registerListener(AUTHORIZATION_CLEAR_CACHE_EVENTS, (ClusterEvent event) -> storeCache.clear());
                cluster.registerListener(REALM_CLEAR_CACHE_EVENTS, (ClusterEvent event) -> storeCache.clear());
                log.debug("Registered cluster listeners");
            }
        }
    }
}
Also used : ClusterEvent(org.keycloak.cluster.ClusterEvent) Revisioned(org.keycloak.models.cache.infinispan.entities.Revisioned) ClusterProvider(org.keycloak.cluster.ClusterProvider) InfinispanConnectionProvider(org.keycloak.connections.infinispan.InfinispanConnectionProvider) InvalidationEvent(org.keycloak.models.cache.infinispan.events.InvalidationEvent)

Example 3 with ClusterEvent

use of org.keycloak.cluster.ClusterEvent 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 4 with ClusterEvent

use of org.keycloak.cluster.ClusterEvent 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 5 with ClusterEvent

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

the class InfinispanNotificationsManager method eventReceived.

private void eventReceived(String key, Serializable obj) {
    if (!(obj instanceof WrapperClusterEvent)) {
        if (obj == null) {
            logger.warnf("Event object wasn't available in remote cache after event was received. Event key: %s", key);
        }
        return;
    }
    WrapperClusterEvent event = (WrapperClusterEvent) obj;
    if (event.isIgnoreSender()) {
        if (this.myAddress.equals(event.getSender())) {
            return;
        }
    }
    if (event.isIgnoreSenderSite()) {
        if (this.mySite == null || this.mySite.equals(event.getSenderSite())) {
            return;
        }
    }
    String eventKey = event.getEventKey();
    if (logger.isTraceEnabled()) {
        logger.tracef("Received event: %s", event);
    }
    ClusterEvent wrappedEvent = event.getDelegateEvent();
    List<ClusterListener> myListeners = listeners.get(eventKey);
    if (myListeners != null) {
        for (ClusterListener listener : myListeners) {
            listener.eventReceived(wrappedEvent);
        }
    }
}
Also used : ClusterEvent(org.keycloak.cluster.ClusterEvent) ClusterListener(org.keycloak.cluster.ClusterListener)

Aggregations

ClusterEvent (org.keycloak.cluster.ClusterEvent)6 ClusterProvider (org.keycloak.cluster.ClusterProvider)5 InfinispanConnectionProvider (org.keycloak.connections.infinispan.InfinispanConnectionProvider)3 Revisioned (org.keycloak.models.cache.infinispan.entities.Revisioned)3 InvalidationEvent (org.keycloak.models.cache.infinispan.events.InvalidationEvent)3 ClusterListener (org.keycloak.cluster.ClusterListener)1 KeycloakSessionFactory (org.keycloak.models.KeycloakSessionFactory)1 ClearCacheEvent (org.keycloak.models.cache.infinispan.ClearCacheEvent)1 RealmRemovedEvent (org.keycloak.models.cache.infinispan.events.RealmRemovedEvent)1 RealmUpdatedEvent (org.keycloak.models.cache.infinispan.events.RealmUpdatedEvent)1