Search in sources :

Example 1 with InfinispanKeyGenerator

use of org.keycloak.models.sessions.infinispan.util.InfinispanKeyGenerator in project keycloak by keycloak.

the class InfinispanUserSessionProviderFactory method postInit.

@Override
public void postInit(final KeycloakSessionFactory factory) {
    factory.register(new ProviderEventListener() {

        @Override
        public void onEvent(ProviderEvent event) {
            if (event instanceof PostMigrationEvent) {
                int preloadTransactionTimeout = getTimeoutForPreloadingSessionsSeconds();
                log.debugf("Will preload sessions with transaction timeout %d seconds", preloadTransactionTimeout);
                KeycloakModelUtils.runJobInTransactionWithTimeout(factory, (KeycloakSession session) -> {
                    keyGenerator = new InfinispanKeyGenerator();
                    checkRemoteCaches(session);
                    loadPersistentSessions(factory, getMaxErrors(), getSessionsPerSegment());
                    registerClusterListeners(session);
                    loadSessionsFromRemoteCaches(session);
                }, preloadTransactionTimeout);
            } else if (event instanceof UserModel.UserRemovedEvent) {
                UserModel.UserRemovedEvent userRemovedEvent = (UserModel.UserRemovedEvent) event;
                InfinispanUserSessionProvider provider = (InfinispanUserSessionProvider) userRemovedEvent.getKeycloakSession().getProvider(UserSessionProvider.class, getId());
                provider.onUserRemoved(userRemovedEvent.getRealm(), userRemovedEvent.getUser());
            } else if (event instanceof ResetTimeOffsetEvent) {
                if (persisterLastSessionRefreshStore != null) {
                    persisterLastSessionRefreshStore.reset();
                }
                if (lastSessionRefreshStore != null) {
                    lastSessionRefreshStore.reset();
                }
                if (offlineLastSessionRefreshStore != null) {
                    offlineLastSessionRefreshStore.reset();
                }
            }
        }
    });
}
Also used : ProviderEventListener(org.keycloak.provider.ProviderEventListener) ProviderEvent(org.keycloak.provider.ProviderEvent) UserModel(org.keycloak.models.UserModel) UserSessionProvider(org.keycloak.models.UserSessionProvider) ResetTimeOffsetEvent(org.keycloak.models.utils.ResetTimeOffsetEvent) KeycloakSession(org.keycloak.models.KeycloakSession) InfinispanKeyGenerator(org.keycloak.models.sessions.infinispan.util.InfinispanKeyGenerator) PostMigrationEvent(org.keycloak.models.utils.PostMigrationEvent)

Example 2 with InfinispanKeyGenerator

use of org.keycloak.models.sessions.infinispan.util.InfinispanKeyGenerator in project keycloak by keycloak.

the class InfinispanAuthenticationSessionProviderFactory method lazyInit.

private void lazyInit(KeycloakSession session) {
    if (authSessionsCache == null) {
        synchronized (this) {
            if (authSessionsCache == null) {
                InfinispanConnectionProvider connections = session.getProvider(InfinispanConnectionProvider.class);
                authSessionsCache = connections.getCache(InfinispanConnectionProvider.AUTHENTICATION_SESSIONS_CACHE_NAME);
                keyGenerator = new InfinispanKeyGenerator();
                ClusterProvider cluster = session.getProvider(ClusterProvider.class);
                cluster.registerListener(AUTHENTICATION_SESSION_EVENTS, this::updateAuthNotes);
                log.debugf("[%s] Registered cluster listeners", authSessionsCache.getCacheManager().getAddress());
            }
        }
    }
}
Also used : ClusterProvider(org.keycloak.cluster.ClusterProvider) InfinispanKeyGenerator(org.keycloak.models.sessions.infinispan.util.InfinispanKeyGenerator) InfinispanConnectionProvider(org.keycloak.connections.infinispan.InfinispanConnectionProvider)

Aggregations

InfinispanKeyGenerator (org.keycloak.models.sessions.infinispan.util.InfinispanKeyGenerator)2 ClusterProvider (org.keycloak.cluster.ClusterProvider)1 InfinispanConnectionProvider (org.keycloak.connections.infinispan.InfinispanConnectionProvider)1 KeycloakSession (org.keycloak.models.KeycloakSession)1 UserModel (org.keycloak.models.UserModel)1 UserSessionProvider (org.keycloak.models.UserSessionProvider)1 PostMigrationEvent (org.keycloak.models.utils.PostMigrationEvent)1 ResetTimeOffsetEvent (org.keycloak.models.utils.ResetTimeOffsetEvent)1 ProviderEvent (org.keycloak.provider.ProviderEvent)1 ProviderEventListener (org.keycloak.provider.ProviderEventListener)1