diff --git a/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java b/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java index 7693394cdb..e46c94ebc6 100644 --- a/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java +++ b/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java @@ -230,10 +230,20 @@ public class DefaultKeycloakSession implements KeycloakSession { return groups(); } + private final ThreadLocal recursionPreventionUserStorageManager = new ThreadLocal<>(); + @Override @Deprecated public UserProvider userStorageManager() { - return users(); + if(recursionPreventionUserStorageManager.get() != null) { + throw new IllegalStateException("userStorageManager() is being called recursively. Please adjust your code according to the Keycloak 19 migration guide."); + } + try { + recursionPreventionUserStorageManager.set(Boolean.TRUE); + return users(); + } finally { + recursionPreventionUserStorageManager.remove(); + } } @Override