Set clientId if it is not set in the entity

Closes #32195

Signed-off-by: Michal Hajas <mhajas@redhat.com>
This commit is contained in:
Michal Hajas 2024-08-16 12:57:07 +02:00 committed by Alexander Schwartz
parent 3ddc3fd4de
commit 6a9245546e

View file

@ -1022,9 +1022,13 @@ public class PersistentUserSessionProvider implements UserSessionProvider, Sessi
// ignoring old and unknown realm found in the session // ignoring old and unknown realm found in the session
return; return;
} }
sessionEntityWrapper.getEntity().getAuthenticatedClientSessions().forEach((k, uuid) -> { sessionEntityWrapper.getEntity().getAuthenticatedClientSessions().forEach((clientId, uuid) -> {
SessionEntityWrapper<AuthenticatedClientSessionEntity> clientSession = clientSessionCache.get(uuid); SessionEntityWrapper<AuthenticatedClientSessionEntity> clientSession = clientSessionCache.get(uuid);
if (clientSession != null) { 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()); clientSession.getEntity().setUserSessionId(sessionEntityWrapper.getEntity().getId());
MergedUpdate<AuthenticatedClientSessionEntity> merged = MergedUpdate.computeUpdate(Collections.singletonList(Tasks.addIfAbsentSync()), clientSession, 1, 1); MergedUpdate<AuthenticatedClientSessionEntity> merged = MergedUpdate.computeUpdate(Collections.singletonList(Tasks.addIfAbsentSync()), clientSession, 1, 1);
clientSessionPerformer.registerChange(Map.entry(uuid, new SessionUpdatesList<>(realm, clientSession)), merged); clientSessionPerformer.registerChange(Map.entry(uuid, new SessionUpdatesList<>(realm, clientSession)), merged);