Fix concurrent modification exception with dispatcher caching

keycloak-1  | 2024-06-21 08:32:21,335 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-9) Uncaught server error: java.util.ConcurrentModificationException
keycloak-1  | 	at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1221)
keycloak-1  | 	at sh.libre.scim.core.ScimDispatcher.createForSession(ScimDispatcher.java:31)
keycloak-1  | 	at sh.libre.scim.event.ScimEventListenerProvider.<init>(ScimEventListenerProvider.java:49)
keycloak-1  | 	at sh.libre.scim.event.ScimEventListenerProviderFactory.create(ScimEventListenerProviderFactory.java:13)
keycloak-1  | 	at sh.libre.scim.event.ScimEventListenerProviderFactory.create(ScimEventListenerProviderFactory.java:9)
keycloak-1  | 	at org.keycloak.services.DefaultKeycloakSession.getProvider(DefaultKeycloakSession.java:195)
This commit is contained in:
Brendan Le Ny 2024-06-21 10:45:48 +02:00 committed by Alex Morel
parent 0b24401def
commit c793c138a3

View file

@ -10,6 +10,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
/**
@ -19,7 +20,7 @@ public class ScimDispatcher {
private static final Logger logger = Logger.getLogger(ScimDispatcher.class);
private static final Map<KeycloakSession, ScimDispatcher> sessionToScimDispatcher = new LinkedHashMap<>();
private static final Map<KeycloakSession, ScimDispatcher> sessionToScimDispatcher = new ConcurrentHashMap<>();
private final KeycloakSession session;
private boolean clientsInitialized = false;
private final List<UserScimService> userScimServices = new ArrayList<>();