From 63cb137b37b6654469cdd921f8b517269bf5dd7c Mon Sep 17 00:00:00 2001 From: Pedro Ruivo Date: Mon, 15 Apr 2024 19:13:56 +0100 Subject: [PATCH] Remove usages of EnvironmentDependentProviderFactory.isSupported Closes #28751 Signed-off-by: Pedro Ruivo --- .../DefaultKeycloakSessionFactory.java | 51 +++++++++++-------- .../testsuite/util/FeatureDeployerUtil.java | 8 ++- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/services/src/main/java/org/keycloak/services/DefaultKeycloakSessionFactory.java b/services/src/main/java/org/keycloak/services/DefaultKeycloakSessionFactory.java index 989b4231be..d0882e3ea2 100755 --- a/services/src/main/java/org/keycloak/services/DefaultKeycloakSessionFactory.java +++ b/services/src/main/java/org/keycloak/services/DefaultKeycloakSessionFactory.java @@ -16,6 +16,20 @@ */ package org.keycloak.services; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.Function; +import java.util.stream.Stream; + import org.jboss.logging.Logger; import org.keycloak.Config; import org.keycloak.common.util.MultivaluedHashMap; @@ -38,20 +52,6 @@ import org.keycloak.provider.Spi; import org.keycloak.services.resources.admin.permissions.AdminPermissions; import org.keycloak.theme.DefaultThemeManagerFactory; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.function.Function; -import java.util.stream.Stream; - public abstract class DefaultKeycloakSessionFactory implements KeycloakSessionFactory, ProviderManagerDeployer { private static final Logger logger = Logger.getLogger(DefaultKeycloakSessionFactory.class); @@ -139,8 +139,7 @@ public abstract class DefaultKeycloakSessionFactory implements KeycloakSessionFa protected Map, Map> getFactoriesCopy() { Map, Map> copy = new HashMap<>(); for (Map.Entry, Map> entry : factoriesMap.entrySet()) { - Map valCopy = new HashMap<>(); - valCopy.putAll(entry.getValue()); + Map valCopy = new HashMap<>(entry.getValue()); copy.put(entry.getKey(), valCopy); } return copy; @@ -162,7 +161,9 @@ public abstract class DefaultKeycloakSessionFactory implements KeycloakSessionFa for (ProviderFactory f : entry.getValue().values()) { deployed.add(f); ProviderFactory old = current.remove(f.getId()); - if (old != null) undeployed.add(old); + if (old != null) { + undeployed.add(old); + } } current.putAll(entry.getValue()); } @@ -279,7 +280,7 @@ public abstract class DefaultKeycloakSessionFactory implements KeycloakSessionFa for (Spi spi : spiList) { - Map factories = new HashMap(); + Map factories = new HashMap<>(); factoryMap.put(spi.getProviderClass(), factories); String provider = Config.getProvider(spi.getName()); @@ -327,7 +328,7 @@ public abstract class DefaultKeycloakSessionFactory implements KeycloakSessionFa return false; } if (factory instanceof EnvironmentDependentProviderFactory) { - return ((EnvironmentDependentProviderFactory) factory).isSupported(); + return ((EnvironmentDependentProviderFactory) factory).isSupported(scope); } return true; } @@ -340,7 +341,9 @@ public abstract class DefaultKeycloakSessionFactory implements KeycloakSessionFa @Override public Spi getSpi(Class providerClass) { for (Spi spi : spis) { - if (spi.getProviderClass().equals(providerClass)) return spi; + if (spi.getProviderClass().equals(providerClass)) { + return spi; + } } return null; } @@ -378,9 +381,13 @@ public abstract class DefaultKeycloakSessionFactory implements KeycloakSessionFa @Override public Stream getProviderFactoriesStream(Class clazz) { - if (factoriesMap == null) return Stream.empty(); + if (factoriesMap == null) { + return Stream.empty(); + } Map providerFactoryMap = factoriesMap.get(clazz); - if (providerFactoryMap == null) return Stream.empty(); + if (providerFactoryMap == null) { + return Stream.empty(); + } return providerFactoryMap.values().stream(); } diff --git a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/util/FeatureDeployerUtil.java b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/util/FeatureDeployerUtil.java index 4f9135d6cc..f3f21d5099 100644 --- a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/util/FeatureDeployerUtil.java +++ b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/util/FeatureDeployerUtil.java @@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import org.jboss.logging.Logger; +import org.keycloak.Config; import org.keycloak.common.Profile; import org.keycloak.provider.DefaultProviderLoader; import org.keycloak.provider.EnvironmentDependentProviderFactory; @@ -50,7 +51,9 @@ public class FeatureDeployerUtil { private static final Logger logger = Logger.getLogger(FeatureDeployerUtil.class); public static void initBeforeChangeFeature(Profile.Feature feature) { - if (deployersCache.containsKey(feature)) return; + if (deployersCache.containsKey(feature)) { + return; + } // Compute which provider factories are enabled before feature is enabled (disabled) Map factoriesBefore = loadEnabledEnvironmentFactories(); @@ -127,10 +130,11 @@ public class FeatureDeployerUtil { Map providerFactories = new HashMap<>(); for (Spi spi : loader.loadSpis()) { + Config.Scope scope = Config.scope(spi.getName(), Config.getProvider(spi.getName())); List currentFactories = loader.load(spi); for (ProviderFactory factory : currentFactories) { if (factory instanceof EnvironmentDependentProviderFactory) { - if (((EnvironmentDependentProviderFactory) factory).isSupported()) { + if (((EnvironmentDependentProviderFactory) factory).isSupported(scope)) { providerFactories.put(factory, spi); } }