diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProviderFactory.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProviderFactory.java index 963d461062..74d02e5b8c 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProviderFactory.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProviderFactory.java @@ -132,8 +132,6 @@ public class InfinispanUserSessionProviderFactory implements UserSessionProvider offlineSessionsCache, clientSessionCache, offlineClientSessionsCache, - this::deriveOfflineSessionCacheEntryLifespanMs, - this::deriveOfflineClientSessionCacheEntryLifespanOverrideMs, serializerSession, serializerOfflineSession, serializerClientSession, diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/PersistentUserSessionProvider.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/PersistentUserSessionProvider.java index eeeab59f07..eb7e39812a 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/PersistentUserSessionProvider.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/PersistentUserSessionProvider.java @@ -116,10 +116,6 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi protected final RemoteCacheInvoker remoteCacheInvoker; protected final InfinispanKeyGenerator keyGenerator; - protected final SessionFunction offlineSessionCacheEntryLifespanAdjuster; - - protected final SessionFunction offlineClientSessionCacheEntryLifespanAdjuster; - public PersistentUserSessionProvider(KeycloakSession session, RemoteCacheInvoker remoteCacheInvoker, CrossDCLastSessionRefreshStore lastSessionRefreshStore, @@ -130,8 +126,6 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi Cache> offlineSessionCache, Cache> clientSessionCache, Cache> offlineClientSessionCache, - SessionFunction offlineSessionCacheEntryLifespanAdjuster, - SessionFunction offlineClientSessionCacheEntryLifespanAdjuster, SerializeExecutionsByKey serializerSession, SerializeExecutionsByKey serializerOfflineSession, SerializeExecutionsByKey serializerClientSession, @@ -150,12 +144,12 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi this.sessionTx = new UserSessionPersistentChangelogBasedTransaction(session, sessionCache, remoteCacheInvoker, SessionTimeouts::getUserSessionLifespanMs, SessionTimeouts::getUserSessionMaxIdleMs, false, serializerSession, asyncQueuePersistentUpdate); - this.offlineSessionTx = new UserSessionPersistentChangelogBasedTransaction(session, offlineSessionCache, remoteCacheInvoker, offlineSessionCacheEntryLifespanAdjuster, SessionTimeouts::getOfflineSessionMaxIdleMs, true, serializerOfflineSession, + this.offlineSessionTx = new UserSessionPersistentChangelogBasedTransaction(session, offlineSessionCache, remoteCacheInvoker, SessionTimeouts::getUserSessionLifespanMs, SessionTimeouts::getOfflineSessionMaxIdleMs, true, serializerOfflineSession, asyncQueuePersistentUpdate); this.clientSessionTx = new ClientSessionPersistentChangelogBasedTransaction(session, clientSessionCache, remoteCacheInvoker, SessionTimeouts::getClientSessionLifespanMs, SessionTimeouts::getClientSessionMaxIdleMs, false, keyGenerator, sessionTx, serializerClientSession, asyncQueuePersistentUpdate); - this.offlineClientSessionTx = new ClientSessionPersistentChangelogBasedTransaction(session, offlineClientSessionCache, remoteCacheInvoker, offlineClientSessionCacheEntryLifespanAdjuster, SessionTimeouts::getOfflineClientSessionMaxIdleMs, true, keyGenerator, offlineSessionTx, serializerOfflineClientSession, + this.offlineClientSessionTx = new ClientSessionPersistentChangelogBasedTransaction(session, offlineClientSessionCache, remoteCacheInvoker, SessionTimeouts::getClientSessionLifespanMs, SessionTimeouts::getOfflineClientSessionMaxIdleMs, true, keyGenerator, offlineSessionTx, serializerOfflineClientSession, asyncQueuePersistentUpdate); this.clusterEventsSenderTx = new SessionEventsSenderTransaction(session); @@ -165,8 +159,6 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi this.persisterLastSessionRefreshStore = persisterLastSessionRefreshStore; this.remoteCacheInvoker = remoteCacheInvoker; this.keyGenerator = keyGenerator; - this.offlineSessionCacheEntryLifespanAdjuster = offlineSessionCacheEntryLifespanAdjuster; - this.offlineClientSessionCacheEntryLifespanAdjuster = offlineClientSessionCacheEntryLifespanAdjuster; session.getTransactionManager().enlistAfterCompletion(clusterEventsSenderTx); session.getTransactionManager().enlistAfterCompletion(sessionTx); @@ -838,7 +830,7 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi Cache> cache = CacheDecorators.skipCacheLoadersIfRemoteStoreIsEnabled(getCache(offline)); sessionsById = importSessionsWithExpiration(sessionsById, cache, - offline ? offlineSessionCacheEntryLifespanAdjuster : SessionTimeouts::getUserSessionLifespanMs, + offline ? SessionTimeouts::getOfflineSessionLifespanMs : SessionTimeouts::getUserSessionLifespanMs, offline ? SessionTimeouts::getOfflineSessionMaxIdleMs : SessionTimeouts::getUserSessionMaxIdleMs); if (sessionsById.isEmpty()) { @@ -853,7 +845,7 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi .collect(Collectors.toMap(sessionEntityWrapper -> sessionEntityWrapper.getEntity().getId(), Function.identity())); importSessionsWithExpiration(sessionsByIdForTransport, remoteCache, - offline ? offlineSessionCacheEntryLifespanAdjuster : SessionTimeouts::getUserSessionLifespanMs, + offline ? SessionTimeouts::getOfflineSessionLifespanMs : SessionTimeouts::getUserSessionLifespanMs, offline ? SessionTimeouts::getOfflineSessionMaxIdleMs : SessionTimeouts::getUserSessionMaxIdleMs); } @@ -862,7 +854,7 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi CacheDecorators.skipCacheLoadersIfRemoteStoreIsEnabled(offline ? offlineClientSessionCache : clientSessionCache); importSessionsWithExpiration(clientSessionsById, clientSessCache, - offline ? offlineClientSessionCacheEntryLifespanAdjuster : SessionTimeouts::getClientSessionLifespanMs, + offline ? SessionTimeouts::getOfflineClientSessionLifespanMs : SessionTimeouts::getClientSessionLifespanMs, offline ? SessionTimeouts::getOfflineClientSessionMaxIdleMs : SessionTimeouts::getClientSessionMaxIdleMs); // put all entities to the remoteCache (if exists) @@ -873,7 +865,7 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi .collect(Collectors.toMap(sessionEntityWrapper -> sessionEntityWrapper.getEntity().getId(), Function.identity())); importSessionsWithExpiration(sessionsByIdForTransport, remoteCacheClientSessions, - offline ? offlineClientSessionCacheEntryLifespanAdjuster : SessionTimeouts::getClientSessionLifespanMs, + offline ? SessionTimeouts::getOfflineClientSessionLifespanMs : SessionTimeouts::getClientSessionLifespanMs, offline ? SessionTimeouts::getOfflineClientSessionMaxIdleMs : SessionTimeouts::getClientSessionMaxIdleMs); } @@ -965,7 +957,7 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi if (checkExpiration) { SessionFunction lifespanChecker = offline - ? offlineClientSessionCacheEntryLifespanAdjuster : SessionTimeouts::getClientSessionLifespanMs; + ? SessionTimeouts::getOfflineClientSessionLifespanMs : SessionTimeouts::getClientSessionLifespanMs; SessionFunction idleTimeoutChecker = offline ? SessionTimeouts::getOfflineClientSessionMaxIdleMs : SessionTimeouts::getClientSessionMaxIdleMs; if (idleTimeoutChecker.apply(sessionToImportInto.getRealm(), clientSession.getClient(), entity) == SessionTimeouts.ENTRY_EXPIRED_FLAG diff --git a/testsuite/model/src/test/java/org/keycloak/testsuite/model/session/UserSessionProviderOfflineModelTest.java b/testsuite/model/src/test/java/org/keycloak/testsuite/model/session/UserSessionProviderOfflineModelTest.java index 0fd58d6985..84a7dd1b19 100644 --- a/testsuite/model/src/test/java/org/keycloak/testsuite/model/session/UserSessionProviderOfflineModelTest.java +++ b/testsuite/model/src/test/java/org/keycloak/testsuite/model/session/UserSessionProviderOfflineModelTest.java @@ -481,8 +481,8 @@ public class UserSessionProviderOfflineModelTest extends KeycloakModelTest { public void testOfflineSessionLifespanOverride() { // skip the test for CrossDC Assume.assumeFalse(Objects.equals(CONFIG.scope("connectionsInfinispan.default").get("remoteStoreEnabled"), "true")); - // As we don't put things in the embedded cache, the test will fail as the number of entries will always be 0. - Assume.assumeFalse(Profile.isFeatureEnabled(Profile.Feature.PERSISTENT_USER_SESSIONS_NO_CACHE)); + // As offline session's timeout is not overriden when PERSISTENT_USER_SESSIONS is enabled + Assume.assumeFalse(Profile.isFeatureEnabled(Profile.Feature.PERSISTENT_USER_SESSIONS)); createOfflineSessions("user1", 2, new LinkedList<>(), new LinkedList<>());