Search in sources :

Example 1 with ClusterProvider

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

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

the class UserCacheSession method clear.

@Override
public void clear() {
    cache.clear();
    ClusterProvider cluster = session.getProvider(ClusterProvider.class);
    cluster.notify(InfinispanUserCacheProviderFactory.USER_CLEAR_CACHE_EVENTS, new ClearCacheEvent(), true, ClusterProvider.DCNotify.ALL_DCS);
}
Also used : ClusterProvider(org.keycloak.cluster.ClusterProvider)

Example 5 with ClusterProvider

use of org.keycloak.cluster.ClusterProvider 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)

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