diff --git a/model/infinispan/src/main/java/org/keycloak/connections/infinispan/InfinispanUtil.java b/model/infinispan/src/main/java/org/keycloak/connections/infinispan/InfinispanUtil.java index 847a47f529..5d3c9ec7da 100644 --- a/model/infinispan/src/main/java/org/keycloak/connections/infinispan/InfinispanUtil.java +++ b/model/infinispan/src/main/java/org/keycloak/connections/infinispan/InfinispanUtil.java @@ -41,7 +41,6 @@ import org.infinispan.factories.impl.ComponentRef; import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.persistence.manager.PersistenceManager; import org.infinispan.persistence.remote.RemoteStore; -import org.infinispan.remoting.transport.Transport; import org.infinispan.remoting.transport.jgroups.JGroupsTransport; import org.infinispan.util.EmbeddedTimeService; import org.jboss.logging.Logger; @@ -79,16 +78,6 @@ public class InfinispanUtil { } - /** - * - * @param cache - * @return true if cluster coordinator OR if it's local cache - */ - public static boolean isCoordinator(Cache cache) { - Transport transport = cache.getCacheManager().getTransport(); - return transport == null || transport.isCoordinator(); - } - /** * Convert the given value to the proper value, which can be used when calling operations for the infinispan remoteCache. * diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/CacheManager.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/CacheManager.java index 9703a1518f..c1e6d89666 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/CacheManager.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/CacheManager.java @@ -134,7 +134,7 @@ public abstract class CacheManager { protected void bumpVersion(String id) { long next = counter.next(); - Object rev = revisions.put(id, next); + revisions.put(id, next); } public void addRevisioned(Revisioned object, long startupRevision) { diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmCacheManager.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmCacheManager.java index 5a6c8d0b00..2e51914aea 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmCacheManager.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmCacheManager.java @@ -102,7 +102,7 @@ public class RealmCacheManager extends CacheManager { addInvalidations(InGroupPredicate.create().group(groupId), invalidations); } - public void clientAdded(String realmId, String clientUUID, String clientId, Set invalidations) { + public void clientAdded(String realmId, Set invalidations) { invalidations.add(RealmCacheSession.getRealmClientsQueryCacheKey(realmId)); } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmCacheSession.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmCacheSession.java index 700ce7c469..8273636310 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmCacheSession.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmCacheSession.java @@ -122,7 +122,6 @@ public class RealmCacheSession implements CacheRealmProvider { protected Set invalidations = new HashSet<>(); protected Set invalidationEvents = new HashSet<>(); // Events to be sent across cluster - protected boolean clearAll; protected final long startupRevision; private final StoreManagers datastoreProvider; @@ -135,14 +134,6 @@ public class RealmCacheSession implements CacheRealmProvider { session.getTransactionManager().enlistAfterCompletion(getAfterTransaction()); } - public long getStartupRevision() { - return startupRevision; - } - - public boolean isInvalid(String id) { - return invalidations.contains(id); - } - @Override public void clear() { ClusterProvider cluster = session.getProvider(ClusterProvider.class); @@ -355,9 +346,6 @@ public class RealmCacheSession implements CacheRealmProvider { @Override public void commit() { try { - if (clearAll) { - cache.clear(); - } runInvalidations(); transactionActive = false; } finally { @@ -551,7 +539,7 @@ public class RealmCacheSession implements CacheRealmProvider { listInvalidations.add(realm.getId()); invalidationEvents.add(ClientAddedEvent.create(client.getId(), client.getClientId(), realm.getId())); - cache.clientAdded(realm.getId(), client.getId(), client.getClientId(), invalidations); + cache.clientAdded(realm.getId(), invalidations); return client; } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserAdapter.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserAdapter.java index c8fee2dbf3..3379ad0e49 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserAdapter.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserAdapter.java @@ -99,7 +99,7 @@ public class UserAdapter implements CachedUserModel { @Override public UserModel getDelegateForUpdate() { if (updated == null) { - userProviderCache.registerUserInvalidation(realm, cached); + userProviderCache.registerUserInvalidation(cached); updated = modelSupplier.get(); if (updated == null) throw new IllegalStateException("Not found in database"); } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserCacheManager.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserCacheManager.java index 9126b2f499..c381e23809 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserCacheManager.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserCacheManager.java @@ -34,8 +34,6 @@ public class UserCacheManager extends CacheManager { private static final Logger logger = Logger.getLogger(UserCacheManager.class); - protected volatile boolean enabled = true; - public UserCacheManager(Cache cache, Cache revisions) { super(cache, revisions); } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserCacheSession.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserCacheSession.java index 5457122351..f0ed6314db 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserCacheSession.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserCacheSession.java @@ -120,7 +120,7 @@ public class UserCacheSession implements UserCache, OnCreateComponent, OnUpdateC return delegate; } - public void registerUserInvalidation(RealmModel realm,CachedUser user) { + public void registerUserInvalidation(CachedUser user) { cache.userUpdatedInvalidations(user.getId(), user.getUsername(), user.getEmail(), user.getRealm(), invalidations); invalidationEvents.add(UserUpdatedEvent.create(user.getId(), user.getUsername(), user.getEmail(), user.getRealm())); } @@ -326,7 +326,7 @@ public class UserCacheSession implements UserCache, OnCreateComponent, OnUpdateC // although we do set a timeout, Infinispan has no guarantees when the user will be evicted // its also hard to test stuff if (model.shouldInvalidate(cached)) { - registerUserInvalidation(realm, cached); + registerUserInvalidation(cached); return getDelegate().getUserById(realm, cached.getId()); } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/StoreFactoryCacheSession.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/StoreFactoryCacheSession.java index 2424a6462a..02d00da7ac 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/StoreFactoryCacheSession.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/StoreFactoryCacheSession.java @@ -99,7 +99,6 @@ public class StoreFactoryCacheSession implements CachedStoreFactoryProvider { protected Set invalidations = new HashSet<>(); protected Set invalidationEvents = new HashSet<>(); // Events to be sent across cluster - protected boolean clearAll; protected final long startupRevision; protected StoreFactory delegate; protected KeycloakSession session; @@ -250,16 +249,6 @@ public class StoreFactoryCacheSession implements CachedStoreFactoryProvider { cache.sendInvalidationEvents(session, invalidationEvents, InfinispanCacheStoreFactoryProviderFactory.AUTHORIZATION_INVALIDATION_EVENTS); } - - - public long getStartupRevision() { - return startupRevision; - } - - public boolean isInvalid(String id) { - return invalidations.contains(id); - } - public void registerResourceServerInvalidation(String id) { cache.resourceServerUpdated(id, invalidations); ResourceServerAdapter adapter = managedResourceServers.get(id); diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/entities/ResourceServerListQuery.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/entities/ResourceServerListQuery.java deleted file mode 100755 index 3c9a348525..0000000000 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/entities/ResourceServerListQuery.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.keycloak.models.cache.infinispan.authorization.entities; - -import org.keycloak.models.cache.infinispan.entities.AbstractRevisioned; - -import java.util.HashSet; -import java.util.Set; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class ResourceServerListQuery extends AbstractRevisioned { - private final Set servers; - - public ResourceServerListQuery(Long revision, String id, String serverId) { - super(revision, id); - servers = new HashSet<>(); - servers.add(serverId); - } - public ResourceServerListQuery(Long revision, String id, Set servers) { - super(revision, id); - this.servers = servers; - } - - public Set getResourceServers() { - return servers; - } -} \ No newline at end of file diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedClient.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedClient.java index 10dc3c40fa..239dc5c91b 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedClient.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedClient.java @@ -17,21 +17,18 @@ package org.keycloak.models.cache.infinispan.entities; -import org.keycloak.models.ClientModel; -import org.keycloak.models.ClientScopeModel; -import org.keycloak.models.ProtocolMapperModel; -import org.keycloak.models.RealmModel; -import org.keycloak.models.RoleModel; - import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; import java.util.stream.Collectors; +import org.keycloak.models.ClientModel; +import org.keycloak.models.ProtocolMapperModel; +import org.keycloak.models.RealmModel; +import org.keycloak.models.RoleModel; + /** * @author Bill Burke * @version $Revision: 1 $ @@ -69,8 +66,6 @@ public class CachedClient extends AbstractRevisioned implements InRealm { protected boolean serviceAccountsEnabled; protected int nodeReRegistrationTimeout; protected Map registeredNodes; - protected List defaultClientScopesIds; - protected List optionalClientScopesIds; public CachedClient(Long revision, RealmModel realm, ClientModel model) { super(revision, model.getId()); @@ -107,15 +102,6 @@ public class CachedClient extends AbstractRevisioned implements InRealm { nodeReRegistrationTimeout = model.getNodeReRegistrationTimeout(); registeredNodes = new TreeMap<>(model.getRegisteredNodes()); - - defaultClientScopesIds = new LinkedList<>(); - for (ClientScopeModel clientScope : model.getClientScopes(true).values()) { - defaultClientScopesIds.add(clientScope.getId()); - } - optionalClientScopesIds = new LinkedList<>(); - for (ClientScopeModel clientScope : model.getClientScopes(false).values()) { - optionalClientScopesIds.add(clientScope.getId()); - } } public String getClientId() { @@ -242,14 +228,6 @@ public class CachedClient extends AbstractRevisioned implements InRealm { return registeredNodes; } - public List getDefaultClientScopesIds() { - return defaultClientScopesIds; - } - - public List getOptionalClientScopesIds() { - return optionalClientScopesIds; - } - public Map getAuthFlowBindings() { return authFlowBindings; } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedRealm.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedRealm.java index 3e206af4ef..29e3c8c0fc 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedRealm.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedRealm.java @@ -17,6 +17,16 @@ package org.keycloak.models.cache.infinispan.entities; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collectors; + import org.keycloak.common.enums.SslRequired; import org.keycloak.common.util.MultivaluedHashMap; import org.keycloak.component.ComponentModel; @@ -40,17 +50,6 @@ import org.keycloak.models.WebAuthnPolicy; import org.keycloak.models.cache.infinispan.DefaultLazyLoader; import org.keycloak.models.cache.infinispan.LazyLoader; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.Collectors; - /** * @author Bill Burke * @version $Revision: 1 $ @@ -151,7 +150,6 @@ public class CachedRealm extends AbstractExtendableRevisioned { protected Set eventsListeners; protected Set enabledEventTypes; protected boolean adminEventsEnabled; - protected Set adminEnabledEventOperations = new HashSet<>(); protected boolean adminEventsDetailsEnabled; protected String defaultRoleId; private boolean allowUserManagedAccess; @@ -597,10 +595,6 @@ public class CachedRealm extends AbstractExtendableRevisioned { return adminEventsEnabled; } - public Set getAdminEnabledEventOperations() { - return adminEnabledEventOperations; - } - public boolean isAdminEventsDetailsEnabled() { return adminEventsDetailsEnabled; } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/GroupListQuery.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/GroupListQuery.java index 4c9b607f07..52ed4d693b 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/GroupListQuery.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/GroupListQuery.java @@ -15,7 +15,7 @@ import java.util.stream.Collectors; public class GroupListQuery extends AbstractRevisioned implements GroupQuery { private final String realm; private final String realmName; - private Map> searchKeys; + private final Map> searchKeys; public GroupListQuery(Long revisioned, String id, RealmModel realm, String searchKey, Set result) { super(revisioned, id); @@ -62,13 +62,6 @@ public class GroupListQuery extends AbstractRevisioned implements GroupQuery { return realm; } - public Map> getSearchKeys() { - if (searchKeys == null) { - searchKeys = new HashMap<>(); - } - return searchKeys; - } - @Override public String toString() { return "GroupListQuery{" + diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientAddedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientAddedEvent.java index bf440935d8..570fbdaf48 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientAddedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientAddedEvent.java @@ -58,7 +58,7 @@ public class ClientAddedEvent extends InvalidationEvent implements RealmCacheInv @Override public void addInvalidations(RealmCacheManager realmCache, Set invalidations) { - realmCache.clientAdded(realmId, clientUuid, clientId, invalidations); + realmCache.clientAdded(realmId, invalidations); } @Override diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/Consumers.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/Consumers.java deleted file mode 100644 index 19cb7c7560..0000000000 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/Consumers.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.models.sessions.infinispan; - -import org.keycloak.models.RealmModel; -import org.keycloak.models.UserSessionModel; -import org.keycloak.models.sessions.infinispan.entities.SessionEntity; -import org.keycloak.models.sessions.infinispan.entities.UserSessionEntity; - -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.function.Consumer; - -/** - * @author Stian Thorgersen - */ -public class Consumers { - - private Consumers() { - } - - public static UserSessionModelsConsumer userSessionModels(InfinispanUserSessionProvider provider, RealmModel realm, boolean offline) { - return new UserSessionModelsConsumer(provider, realm, offline); - } - - public static class UserSessionModelsConsumer implements Consumer> { - - private InfinispanUserSessionProvider provider; - private RealmModel realm; - private boolean offline; - private List sessions = new LinkedList<>(); - - private UserSessionModelsConsumer(InfinispanUserSessionProvider provider, RealmModel realm, boolean offline) { - this.provider = provider; - this.realm = realm; - this.offline = offline; - } - - @Override - public void accept(Map.Entry entry) { - SessionEntity e = entry.getValue(); - sessions.add(provider.wrap(realm, (UserSessionEntity) e, offline)); - } - - public List getSessions() { - return sessions; - } - - } -} diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanAuthenticationSessionProvider.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanAuthenticationSessionProvider.java index 1809250cf0..051a377ae3 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanAuthenticationSessionProvider.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanAuthenticationSessionProvider.java @@ -46,8 +46,6 @@ import org.keycloak.sessions.RootAuthenticationSessionModel; */ public class InfinispanAuthenticationSessionProvider implements AuthenticationSessionProvider { - private static final Logger log = Logger.getLogger(InfinispanAuthenticationSessionProvider.class); - private final KeycloakSession session; private final Cache cache; private final InfinispanKeyGenerator keyGenerator; @@ -142,10 +140,6 @@ public class InfinispanAuthenticationSessionProvider implements AuthenticationSe // ClusterProvider.DCNotify.ALL_DCS); } - protected void onClientRemovedEvent(String realmId, String clientUuid) { - - } - @Override public void updateNonlocalSessionAuthNotes(AuthenticationSessionCompoundId compoundId, Map authNotesFragment) { diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanAuthenticationSessionProviderFactory.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanAuthenticationSessionProviderFactory.java index 450f3471eb..6280738902 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanAuthenticationSessionProviderFactory.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanAuthenticationSessionProviderFactory.java @@ -28,7 +28,6 @@ import org.keycloak.models.cache.infinispan.events.AuthenticationSessionAuthNote import org.keycloak.models.sessions.infinispan.entities.AuthenticationSessionEntity; import org.keycloak.models.sessions.infinispan.entities.RootAuthenticationSessionEntity; import org.keycloak.models.sessions.infinispan.events.AbstractAuthSessionClusterListener; -import org.keycloak.models.sessions.infinispan.events.ClientRemovedSessionEvent; import org.keycloak.models.sessions.infinispan.events.RealmRemovedSessionEvent; import org.keycloak.models.sessions.infinispan.util.InfinispanKeyGenerator; import org.keycloak.models.utils.KeycloakModelUtils; @@ -69,8 +68,6 @@ public class InfinispanAuthenticationSessionProviderFactory implements Authentic public static final String REALM_REMOVED_AUTHSESSION_EVENT = "REALM_REMOVED_EVENT_AUTHSESSIONS"; - public static final String CLIENT_REMOVED_AUTHSESSION_EVENT = "CLIENT_REMOVED_SESSION_AUTHSESSIONS"; - @Override public void init(Config.Scope config) { // get auth sessions limit from config or use default if not provided @@ -117,20 +114,12 @@ public class InfinispanAuthenticationSessionProviderFactory implements Authentic cluster.registerListener(REALM_REMOVED_AUTHSESSION_EVENT, new AbstractAuthSessionClusterListener(sessionFactory) { @Override - protected void eventReceived(KeycloakSession session, InfinispanAuthenticationSessionProvider provider, RealmRemovedSessionEvent sessionEvent) { + protected void eventReceived(InfinispanAuthenticationSessionProvider provider, RealmRemovedSessionEvent sessionEvent) { provider.onRealmRemovedEvent(sessionEvent.getRealmId()); } }); - cluster.registerListener(CLIENT_REMOVED_AUTHSESSION_EVENT, new AbstractAuthSessionClusterListener(sessionFactory) { - - @Override - protected void eventReceived(KeycloakSession session, InfinispanAuthenticationSessionProvider provider, ClientRemovedSessionEvent sessionEvent) { - provider.onClientRemovedEvent(sessionEvent.getRealmId(), sessionEvent.getClientUuid()); - } - }); - log.debug("Registered cluster listeners"); } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanKeycloakTransaction.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanKeycloakTransaction.java index df77c2f32b..177f9092e8 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanKeycloakTransaction.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanKeycloakTransaction.java @@ -18,8 +18,6 @@ package org.keycloak.models.sessions.infinispan; import org.infinispan.client.hotrod.RemoteCache; import org.infinispan.commons.api.BasicCache; -import org.keycloak.cluster.ClusterEvent; -import org.keycloak.cluster.ClusterProvider; import org.infinispan.context.Flag; import org.keycloak.models.KeycloakTransaction; @@ -52,7 +50,7 @@ public class InfinispanKeycloakTransaction implements KeycloakTransaction { }; public enum CacheOperation { - ADD, ADD_WITH_LIFESPAN, REMOVE, REPLACE, ADD_IF_ABSENT // ADD_IF_ABSENT throws an exception if there is existing value + ADD_WITH_LIFESPAN, REMOVE, REPLACE } private boolean active; @@ -93,32 +91,6 @@ public class InfinispanKeycloakTransaction implements KeycloakTransaction { return active; } - public void put(Cache cache, K key, V value) { - log.tracev("Adding cache operation: {0} on {1}", CacheOperation.ADD, key); - - Object taskKey = getTaskKey(cache, key); - if (tasks.containsKey(taskKey)) { - throw new IllegalStateException("Can't add session: task in progress for session"); - } else { - tasks.put(taskKey, new CacheTaskWithValue(value) { - @Override - public void execute() { - decorateCache(cache).put(key, value); - } - - @Override - public String toString() { - return String.format("CacheTaskWithValue: Operation 'put' for key %s", key); - } - - @Override - public Operation getOperation() { - return Operation.PUT; - } - }); - } - } - public void put(BasicCache cache, K key, V value, long lifespan, TimeUnit lifespanUnit) { log.tracev("Adding cache operation: {0} on {1}", CacheOperation.ADD_WITH_LIFESPAN, key); @@ -145,35 +117,6 @@ public class InfinispanKeycloakTransaction implements KeycloakTransaction { } } - public void putIfAbsent(Cache cache, K key, V value) { - log.tracev("Adding cache operation: {0} on {1}", CacheOperation.ADD_IF_ABSENT, key); - - Object taskKey = getTaskKey(cache, key); - if (tasks.containsKey(taskKey)) { - throw new IllegalStateException("Can't add session: task in progress for session"); - } else { - tasks.put(taskKey, new CacheTaskWithValue(value) { - @Override - public void execute() { - V existing = cache.putIfAbsent(key, value); - if (existing != null) { - throw new IllegalStateException("There is already existing value in cache for key " + key); - } - } - - @Override - public String toString() { - return String.format("CacheTaskWithValue: Operation 'putIfAbsent' for key %s", key); - } - - @Override - public Operation getOperation() { - return Operation.PUT; - } - }); - } - } - public void replace(Cache cache, K key, V value, long lifespan, TimeUnit lifespanUnit) { log.tracev("Adding cache operation: {0} on {1}. Lifespan {2} {3}.", CacheOperation.REPLACE, key, lifespan, lifespanUnit); @@ -200,18 +143,6 @@ public class InfinispanKeycloakTransaction implements KeycloakTransaction { } } - public void notify(ClusterProvider clusterProvider, String taskKey, ClusterEvent event, boolean ignoreSender) { - log.tracev("Adding cache operation SEND_EVENT: {0}", event); - - String theTaskKey = taskKey; - int i = 1; - while (tasks.containsKey(theTaskKey)) { - theTaskKey = taskKey + "-" + (i++); - } - - tasks.put(taskKey, () -> clusterProvider.notify(taskKey, event, ignoreSender, ClusterProvider.DCNotify.ALL_DCS)); - } - public void remove(BasicCache cache, K key) { log.tracev("Adding cache operation: {0} on {1}", CacheOperation.REMOVE, key); @@ -278,10 +209,6 @@ public class InfinispanKeycloakTransaction implements KeycloakTransaction { protected long lifespan; protected TimeUnit lifespanUnit; - public CacheTaskWithValue(V value) { - this(value, -1, TimeUnit.SECONDS); - } - public CacheTaskWithValue(V value, long lifespan, TimeUnit lifespanUnit) { this.value = value; this.lifespan = lifespan; diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanSingleUseObjectProvider.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanSingleUseObjectProvider.java index 714ae30d62..0108d39574 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanSingleUseObjectProvider.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanSingleUseObjectProvider.java @@ -25,10 +25,10 @@ import org.infinispan.client.hotrod.exceptions.HotRodClientException; import org.infinispan.commons.api.BasicCache; import org.jboss.logging.Logger; import org.keycloak.common.util.Time; +import org.keycloak.connections.infinispan.InfinispanUtil; import org.keycloak.models.KeycloakSession; import org.keycloak.models.SingleUseObjectProvider; import org.keycloak.models.sessions.infinispan.entities.SingleUseObjectValueEntity; -import org.keycloak.connections.infinispan.InfinispanUtil; /** * TODO: Check if Boolean can be used as single-use cache argument instead of SingleUseObjectValueEntity. With respect to other single-use cache usecases like "Revoke Refresh Token" . @@ -42,14 +42,11 @@ public class InfinispanSingleUseObjectProvider implements SingleUseObjectProvide public static final Logger logger = Logger.getLogger(InfinispanSingleUseObjectProvider.class); private final Supplier> singleUseObjectCache; - private final KeycloakSession session; private final InfinispanKeycloakTransaction tx; public InfinispanSingleUseObjectProvider(KeycloakSession session, Supplier> singleUseObjectCache) { - this.session = session; this.singleUseObjectCache = singleUseObjectCache; this.tx = new InfinispanKeycloakTransaction(); - session.getTransactionManager().enlistAfterCompletion(tx); } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserLoginFailureProviderFactory.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserLoginFailureProviderFactory.java index 1aeac3f9f9..467fc4f9e7 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserLoginFailureProviderFactory.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserLoginFailureProviderFactory.java @@ -112,7 +112,7 @@ public class InfinispanUserLoginFailureProviderFactory implements UserLoginFailu new AbstractUserSessionClusterListener(sessionFactory, UserLoginFailureProvider.class) { @Override - protected void eventReceived(KeycloakSession session, UserLoginFailureProvider provider, RealmRemovedSessionEvent sessionEvent) { + protected void eventReceived(UserLoginFailureProvider provider, RealmRemovedSessionEvent sessionEvent) { if (provider instanceof InfinispanUserLoginFailureProvider) { ((InfinispanUserLoginFailureProvider) provider).removeAllLocalUserLoginFailuresEvent(sessionEvent.getRealmId()); } @@ -123,7 +123,7 @@ public class InfinispanUserLoginFailureProviderFactory implements UserLoginFailu new AbstractUserSessionClusterListener(sessionFactory, UserLoginFailureProvider.class) { @Override - protected void eventReceived(KeycloakSession session, UserLoginFailureProvider provider, RemoveAllUserLoginFailuresEvent sessionEvent) { + protected void eventReceived(UserLoginFailureProvider provider, RemoveAllUserLoginFailuresEvent sessionEvent) { if (provider instanceof InfinispanUserLoginFailureProvider) { ((InfinispanUserLoginFailureProvider) provider).removeAllLocalUserLoginFailuresEvent(sessionEvent.getRealmId()); } @@ -200,7 +200,7 @@ public class InfinispanUserLoginFailureProviderFactory implements UserLoginFailu .getCacheConfiguration().clustering().stateTransfer().timeout() / 1000); InfinispanCacheInitializer initializer = new InfinispanCacheInitializer(sessionFactory, workCache, - new RemoteCacheSessionsLoader(cacheName, sessionsPerSegment), "remoteCacheLoad::" + cacheName, sessionsPerSegment, maxErrors, + new RemoteCacheSessionsLoader(cacheName, sessionsPerSegment), "remoteCacheLoad::" + cacheName, maxErrors, getStalledTimeoutInSeconds(defaultStateTransferTimeout)); initializer.initCache(); diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java index 54fc874754..70504b5fb2 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java @@ -113,7 +113,6 @@ public class InfinispanUserSessionProvider implements UserSessionProvider, Sessi protected final CrossDCLastSessionRefreshStore offlineLastSessionRefreshStore; protected final PersisterLastSessionRefreshStore persisterLastSessionRefreshStore; - protected final RemoteCacheInvoker remoteCacheInvoker; protected final InfinispanKeyGenerator keyGenerator; protected final SessionFunction offlineSessionCacheEntryLifespanAdjuster; @@ -153,7 +152,6 @@ public class InfinispanUserSessionProvider implements UserSessionProvider, Sessi this.lastSessionRefreshStore = lastSessionRefreshStore; this.offlineLastSessionRefreshStore = offlineLastSessionRefreshStore; this.persisterLastSessionRefreshStore = persisterLastSessionRefreshStore; - this.remoteCacheInvoker = remoteCacheInvoker; this.keyGenerator = keyGenerator; this.offlineSessionCacheEntryLifespanAdjuster = offlineSessionCacheEntryLifespanAdjuster; this.offlineClientSessionCacheEntryLifespanAdjuster = offlineClientSessionCacheEntryLifespanAdjuster; @@ -717,10 +715,6 @@ public class InfinispanUserSessionProvider implements UserSessionProvider, Sessi } } - protected void onClientRemovedEvent(String realmId, String clientUuid) { - // Nothing for now. userSession.getAuthenticatedClientSessions() will check lazily if particular client exists and update userSession on-the-fly. - } - protected void onUserRemoved(RealmModel realm, UserModel user) { removeUserSessions(realm, user, true); @@ -789,7 +783,6 @@ public class InfinispanUserSessionProvider implements UserSessionProvider, Sessi } AuthenticatedClientSessionAdapter wrap(UserSessionModel userSession, ClientModel client, AuthenticatedClientSessionEntity entity, boolean offline) { - InfinispanChangelogBasedTransaction userSessionUpdateTx = getTransaction(offline); InfinispanChangelogBasedTransaction clientSessionUpdateTx = getClientSessionTransaction(offline); return entity != null ? new AuthenticatedClientSessionAdapter(session, this, entity, client, userSession, clientSessionUpdateTx, offline) : null; } @@ -1151,7 +1144,7 @@ public class InfinispanUserSessionProvider implements UserSessionProvider, Sessi } @Override - public CacheOperation getOperation(UserSessionEntity session) { + public CacheOperation getOperation() { return CacheOperation.REPLACE; } 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 306209890c..745b4ba487 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 @@ -48,7 +48,6 @@ import org.keycloak.models.sessions.infinispan.entities.AuthenticatedClientSessi import org.keycloak.models.sessions.infinispan.entities.SessionEntity; import org.keycloak.models.sessions.infinispan.entities.UserSessionEntity; import org.keycloak.models.sessions.infinispan.events.AbstractUserSessionClusterListener; -import org.keycloak.models.sessions.infinispan.events.ClientRemovedSessionEvent; import org.keycloak.models.sessions.infinispan.events.RealmRemovedSessionEvent; import org.keycloak.models.sessions.infinispan.events.RemoveUserSessionsEvent; import org.keycloak.models.sessions.infinispan.initializer.InfinispanCacheInitializer; @@ -85,8 +84,6 @@ public class InfinispanUserSessionProviderFactory implements UserSessionProvider public static final String REALM_REMOVED_SESSION_EVENT = "REALM_REMOVED_EVENT_SESSIONS"; - public static final String CLIENT_REMOVED_SESSION_EVENT = "CLIENT_REMOVED_SESSION_SESSIONS"; - public static final String REMOVE_USER_SESSIONS_EVENT = "REMOVE_USER_SESSIONS_EVENT"; public static final String CONFIG_OFFLINE_SESSION_CACHE_ENTRY_LIFESPAN_OVERRIDE = "offlineSessionCacheEntryLifespanOverride"; public static final String CONFIG_OFFLINE_CLIENT_SESSION_CACHE_ENTRY_LIFESPAN_OVERRIDE = "offlineClientSessionCacheEntryLifespanOverride"; @@ -255,7 +252,7 @@ public class InfinispanUserSessionProviderFactory implements UserSessionProvider new AbstractUserSessionClusterListener(sessionFactory, UserSessionProvider.class) { @Override - protected void eventReceived(KeycloakSession session, UserSessionProvider provider, RealmRemovedSessionEvent sessionEvent) { + protected void eventReceived(UserSessionProvider provider, RealmRemovedSessionEvent sessionEvent) { if (provider instanceof InfinispanUserSessionProvider) { ((InfinispanUserSessionProvider) provider).onRealmRemovedEvent(sessionEvent.getRealmId()); } else if (provider instanceof PersistentUserSessionProvider) { @@ -265,25 +262,11 @@ public class InfinispanUserSessionProviderFactory implements UserSessionProvider }); - cluster.registerListener(CLIENT_REMOVED_SESSION_EVENT, - new AbstractUserSessionClusterListener(sessionFactory, UserSessionProvider.class) { - - @Override - protected void eventReceived(KeycloakSession session, UserSessionProvider provider, ClientRemovedSessionEvent sessionEvent) { - if (provider instanceof InfinispanUserSessionProvider) { - ((InfinispanUserSessionProvider) provider).onClientRemovedEvent(sessionEvent.getRealmId(), sessionEvent.getClientUuid()); - } else if (provider instanceof PersistentUserSessionProvider) { - ((PersistentUserSessionProvider) provider).onClientRemovedEvent(sessionEvent.getRealmId(), sessionEvent.getClientUuid()); - } - } - - }); - cluster.registerListener(REMOVE_USER_SESSIONS_EVENT, new AbstractUserSessionClusterListener(sessionFactory, UserSessionProvider.class) { @Override - protected void eventReceived(KeycloakSession session, UserSessionProvider provider, RemoveUserSessionsEvent sessionEvent) { + protected void eventReceived(UserSessionProvider provider, RemoveUserSessionsEvent sessionEvent) { if (provider instanceof InfinispanUserSessionProvider) { ((InfinispanUserSessionProvider) provider).onRemoveUserSessionsEvent(sessionEvent.getRealmId()); } else if (provider instanceof PersistentUserSessionProvider) { @@ -414,7 +397,7 @@ public class InfinispanUserSessionProviderFactory implements UserSessionProvider .getCacheConfiguration().clustering().stateTransfer().timeout() / 1000); InfinispanCacheInitializer initializer = new InfinispanCacheInitializer(sessionFactory, workCache, - new RemoteCacheSessionsLoader(cacheName, sessionsPerSegment), "remoteCacheLoad::" + cacheName, sessionsPerSegment, maxErrors, + new RemoteCacheSessionsLoader(cacheName, sessionsPerSegment), "remoteCacheLoad::" + cacheName, maxErrors, getStalledTimeoutInSeconds(defaultStateTransferTimeout)); initializer.initCache(); 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 07bad6a84a..ad0b1cd71d 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 @@ -108,7 +108,6 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi protected final CrossDCLastSessionRefreshStore lastSessionRefreshStore; protected final CrossDCLastSessionRefreshStore offlineLastSessionRefreshStore; - protected final RemoteCacheInvoker remoteCacheInvoker; protected final InfinispanKeyGenerator keyGenerator; public PersistentUserSessionProvider(KeycloakSession session, @@ -151,7 +150,6 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi this.lastSessionRefreshStore = lastSessionRefreshStore; this.offlineLastSessionRefreshStore = offlineLastSessionRefreshStore; - this.remoteCacheInvoker = remoteCacheInvoker; this.keyGenerator = keyGenerator; session.getTransactionManager().enlistAfterCompletion(clusterEventsSenderTx); @@ -276,10 +274,10 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi return entityWrapper != null ? entityWrapper.getEntity() : null; } - private Stream getUserSessionsFromPersistenceProviderStream(RealmModel realm, UserModel user, boolean offline) { + private Stream getUserSessionsFromPersistenceProviderStream(RealmModel realm, UserModel user) { UserSessionPersisterProvider persister = session.getProvider(UserSessionPersisterProvider.class); - return persister.loadUserSessionsStream(realm, user, offline, 0, null) - .map(persistentUserSession -> (UserSessionModel) getUserSession(realm, persistentUserSession.getId(), offline)) + return persister.loadUserSessionsStream(realm, user, true, 0, null) + .map(persistentUserSession -> (UserSessionModel) getUserSession(realm, persistentUserSession.getId(), true)) .filter(Objects::nonNull); } @@ -336,9 +334,9 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi if (predicate.getBrokerSessionId() != null && !offline) { // we haven't yet migrated the old offline entries, so they don't have a brokerSessionId yet - return Stream.of(persister.loadUserSessionsStreamByBrokerSessionId(realm, predicate.getBrokerSessionId(), offline)) + return Stream.of(persister.loadUserSessionsStreamByBrokerSessionId(realm, predicate.getBrokerSessionId(), false)) .filter(predicate.toModelPredicate()) - .map(s -> (UserSessionModel) getUserSession(realm, s.getId(), offline)) + .map(s -> (UserSessionModel) getUserSession(realm, s.getId(), false)) .filter(Objects::nonNull); } @@ -590,11 +588,6 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi } } - protected void onClientRemovedEvent(String realmId, String clientUuid) { - // Nothing for now. userSession.getAuthenticatedClientSessions() will check lazily if particular client exists and update userSession on-the-fly. - } - - protected void onUserRemoved(RealmModel realm, UserModel user) { removeUserSessions(realm, user, true); removeUserSessions(realm, user, false); @@ -630,7 +623,7 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi } UserSessionAdapter wrap(RealmModel realm, UserSessionEntity entity, boolean offline) { - UserModel user = null; + UserModel user; if (Profile.isFeatureEnabled(Feature.TRANSIENT_USERS) && entity.getNotes().containsKey(SESSION_NOTE_LIGHTWEIGHT_USER)) { LightweightUserAdapter lua = LightweightUserAdapter.fromString(session, realm, entity.getNotes().get(SESSION_NOTE_LIGHTWEIGHT_USER)); final UserSessionAdapter us = wrap(realm, entity, offline, lua); @@ -704,7 +697,7 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi UserSessionAdapter userSessionAdapter = (offlineUserSession instanceof UserSessionAdapter) ? (UserSessionAdapter) offlineUserSession : getOfflineUserSession(offlineUserSession.getRealm(), offlineUserSession.getId()); - AuthenticatedClientSessionAdapter offlineClientSession = importClientSession(userSessionAdapter, clientSession, true, false); + AuthenticatedClientSessionAdapter offlineClientSession = importOfflineClientSession(userSessionAdapter, clientSession); // update timestamp to current time offlineClientSession.setTimestamp(Time.currentTime()); @@ -716,7 +709,7 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi @Override public Stream getOfflineUserSessionsStream(RealmModel realm, UserModel user) { - return getUserSessionsFromPersistenceProviderStream(realm, user, true); + return getUserSessionsFromPersistenceProviderStream(realm, user); } @Override @@ -862,11 +855,10 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi entity.setAuthenticatedClientSessions(new AuthenticatedClientSessionStore()); entity.setRememberMe(userSession.isRememberMe()); entity.setState(userSession.getState()); - if (userSession instanceof OfflineUserSessionModel) { + if (userSession instanceof OfflineUserSessionModel offlineUserSession) { // this is a hack so that UserModel doesn't have to be available when offline token is imported. // see related JIRA - KEYCLOAK-5350 and corresponding test - OfflineUserSessionModel oline = (OfflineUserSessionModel) userSession; - entity.setUser(oline.getUserId()); + entity.setUser(offlineUserSession.getUserId()); // NOTE: Hack // We skip calling entity.setLoginUsername(userSession.getLoginUsername()) @@ -883,28 +875,15 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi } - private AuthenticatedClientSessionAdapter importClientSession(UserSessionAdapter sessionToImportInto, - AuthenticatedClientSessionModel clientSession, - boolean offline, - boolean checkExpiration) { + private AuthenticatedClientSessionAdapter importOfflineClientSession(UserSessionAdapter sessionToImportInto, + AuthenticatedClientSessionModel clientSession) { AuthenticatedClientSessionEntity entity = createAuthenticatedClientSessionInstance(sessionToImportInto.getId(), clientSession, - sessionToImportInto.getRealm().getId(), clientSession.getClient().getId(), offline); + sessionToImportInto.getRealm().getId(), clientSession.getClient().getId(), true); entity.setUserSessionId(sessionToImportInto.getId()); // Update timestamp to same value as userSession. LastSessionRefresh of userSession from DB will have correct value entity.setTimestamp(sessionToImportInto.getLastSessionRefresh()); - if (checkExpiration) { - SessionFunction lifespanChecker = offline - ? SessionTimeouts::getOfflineClientSessionLifespanMs : SessionTimeouts::getClientSessionLifespanMs; - SessionFunction idleTimeoutChecker = offline - ? SessionTimeouts::getOfflineClientSessionMaxIdleMs : SessionTimeouts::getClientSessionMaxIdleMs; - if (idleTimeoutChecker.apply(sessionToImportInto.getRealm(), clientSession.getClient(), entity) == SessionTimeouts.ENTRY_EXPIRED_FLAG - || lifespanChecker.apply(sessionToImportInto.getRealm(), clientSession.getClient(), entity) == SessionTimeouts.ENTRY_EXPIRED_FLAG) { - return null; - } - } - final UUID clientSessionId = entity.getId(); SessionUpdateTask createClientSessionTask = Tasks.addIfAbsentSync(); @@ -913,10 +892,10 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi AuthenticatedClientSessionStore clientSessions = sessionToImportInto.getEntity().getAuthenticatedClientSessions(); clientSessions.put(clientSession.getClient().getId(), clientSessionId); - SessionUpdateTask registerClientSessionTask = new ClientSessionPersistentChangelogBasedTransaction.RegisterClientSessionTask(clientSession.getClient().getId(), clientSessionId, offline); + SessionUpdateTask registerClientSessionTask = new ClientSessionPersistentChangelogBasedTransaction.RegisterClientSessionTask(clientSession.getClient().getId(), clientSessionId, true); sessionTx.addTask(sessionToImportInto.getId(), registerClientSessionTask); - return new AuthenticatedClientSessionAdapter(session, this, entity, clientSession.getClient(), sessionToImportInto, clientSessionTx, offline); + return new AuthenticatedClientSessionAdapter(session, this, entity, clientSession.getClient(), sessionToImportInto, clientSessionTx, true); } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/UserSessionTimestamp.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/UserSessionTimestamp.java deleted file mode 100644 index c8da93fd2b..0000000000 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/UserSessionTimestamp.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.models.sessions.infinispan; - -import java.io.Serializable; - -/** - * @author Stian Thorgersen - */ -public class UserSessionTimestamp implements Serializable { - private String userSessionId; - private int clientSessionTimestamp; - - public UserSessionTimestamp(String userSessionId, int clientSessionTimestamp) { - this.userSessionId = userSessionId; - this.clientSessionTimestamp = clientSessionTimestamp; - } - - public String getUserSessionId() { - return userSessionId; - } - - public int getClientSessionTimestamp() { - return clientSessionTimestamp; - } -} diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/ClientSessionPersistentChangelogBasedTransaction.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/ClientSessionPersistentChangelogBasedTransaction.java index 4de5b16e15..04c394d594 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/ClientSessionPersistentChangelogBasedTransaction.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/ClientSessionPersistentChangelogBasedTransaction.java @@ -90,12 +90,11 @@ public class ClientSessionPersistentChangelogBasedTransaction extends Persistent return wrappedEntity; } else { - AuthenticatedClientSessionEntity entity = myUpdates.getEntityWrapper().getEntity(); // If entity is scheduled for remove, we don't return it. boolean scheduledForRemove = myUpdates.getUpdateTasks().stream().filter((SessionUpdateTask task) -> { - return task.getOperation(entity) == SessionUpdateTask.CacheOperation.REMOVE; + return task.getOperation() == SessionUpdateTask.CacheOperation.REMOVE; }).findFirst().isPresent(); @@ -192,7 +191,7 @@ public class ClientSessionPersistentChangelogBasedTransaction extends Persistent } @Override - public CacheOperation getOperation(UserSessionEntity session) { + public CacheOperation getOperation() { return CacheOperation.REPLACE; } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/ClientSessionUpdateTask.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/ClientSessionUpdateTask.java index 240610c72b..231206b4e9 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/ClientSessionUpdateTask.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/ClientSessionUpdateTask.java @@ -25,7 +25,7 @@ import org.keycloak.models.sessions.infinispan.entities.AuthenticatedClientSessi public abstract class ClientSessionUpdateTask implements PersistentSessionUpdateTask { @Override - public CacheOperation getOperation(AuthenticatedClientSessionEntity session) { + public CacheOperation getOperation() { return CacheOperation.REPLACE; } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/EmbeddedCachesChangesPerformer.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/EmbeddedCachesChangesPerformer.java index 117750ad75..f3487a2d85 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/EmbeddedCachesChangesPerformer.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/EmbeddedCachesChangesPerformer.java @@ -40,8 +40,7 @@ public class EmbeddedCachesChangesPerformer implemen } private void runOperationInCluster(K key, MergedUpdate task, SessionEntityWrapper sessionWrapper) { - V session = sessionWrapper.getEntity(); - SessionUpdateTask.CacheOperation operation = task.getOperation(session); + SessionUpdateTask.CacheOperation operation = task.getOperation(); // Don't need to run update of underlying entity. Local updates were already run //task.runUpdate(session); diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/InfinispanChangelogBasedTransaction.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/InfinispanChangelogBasedTransaction.java index 0e8dbdfabb..5eb70336ea 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/InfinispanChangelogBasedTransaction.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/InfinispanChangelogBasedTransaction.java @@ -149,12 +149,10 @@ public class InfinispanChangelogBasedTransaction ext return wrappedEntity; } else { - V entity = myUpdates.getEntityWrapper().getEntity(); - // If entity is scheduled for remove, we don't return it. boolean scheduledForRemove = myUpdates.getUpdateTasks().stream().filter((SessionUpdateTask task) -> { - return task.getOperation(entity) == SessionUpdateTask.CacheOperation.REMOVE; + return task.getOperation() == SessionUpdateTask.CacheOperation.REMOVE; }).findFirst().isPresent(); @@ -190,8 +188,7 @@ public class InfinispanChangelogBasedTransaction ext private void runOperationInCluster(K key, MergedUpdate task, SessionEntityWrapper sessionWrapper) { - V session = sessionWrapper.getEntity(); - SessionUpdateTask.CacheOperation operation = task.getOperation(session); + SessionUpdateTask.CacheOperation operation = task.getOperation(); // Don't need to run update of underlying entity. Local updates were already run //task.runUpdate(session); diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/JpaChangesPerformer.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/JpaChangesPerformer.java index d00618c209..ad184dba3b 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/JpaChangesPerformer.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/JpaChangesPerformer.java @@ -122,10 +122,10 @@ public class JpaChangesPerformer implements SessionC RealmModel realm = sessionUpdates.getRealm(); UserSessionPersisterProvider userSessionPersister = innerSession.getProvider(UserSessionPersisterProvider.class); - if (merged.getOperation(sessionWrapper.getEntity()) == SessionUpdateTask.CacheOperation.REMOVE) { + if (merged.getOperation() == SessionUpdateTask.CacheOperation.REMOVE) { AuthenticatedClientSessionEntity entity = (AuthenticatedClientSessionEntity) sessionWrapper.getEntity(); userSessionPersister.removeClientSession(entity.getUserSessionId(), entity.getClientId(), entity.isOffline()); - } else if (merged.getOperation(sessionWrapper.getEntity()) == SessionUpdateTask.CacheOperation.ADD || merged.getOperation(sessionWrapper.getEntity()) == SessionUpdateTask.CacheOperation.ADD_IF_ABSENT){ + } else if (merged.getOperation() == SessionUpdateTask.CacheOperation.ADD || merged.getOperation() == SessionUpdateTask.CacheOperation.ADD_IF_ABSENT){ AuthenticatedClientSessionEntity entity = (AuthenticatedClientSessionEntity) sessionWrapper.getEntity(); userSessionPersister.createClientSession(new AuthenticatedClientSessionModel() { @Override @@ -405,7 +405,7 @@ public class JpaChangesPerformer implements SessionC }; sessionUpdates.getUpdateTasks().forEach(vSessionUpdateTask -> { vSessionUpdateTask.runUpdate((V) authenticatedClientSessionEntity); - if (vSessionUpdateTask.getOperation((V) authenticatedClientSessionEntity) == SessionUpdateTask.CacheOperation.REMOVE) { + if (vSessionUpdateTask.getOperation() == SessionUpdateTask.CacheOperation.REMOVE) { userSessionPersister.removeClientSession(entity.getUserSessionId(), entity.getClientId(), entity.isOffline()); } }); @@ -422,9 +422,9 @@ public class JpaChangesPerformer implements SessionC UserSessionPersisterProvider userSessionPersister = innerSession.getProvider(UserSessionPersisterProvider.class); UserSessionEntity entity = (UserSessionEntity) sessionWrapper.getEntity(); - if (merged.getOperation((V) entity) == SessionUpdateTask.CacheOperation.REMOVE) { + if (merged.getOperation() == SessionUpdateTask.CacheOperation.REMOVE) { userSessionPersister.removeUserSession(entry.getKey().toString(), entity.isOffline()); - } else if (merged.getOperation(sessionWrapper.getEntity()) == SessionUpdateTask.CacheOperation.ADD || merged.getOperation(sessionWrapper.getEntity()) == SessionUpdateTask.CacheOperation.ADD_IF_ABSENT){ + } else if (merged.getOperation() == SessionUpdateTask.CacheOperation.ADD || merged.getOperation() == SessionUpdateTask.CacheOperation.ADD_IF_ABSENT){ userSessionPersister.createUserSession(new UserSessionModel() { @Override public String getId() { @@ -729,7 +729,7 @@ public class JpaChangesPerformer implements SessionC }; sessionUpdates.getUpdateTasks().forEach(vSessionUpdateTask -> { vSessionUpdateTask.runUpdate((V) userSessionEntity); - if (vSessionUpdateTask.getOperation((V)userSessionEntity) == SessionUpdateTask.CacheOperation.REMOVE) { + if (vSessionUpdateTask.getOperation() == SessionUpdateTask.CacheOperation.REMOVE) { userSessionPersister.removeUserSession(entry.getKey().toString(), entity.isOffline()); } }); diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/LoginFailuresUpdateTask.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/LoginFailuresUpdateTask.java index 04ed05a318..54994141a8 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/LoginFailuresUpdateTask.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/LoginFailuresUpdateTask.java @@ -25,7 +25,7 @@ import org.keycloak.models.sessions.infinispan.entities.LoginFailureEntity; public abstract class LoginFailuresUpdateTask implements SessionUpdateTask { @Override - public CacheOperation getOperation(LoginFailureEntity session) { + public CacheOperation getOperation() { return CacheOperation.REPLACE; } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/MergedUpdate.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/MergedUpdate.java index 3c44789414..340a6308e7 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/MergedUpdate.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/MergedUpdate.java @@ -52,7 +52,7 @@ public class MergedUpdate implements SessionUpdateTask< } @Override - public CacheOperation getOperation(S session) { + public CacheOperation getOperation() { return operation; } @@ -79,7 +79,7 @@ public class MergedUpdate implements SessionUpdateTask< S session = sessionWrapper.getEntity(); for (SessionUpdateTask child : childUpdates) { if (result == null) { - CacheOperation operation = child.getOperation(session); + CacheOperation operation = child.getOperation(); if (lifespanMs == SessionTimeouts.ENTRY_EXPIRED_FLAG || maxIdleTimeMs == SessionTimeouts.ENTRY_EXPIRED_FLAG) { operation = CacheOperation.REMOVE; @@ -91,9 +91,9 @@ public class MergedUpdate implements SessionUpdateTask< } else { // Merge the operations. REMOVE is special case as other operations are not needed then. - CacheOperation mergedOp = result.getOperation(session).merge(child.getOperation(session), session); + CacheOperation mergedOp = result.getOperation().merge(child.getOperation(), session); if (mergedOp == CacheOperation.REMOVE) { - result = new MergedUpdate<>(child.getOperation(session), child.getCrossDCMessageStatus(sessionWrapper), lifespanMs, maxIdleTimeMs); + result = new MergedUpdate<>(child.getOperation(), child.getCrossDCMessageStatus(sessionWrapper), lifespanMs, maxIdleTimeMs); result.childUpdates.add(child); return result; } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/PersistentSessionsChangelogBasedTransaction.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/PersistentSessionsChangelogBasedTransaction.java index b10bce5121..f6d5a66aa1 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/PersistentSessionsChangelogBasedTransaction.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/PersistentSessionsChangelogBasedTransaction.java @@ -164,11 +164,9 @@ abstract public class PersistentSessionsChangelogBasedTransaction { - - return task.getOperation(entity) == SessionUpdateTask.CacheOperation.REMOVE; - - }).findFirst().isPresent(); + boolean scheduledForRemove = myUpdates.getUpdateTasks().stream() + .map(SessionUpdateTask::getOperation) + .anyMatch(SessionUpdateTask.CacheOperation.REMOVE::equals); return scheduledForRemove ? null : myUpdates.getEntityWrapper(); } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionEntityWrapper.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionEntityWrapper.java index 2d64bd5832..13b92b4f4b 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionEntityWrapper.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionEntityWrapper.java @@ -43,7 +43,7 @@ public class SessionEntityWrapper { private static final Logger log = Logger.getLogger(SessionEntityWrapper.class); - private UUID version; + private final UUID version; private final S entity; private final Map localMetadata; @@ -91,10 +91,6 @@ public class SessionEntityWrapper { return version; } - public void setVersion(UUID version) { - this.version = version; - } - public S getEntity() { return entity; } @@ -116,13 +112,6 @@ public class SessionEntityWrapper { return localMetadata.get(key); } - public void putLocalMetadataNote(String key, String value) { - if (isForTransport()) { - throw new IllegalStateException("This entity is only intended for transport"); - } - localMetadata.put(key, value); - } - public Integer getLocalMetadataNoteInt(String key) { String note = getLocalMetadataNote(key); return note==null ? null : Integer.valueOf(note); diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionUpdateTask.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionUpdateTask.java index 4a71507e5d..b0f5d59121 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionUpdateTask.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionUpdateTask.java @@ -26,7 +26,7 @@ public interface SessionUpdateTask { void runUpdate(S entity); - CacheOperation getOperation(S entity); + CacheOperation getOperation(); CrossDCMessageStatus getCrossDCMessageStatus(SessionEntityWrapper sessionWrapper); diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/Tasks.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/Tasks.java index f248b35610..70dee7016c 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/Tasks.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/Tasks.java @@ -32,7 +32,7 @@ public class Tasks { } @Override - public CacheOperation getOperation(SessionEntity entity) { + public CacheOperation getOperation() { return CacheOperation.ADD_IF_ABSENT; } @@ -48,7 +48,7 @@ public class Tasks { } @Override - public CacheOperation getOperation(SessionEntity entity) { + public CacheOperation getOperation() { return CacheOperation.REMOVE; } @@ -63,13 +63,13 @@ public class Tasks { } }; - private static final SessionUpdateTask OFFLINE_REMOVE_SYNC = new PersistentSessionUpdateTask() { + private static final SessionUpdateTask OFFLINE_REMOVE_SYNC = new PersistentSessionUpdateTask<>() { @Override public void runUpdate(SessionEntity entity) { } @Override - public CacheOperation getOperation(SessionEntity entity) { + public CacheOperation getOperation() { return CacheOperation.REMOVE; } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/UserSessionPersistentChangelogBasedTransaction.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/UserSessionPersistentChangelogBasedTransaction.java index 13af306f89..3534e280cd 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/UserSessionPersistentChangelogBasedTransaction.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/UserSessionPersistentChangelogBasedTransaction.java @@ -81,14 +81,10 @@ public class UserSessionPersistentChangelogBasedTransaction extends PersistentSe return wrappedEntity; } else { - UserSessionEntity entity = myUpdates.getEntityWrapper().getEntity(); - // If entity is scheduled for remove, we don't return it. - boolean scheduledForRemove = myUpdates.getUpdateTasks().stream().filter((SessionUpdateTask task) -> { - - return task.getOperation(entity) == SessionUpdateTask.CacheOperation.REMOVE; - - }).findFirst().isPresent(); + boolean scheduledForRemove = myUpdates.getUpdateTasks().stream() + .map(SessionUpdateTask::getOperation) + .anyMatch(SessionUpdateTask.CacheOperation.REMOVE::equals); return scheduledForRemove ? null : myUpdates.getEntityWrapper(); } @@ -133,15 +129,11 @@ public class UserSessionPersistentChangelogBasedTransaction extends PersistentSe if (myUpdates == null) { return false; } - - V entity = myUpdates.getEntityWrapper().getEntity(); - // If entity is scheduled for remove, we don't return it. - boolean scheduledForRemove = myUpdates.getUpdateTasks() - .stream() - .anyMatch(task -> task.getOperation(entity) == SessionUpdateTask.CacheOperation.REMOVE); - return scheduledForRemove; + return myUpdates.getUpdateTasks() + .stream() + .anyMatch(task -> task.getOperation() == SessionUpdateTask.CacheOperation.REMOVE); } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/UserSessionUpdateTask.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/UserSessionUpdateTask.java index 9cb34e1359..e17ce0cbea 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/UserSessionUpdateTask.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/UserSessionUpdateTask.java @@ -25,7 +25,7 @@ import org.keycloak.models.sessions.infinispan.entities.UserSessionEntity; public abstract class UserSessionUpdateTask implements PersistentSessionUpdateTask { @Override - public CacheOperation getOperation(UserSessionEntity session) { + public CacheOperation getOperation() { return CacheOperation.REPLACE; } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/AbstractAuthSessionClusterListener.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/AbstractAuthSessionClusterListener.java index 18461e0cc4..50e0b0a0fb 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/AbstractAuthSessionClusterListener.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/AbstractAuthSessionClusterListener.java @@ -55,10 +55,10 @@ public abstract class AbstractAuthSessionClusterListener Marek Posolda - */ -@SerializeWith(ClientRemovedSessionEvent.ExternalizerImpl.class) -public class ClientRemovedSessionEvent extends SessionClusterEvent { - - private String clientUuid; - - public static ClientRemovedSessionEvent create(KeycloakSession session, String eventKey, String realmId, boolean resendingEvent, String clientUuid) { - ClientRemovedSessionEvent event = ClientRemovedSessionEvent.createEvent(ClientRemovedSessionEvent.class, eventKey, session, realmId, resendingEvent); - event.clientUuid = clientUuid; - return event; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - - ClientRemovedSessionEvent that = (ClientRemovedSessionEvent) o; - return Objects.equals(clientUuid, that.clientUuid); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), clientUuid); - } - - @Override - public String toString() { - return String.format("ClientRemovedSessionEvent [ realmId=%s , clientUuid=%s ]", getRealmId(), clientUuid); - } - - public String getClientUuid() { - return clientUuid; - } - - public static class ExternalizerImpl implements Externalizer { - - private static final int VERSION_1 = 1; - - @Override - public void writeObject(ObjectOutput output, ClientRemovedSessionEvent obj) throws IOException { - output.writeByte(VERSION_1); - obj.marshallTo(output); - MarshallUtil.marshallString(obj.clientUuid, output); - } - - @Override - public ClientRemovedSessionEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { - switch (input.readByte()) { - case VERSION_1: - return readObjectVersion1(input); - default: - throw new IOException("Unknown version"); - } - } - - public ClientRemovedSessionEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { - ClientRemovedSessionEvent res = new ClientRemovedSessionEvent(); - res.unmarshallFrom(input); - res.clientUuid = MarshallUtil.unmarshallString(input); - - return res; - } - } -} diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/BaseCacheInitializer.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/BaseCacheInitializer.java index 2c3a40f4ae..f128da6694 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/BaseCacheInitializer.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/BaseCacheInitializer.java @@ -38,14 +38,12 @@ public abstract class BaseCacheInitializer extends CacheInitializer { protected final KeycloakSessionFactory sessionFactory; protected final Cache workCache; protected final SessionLoader sessionLoader; - protected final int sessionsPerSegment; protected final String stateKey; - public BaseCacheInitializer(KeycloakSessionFactory sessionFactory, Cache workCache, SessionLoader sessionLoader, String stateKeySuffix, int sessionsPerSegment) { + public BaseCacheInitializer(KeycloakSessionFactory sessionFactory, Cache workCache, SessionLoader sessionLoader, String stateKeySuffix) { this.sessionFactory = sessionFactory; this.workCache = workCache; this.sessionLoader = sessionLoader; - this.sessionsPerSegment = sessionsPerSegment; this.stateKey = STATE_KEY_PREFIX + stateKeySuffix; } @@ -59,8 +57,7 @@ public abstract class BaseCacheInitializer extends CacheInitializer { @Override protected boolean isCoordinator() { - Transport transport = workCache.getCacheManager().getTransport(); - return transport == null || transport.isCoordinator(); + return workCache.getCacheManager().isCoordinator(); } @Override diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/CacheInitializer.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/CacheInitializer.java index 725005371f..c41fe4a156 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/CacheInitializer.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/CacheInitializer.java @@ -28,9 +28,6 @@ public abstract class CacheInitializer { private static final Logger log = Logger.getLogger(CacheInitializer.class); - public void initCache() { - } - public void loadSessions() { Instant loadingMustContinueBy = Instant.now().plusSeconds(getStalledTimeoutInSeconds()); boolean loadingStalledInPreviousStep = false; diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/InfinispanCacheInitializer.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/InfinispanCacheInitializer.java index 12340564c5..49bf009c85 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/InfinispanCacheInitializer.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/InfinispanCacheInitializer.java @@ -46,14 +46,13 @@ public class InfinispanCacheInitializer extends BaseCacheInitializer { // Effectively no timeout private final int stalledTimeoutInSeconds; - public InfinispanCacheInitializer(KeycloakSessionFactory sessionFactory, Cache workCache, SessionLoader sessionLoader, String stateKeySuffix, int sessionsPerSegment, int maxErrors, int stalledTimeoutInSeconds) { - super(sessionFactory, workCache, sessionLoader, stateKeySuffix, sessionsPerSegment); + public InfinispanCacheInitializer(KeycloakSessionFactory sessionFactory, Cache workCache, SessionLoader sessionLoader, String stateKeySuffix, int maxErrors, int stalledTimeoutInSeconds) { + super(sessionFactory, workCache, sessionLoader, stateKeySuffix); this.maxErrors = maxErrors; this.stalledTimeoutInSeconds = stalledTimeoutInSeconds; } - @Override public void initCache() { // due to lazy initialization, this might be called from multiple threads simultaneously, therefore, synchronize synchronized (workCache) { @@ -72,19 +71,10 @@ public class InfinispanCacheInitializer extends BaseCacheInitializer { InitializerState state = getStateFromCache(); SessionLoader.LoaderContext[] ctx = new SessionLoader.LoaderContext[1]; if (state == null) { - // Rather use separate transactions for update and counting KeycloakModelUtils.runJobInTransaction(sessionFactory, new KeycloakSessionTask() { @Override public void run(KeycloakSession session) { - sessionLoader.init(session); - } - - }); - - KeycloakModelUtils.runJobInTransaction(sessionFactory, new KeycloakSessionTask() { - @Override - public void run(KeycloakSession session) { - ctx[0] = sessionLoader.computeLoaderContext(session); + ctx[0] = sessionLoader.computeLoaderContext(); } }); @@ -94,7 +84,7 @@ public class InfinispanCacheInitializer extends BaseCacheInitializer { KeycloakModelUtils.runJobInTransaction(sessionFactory, new KeycloakSessionTask() { @Override public void run(KeycloakSession session) { - ctx[0] = sessionLoader.computeLoaderContext(session); + ctx[0] = sessionLoader.computeLoaderContext(); } }); @@ -115,8 +105,6 @@ public class InfinispanCacheInitializer extends BaseCacheInitializer { int errors = 0; int segmentToLoad = 0; - SessionLoader.WorkerResult previousResult = null; - SessionLoader.WorkerResult nextResult = null; int distributedWorkersCount = 1; while (segmentToLoad < state.getSegmentsCount()) { @@ -132,7 +120,7 @@ public class InfinispanCacheInitializer extends BaseCacheInitializer { final Queue results = new ConcurrentLinkedQueue<>(); for (Integer segment : segments) { - SessionLoader.WorkerContext workerCtx = sessionLoader.computeWorkerContext(loaderCtx, segment, segment - segmentToLoad, previousResult); + SessionLoader.WorkerContext workerCtx = sessionLoader.computeWorkerContext(segment); SessionInitializerWorker worker = new SessionInitializerWorker(); worker.setWorkerEnvironment(loaderCtx, workerCtx, sessionLoader); @@ -144,15 +132,14 @@ public class InfinispanCacheInitializer extends BaseCacheInitializer { // Check the results for (SessionLoader.WorkerResult result : results) { - if (result.isSuccess()) { - state.markSegmentFinished(result.getSegment()); - if (result.getSegment() == segmentToLoad + distributedWorkersCount - 1) { + if (result.success()) { + state.markSegmentFinished(result.segment()); + if (result.segment() == segmentToLoad + distributedWorkersCount - 1) { // last result for next iteration when complete - nextResult = result; } } else { if (log.isTraceEnabled()) { - log.tracef("Segment %d failed to compute", result.getSegment()); + log.tracef("Segment %d failed to compute", result.segment()); } anyFailure = true; } @@ -165,8 +152,6 @@ public class InfinispanCacheInitializer extends BaseCacheInitializer { if (!anyFailure) { // everything is OK, prepare the new row segmentToLoad += distributedWorkersCount; - previousResult = nextResult; - nextResult = null; if (log.isTraceEnabled()) { log.debugf("New initializer state is: %s", state); } @@ -177,7 +162,7 @@ public class InfinispanCacheInitializer extends BaseCacheInitializer { saveStateToCache(state); // Loader callback after the task is finished - this.sessionLoader.afterAllSessionsLoaded(this); + this.sessionLoader.afterAllSessionsLoaded(); } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/OfflinePersistentLoaderContext.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/OfflinePersistentLoaderContext.java index a18b15a818..7a28128545 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/OfflinePersistentLoaderContext.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/OfflinePersistentLoaderContext.java @@ -41,15 +41,6 @@ public class OfflinePersistentLoaderContext extends SessionLoader.LoaderContext } - public int getSessionsTotal() { - return sessionsTotal; - } - - public int getSessionsPerSegment() { - return sessionsPerSegment; - } - - @Override public String toString() { return new StringBuilder("OfflinePersistentLoaderContext [ ") diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/OfflinePersistentWorkerContext.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/OfflinePersistentWorkerContext.java deleted file mode 100644 index 83ea795b0e..0000000000 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/OfflinePersistentWorkerContext.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2017 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.models.sessions.infinispan.initializer; - -/** - * @author Marek Posolda - */ -public class OfflinePersistentWorkerContext extends SessionLoader.WorkerContext { - - private final String lastSessionId; - - public OfflinePersistentWorkerContext(int segment, int workerId, String lastSessionId) { - super(segment, workerId); - this.lastSessionId = lastSessionId; - } - - public String getLastSessionId() { - return lastSessionId; - } -} diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/OfflinePersistentWorkerResult.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/OfflinePersistentWorkerResult.java deleted file mode 100644 index 8e9ed33de9..0000000000 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/OfflinePersistentWorkerResult.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2017 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.models.sessions.infinispan.initializer; - -/** - * @author Marek Posolda - */ -public class OfflinePersistentWorkerResult extends SessionLoader.WorkerResult { - - private final String lastSessionId; - - - public OfflinePersistentWorkerResult(boolean success, int segment, int workerId, String lastSessionId) { - super(success, segment, workerId); - this.lastSessionId = lastSessionId; - } - - public String getLastSessionId() { - return lastSessionId; - } -} diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/SessionLoader.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/SessionLoader.java index af513fcfdb..be35fec980 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/SessionLoader.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/initializer/SessionLoader.java @@ -28,15 +28,6 @@ public interface SessionLoader extends Serializable { - /** - * Will be triggered just once on cluster coordinator node to perform some generic initialization tasks (Eg. update DB before starting load). - * - * NOTE: This shouldn't be used for the initialization of loader instance itself! - * - * @param session - */ - void init(KeycloakSession session); - /** * @@ -45,22 +36,18 @@ public interface SessionLoader void runOnRemoteCache(TopologyInfo topology, RemoteCache> remoteCache, long maxIdleMs, K key, MergedUpdate task, SessionEntityWrapper sessionWrapper) { - final V session = sessionWrapper.getEntity(); - SessionUpdateTask.CacheOperation operation = task.getOperation(session); + SessionUpdateTask.CacheOperation operation = task.getOperation(); switch (operation) { case REMOVE: diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/RemoteCacheSessionListener.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/RemoteCacheSessionListener.java index f81ccaa446..82b02dde8c 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/RemoteCacheSessionListener.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/RemoteCacheSessionListener.java @@ -97,7 +97,7 @@ public class RemoteCacheSessionListener { // Doesn't work due https://issues.jboss.org/browse/ISPN-9323. Needs to explicitly retrieve and create it //cache.get(key); - createRemoteEntityInCache(key, event.getVersion()); + createRemoteEntityInCache(key); }); } @@ -119,7 +119,7 @@ public class RemoteCacheSessionListener { } - protected void createRemoteEntityInCache(K key, long eventVersion) { + protected void createRemoteEntityInCache(K key) { VersionedValue> remoteSessionVersioned = remoteCache.getWithMetadata(key); // Maybe can happen under some circumstances that remoteCache doesn't yet contain the value sent in the event (maybe just theoretically...) @@ -249,18 +249,6 @@ public class RemoteCacheSessionListener { return result; } - - - @ClientListener(includeCurrentState = true) - public static class FetchInitialStateCacheListener extends RemoteCacheSessionListener { - } - - - @ClientListener(includeCurrentState = false) - public static class DontFetchInitialStateCacheListener extends RemoteCacheSessionListener { - } - - public static RemoteCacheSessionListener createListener(KeycloakSession session, Cache> cache, RemoteCache> remoteCache, SessionFunction lifespanMsLoader, SessionFunction maxIdleTimeMsLoader) { /*boolean isCoordinator = InfinispanUtil.isCoordinator(cache); diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/RemoteCacheSessionsLoader.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/RemoteCacheSessionsLoader.java index a1945b88be..571a89cc41 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/RemoteCacheSessionsLoader.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/RemoteCacheSessionsLoader.java @@ -32,7 +32,6 @@ import org.keycloak.common.util.Retry; import org.keycloak.connections.infinispan.DefaultInfinispanConnectionProviderFactory; import org.keycloak.connections.infinispan.InfinispanConnectionProvider; import org.keycloak.models.KeycloakSession; -import org.keycloak.models.sessions.infinispan.initializer.BaseCacheInitializer; import org.keycloak.models.sessions.infinispan.initializer.SessionLoader; /** @@ -52,27 +51,17 @@ public class RemoteCacheSessionsLoader implements SessionLoader cache = getCache(session); @@ -142,13 +131,13 @@ public class RemoteCacheSessionsLoader implements SessionLoader cache, Map entries, int maxIdle, int lifespan) { @@ -169,7 +158,7 @@ public class RemoteCacheSessionsLoader implements SessionLoaderMarek Posolda - */ -@SerializeWith(AuthenticatedClientSessionPredicate.ExternalizerImpl.class) -public class AuthenticatedClientSessionPredicate implements Predicate>> { - - private final String realm; - - private Integer expired; - - private AuthenticatedClientSessionPredicate(String realm) { - this.realm = realm; - } - - /** - * Creates a client session predicate. - * @param realm - * @return - */ - public static AuthenticatedClientSessionPredicate create(String realm) { - return new AuthenticatedClientSessionPredicate(realm); - } - - - public AuthenticatedClientSessionPredicate expired(Integer expired) { - this.expired = expired; - return this; - } - - - @Override - public boolean test(Map.Entry> entry) { - AuthenticatedClientSessionEntity entity = entry.getValue().getEntity(); - - if (!realm.equals(entity.getRealmId())) { - return false; - } - - if (expired != null && entity.getTimestamp() > expired) { - return false; - } - - return true; - } - - - public static class ExternalizerImpl implements Externalizer { - - private static final int VERSION_1 = 1; - - @Override - public void writeObject(ObjectOutput output, AuthenticatedClientSessionPredicate obj) throws IOException { - output.writeByte(VERSION_1); - - MarshallUtil.marshallString(obj.realm, output); - KeycloakMarshallUtil.marshall(obj.expired, output); - } - - @Override - public AuthenticatedClientSessionPredicate readObject(ObjectInput input) throws IOException, ClassNotFoundException { - switch (input.readByte()) { - case VERSION_1: - return readObjectVersion1(input); - default: - throw new IOException("Unknown version"); - } - } - - public AuthenticatedClientSessionPredicate readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { - AuthenticatedClientSessionPredicate res = new AuthenticatedClientSessionPredicate(MarshallUtil.unmarshallString(input)); - res.expired(KeycloakMarshallUtil.unmarshallInteger(input)); - return res; - } - } -} diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/Comparators.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/Comparators.java deleted file mode 100644 index 965f13861e..0000000000 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/Comparators.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.models.sessions.infinispan.stream; - -import org.keycloak.models.sessions.infinispan.UserSessionTimestamp; -import org.keycloak.models.sessions.infinispan.entities.UserSessionEntity; - -import java.io.Serializable; -import java.util.Comparator; - -/** - * @author Stian Thorgersen - */ -public class Comparators { - - public static Comparator userSessionTimestamp() { - return new UserSessionTimestampComparator(); - } - - private static class UserSessionTimestampComparator implements Comparator, Serializable { - @Override - public int compare(UserSessionTimestamp u1, UserSessionTimestamp u2) { - return u1.getClientSessionTimestamp() - u2.getClientSessionTimestamp(); - } - } - - - public static Comparator userSessionLastSessionRefresh() { - return new UserSessionLastSessionRefreshComparator(); - } - - private static class UserSessionLastSessionRefreshComparator implements Comparator, Serializable { - - @Override - public int compare(UserSessionEntity u1, UserSessionEntity u2) { - return u1.getLastSessionRefresh() - u2.getLastSessionRefresh(); - } - } - -} diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/Mappers.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/Mappers.java index 69fcddb569..4343f0a60d 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/Mappers.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/Mappers.java @@ -18,17 +18,14 @@ package org.keycloak.models.sessions.infinispan.stream; import org.keycloak.models.sessions.infinispan.changes.SessionEntityWrapper; -import org.keycloak.models.sessions.infinispan.entities.AuthenticatedClientSessionEntity; import org.keycloak.models.sessions.infinispan.entities.LoginFailureEntity; import org.keycloak.models.sessions.infinispan.entities.LoginFailureKey; -import org.keycloak.models.sessions.infinispan.entities.SessionEntity; import org.keycloak.models.sessions.infinispan.entities.UserSessionEntity; import java.io.Serializable; import java.util.Collection; import java.util.Map; import java.util.Set; -import java.util.UUID; import java.util.function.Function; import java.util.stream.Stream; @@ -37,72 +34,15 @@ import java.util.stream.Stream; */ public class Mappers { - public static Function, Map.Entry> unwrap() { - return new SessionUnwrap(); - } - - public static Function>, String> sessionId() { - return new SessionIdMapper(); - } - - public static Function, SessionEntity> sessionEntity() { - return new SessionEntityMapper(); - } - public static Function>, UserSessionEntity> userSessionEntity() { return new UserSessionEntityMapper(); } - public static Function>, AuthenticatedClientSessionEntity> clientSessionEntity() { - return new AuthenticatedClientSessionEntityMapper(); - } - public static Function>, LoginFailureKey> loginFailureId() { return new LoginFailureIdMapper(); } - private static class SessionUnwrap implements Function, Map.Entry>, Serializable { - - @Override - public Map.Entry apply(Map.Entry wrapperEntry) { - return new Map.Entry() { - - @Override - public String getKey() { - return wrapperEntry.getKey(); - } - - @Override - public SessionEntity getValue() { - return wrapperEntry.getValue().getEntity(); - } - - @Override - public SessionEntity setValue(SessionEntity value) { - throw new IllegalStateException("Unsupported operation"); - } - - }; - } - - } - - - private static class SessionIdMapper implements Function>, String>, Serializable { - @Override - public String apply(Map.Entry> entry) { - return entry.getKey(); - } - } - - private static class SessionEntityMapper implements Function, SessionEntity>, Serializable { - @Override - public SessionEntity apply(Map.Entry entry) { - return entry.getValue().getEntity(); - } - } - private static class UserSessionEntityMapper implements Function>, UserSessionEntity>, Serializable { @Override @@ -112,15 +52,6 @@ public class Mappers { } - private static class AuthenticatedClientSessionEntityMapper implements Function>, AuthenticatedClientSessionEntity>, Serializable { - - @Override - public AuthenticatedClientSessionEntity apply(Map.Entry> entry) { - return entry.getValue().getEntity(); - } - - } - private static class LoginFailureIdMapper implements Function>, LoginFailureKey>, Serializable { @Override public LoginFailureKey apply(Map.Entry> entry) { diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/util/KeycloakMarshallUtil.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/util/KeycloakMarshallUtil.java index ed94d3c94c..dbb8689adb 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/util/KeycloakMarshallUtil.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/util/KeycloakMarshallUtil.java @@ -22,7 +22,6 @@ import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedList; import java.util.Map; import java.util.UUID; @@ -40,8 +39,6 @@ import org.jboss.logging.Logger; */ public class KeycloakMarshallUtil { - private static final Logger log = Logger.getLogger(KeycloakMarshallUtil.class); - public static final Externalizer STRING_EXT = new StringExternalizer(); public static final Externalizer UUID_EXT = new Externalizer() { @@ -174,14 +171,6 @@ public class KeycloakMarshallUtil { } - public static class HashSetBuilder implements MarshallUtil.CollectionBuilder> { - - @Override - public HashSet build(int size) { - return new HashSet<>(size); - } - } - private static class StringExternalizer implements Externalizer { diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/util/SessionTimeouts.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/util/SessionTimeouts.java index bf747ba841..ba40b01e08 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/util/SessionTimeouts.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/util/SessionTimeouts.java @@ -37,11 +37,6 @@ public class SessionTimeouts { */ public static final long ENTRY_EXPIRED_FLAG = -2l; - /** - * This is used just if timeouts are not set on the realm (usually happens just during tests when realm is created manually with the model API) - */ - public static final int MINIMAL_EXPIRATION_SEC = 300; - /** * Get the maximum lifespan, which this userSession can remain in the infinispan cache. * Returned value will be used as "lifespan" when calling put/replace operation in the infinispan cache for this entity diff --git a/model/infinispan/src/test/java/org/keycloak/cluster/infinispan/RemoteCacheSessionsLoaderTest.java b/model/infinispan/src/test/java/org/keycloak/cluster/infinispan/RemoteCacheSessionsLoaderTest.java index 7d58ed898e..b753144910 100644 --- a/model/infinispan/src/test/java/org/keycloak/cluster/infinispan/RemoteCacheSessionsLoaderTest.java +++ b/model/infinispan/src/test/java/org/keycloak/cluster/infinispan/RemoteCacheSessionsLoaderTest.java @@ -103,8 +103,7 @@ public class RemoteCacheSessionsLoaderTest { // Just to be able to test serializability RemoteCacheSessionsLoader loader = new CustomLoader(cacheName, 64, cache2, remoteCache); - loader.init(null); - RemoteCacheSessionsLoaderContext ctx = loader.computeLoaderContext(null); + RemoteCacheSessionsLoaderContext ctx = loader.computeLoaderContext(); Assert.assertEquals(ctx.getSessionsPerSegment(), 64); int totalCount = 0; @@ -113,7 +112,7 @@ public class RemoteCacheSessionsLoaderTest { Set visitedKeys = new HashSet<>(); for (int currentSegment=0 ; currentSegment