From 6a9245546e92a05c00410a8d7ac5897f3261a116 Mon Sep 17 00:00:00 2001 From: Michal Hajas Date: Fri, 16 Aug 2024 12:57:07 +0200 Subject: [PATCH] Set clientId if it is not set in the entity Closes #32195 Signed-off-by: Michal Hajas --- .../sessions/infinispan/PersistentUserSessionProvider.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 7ba7d9ef98..032c9f2a75 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 @@ -1022,9 +1022,13 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi // ignoring old and unknown realm found in the session return; } - sessionEntityWrapper.getEntity().getAuthenticatedClientSessions().forEach((k, uuid) -> { + sessionEntityWrapper.getEntity().getAuthenticatedClientSessions().forEach((clientId, uuid) -> { SessionEntityWrapper clientSession = clientSessionCache.get(uuid); if (clientSession != null) { + // This is necessary because client sessions created by a KC version < 22 do not have clientId set within the entity. + if (clientSession.getEntity().getClientId() == null) { + clientSession.getEntity().setClientId(clientId); + } clientSession.getEntity().setUserSessionId(sessionEntityWrapper.getEntity().getId()); MergedUpdate merged = MergedUpdate.computeUpdate(Collections.singletonList(Tasks.addIfAbsentSync()), clientSession, 1, 1); clientSessionPerformer.registerChange(Map.entry(uuid, new SessionUpdatesList<>(realm, clientSession)), merged);