From 29c8060bda5f0e70cf9cf4beb8910268ed67edb1 Mon Sep 17 00:00:00 2001 From: Pedro Ruivo Date: Mon, 2 Sep 2024 17:42:42 +0100 Subject: [PATCH] Trigger mass re-index of the sessions caches when the entity changes Closes #32594 Signed-off-by: Pedro Ruivo --- ...nAuthenticationSessionProviderFactory.java | 2 +- .../infinispan/CacheManagerFactory.java | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remote/RemoteInfinispanAuthenticationSessionProviderFactory.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remote/RemoteInfinispanAuthenticationSessionProviderFactory.java index 6ecb496514..0e864788c2 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remote/RemoteInfinispanAuthenticationSessionProviderFactory.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remote/RemoteInfinispanAuthenticationSessionProviderFactory.java @@ -43,7 +43,7 @@ import static org.keycloak.models.sessions.infinispan.InfinispanAuthenticationSe public class RemoteInfinispanAuthenticationSessionProviderFactory implements AuthenticationSessionProviderFactory, EnvironmentDependentProviderFactory { private final static Logger logger = Logger.getLogger(MethodHandles.lookup().lookupClass()); - private static final String PROTO_ENTITY = Marshalling.protoEntity(RootAuthenticationSessionEntity.class); + public static final String PROTO_ENTITY = Marshalling.protoEntity(RootAuthenticationSessionEntity.class); private int authSessionsLimit; private volatile RemoteCache cache; diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/storage/legacy/infinispan/CacheManagerFactory.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/storage/legacy/infinispan/CacheManagerFactory.java index ae5d2b4db2..6bbced667d 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/storage/legacy/infinispan/CacheManagerFactory.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/storage/legacy/infinispan/CacheManagerFactory.java @@ -64,8 +64,10 @@ import org.keycloak.infinispan.util.InfinispanUtils; import org.keycloak.marshalling.KeycloakIndexSchemaUtil; import org.keycloak.marshalling.KeycloakModelSchema; import org.keycloak.marshalling.Marshalling; -import org.keycloak.models.sessions.infinispan.RootAuthenticationSessionAdapter; -import org.keycloak.models.sessions.infinispan.entities.LoginFailureEntity; +import org.keycloak.models.sessions.infinispan.query.ClientSessionQueries; +import org.keycloak.models.sessions.infinispan.query.UserSessionQueries; +import org.keycloak.models.sessions.infinispan.remote.RemoteInfinispanAuthenticationSessionProviderFactory; +import org.keycloak.models.sessions.infinispan.remote.RemoteUserLoginFailureProviderFactory; import org.keycloak.quarkus.runtime.configuration.Configuration; import javax.net.ssl.SSLContext; @@ -245,13 +247,23 @@ public class CacheManagerFactory { var newPS = KeycloakModelSchema.parseProtoSchema(newSchema); var admin = remoteCacheManager.administration(); - if (isEntityChanged(oldPS, newPS, Marshalling.protoEntity(LoginFailureEntity.class))) { + if (isEntityChanged(oldPS, newPS, RemoteUserLoginFailureProviderFactory.PROTO_ENTITY)) { updateSchemaAndReIndexCache(admin, LOGIN_FAILURE_CACHE_NAME); } - if (isEntityChanged(oldPS, newPS, Marshalling.protoEntity(RootAuthenticationSessionAdapter.class))) { + if (isEntityChanged(oldPS, newPS, RemoteInfinispanAuthenticationSessionProviderFactory.PROTO_ENTITY)) { updateSchemaAndReIndexCache(admin, AUTHENTICATION_SESSIONS_CACHE_NAME); } + + if (isEntityChanged(oldPS, newPS, ClientSessionQueries.CLIENT_SESSION)) { + updateSchemaAndReIndexCache(admin, CLIENT_SESSION_CACHE_NAME); + updateSchemaAndReIndexCache(admin, OFFLINE_CLIENT_SESSION_CACHE_NAME); + } + + if (isEntityChanged(oldPS, newPS, UserSessionQueries.USER_SESSION)) { + updateSchemaAndReIndexCache(admin, USER_SESSION_CACHE_NAME); + updateSchemaAndReIndexCache(admin, OFFLINE_USER_SESSION_CACHE_NAME); + } } private static boolean isEntityChanged(FileDescriptor oldSchema, FileDescriptor newSchema, String entity) {