From 9b7cf9d5841dea0f8a4883578af06e3bfe638a29 Mon Sep 17 00:00:00 2001 From: Stefan Guilhen Date: Tue, 1 Oct 2024 16:53:04 -0300 Subject: [PATCH] Ensure componentsByParentAndType in CachedRealm is returned as a concurrent multi-valued map Closes #30235 Signed-off-by: Stefan Guilhen --- .../common/util/ConcurrentMultivaluedHashMap.java | 10 ++++++++++ .../models/cache/infinispan/entities/CachedRealm.java | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/keycloak/common/util/ConcurrentMultivaluedHashMap.java b/common/src/main/java/org/keycloak/common/util/ConcurrentMultivaluedHashMap.java index 125e51ade7..703ef9146f 100755 --- a/common/src/main/java/org/keycloak/common/util/ConcurrentMultivaluedHashMap.java +++ b/common/src/main/java/org/keycloak/common/util/ConcurrentMultivaluedHashMap.java @@ -18,6 +18,7 @@ package org.keycloak.common.util; import java.util.List; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; @@ -28,6 +29,15 @@ import java.util.concurrent.CopyOnWriteArrayList; @SuppressWarnings("serial") public class ConcurrentMultivaluedHashMap extends ConcurrentHashMap> implements MultivaluedMap { + public ConcurrentMultivaluedHashMap() { + } + + public ConcurrentMultivaluedHashMap(Map> map) { + if (map == null) { + throw new IllegalArgumentException("Map can not be null"); + } + putAll(map); + } @Override public List createListInstance() { 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 bbc0627de0..e1dd4a1b1f 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 @@ -696,7 +696,7 @@ public class CachedRealm extends AbstractExtendableRevisioned { } public MultivaluedMap getComponentsByParentAndType() { - return new MultivaluedHashMap<>(componentsByParentAndType); + return new ConcurrentMultivaluedHashMap<>(componentsByParentAndType); } public Map getComponents() {