Remove usages of EnvironmentDependentProviderFactory.isSupported
Closes #28751 Signed-off-by: Pedro Ruivo <pruivo@redhat.com>
This commit is contained in:
parent
12b263c029
commit
63cb137b37
2 changed files with 35 additions and 24 deletions
|
@ -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<Class<? extends Provider>, Map<String, ProviderFactory>> getFactoriesCopy() {
|
||||
Map<Class<? extends Provider>, Map<String, ProviderFactory>> copy = new HashMap<>();
|
||||
for (Map.Entry<Class<? extends Provider>, Map<String, ProviderFactory>> entry : factoriesMap.entrySet()) {
|
||||
Map<String, ProviderFactory> valCopy = new HashMap<>();
|
||||
valCopy.putAll(entry.getValue());
|
||||
Map<String, ProviderFactory> 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<String, ProviderFactory> factories = new HashMap<String, ProviderFactory>();
|
||||
Map<String, ProviderFactory> 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<? extends Provider> 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<ProviderFactory> getProviderFactoriesStream(Class<? extends Provider> clazz) {
|
||||
if (factoriesMap == null) return Stream.empty();
|
||||
if (factoriesMap == null) {
|
||||
return Stream.empty();
|
||||
}
|
||||
Map<String, ProviderFactory> providerFactoryMap = factoriesMap.get(clazz);
|
||||
if (providerFactoryMap == null) return Stream.empty();
|
||||
if (providerFactoryMap == null) {
|
||||
return Stream.empty();
|
||||
}
|
||||
return providerFactoryMap.values().stream();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ProviderFactory, Spi> factoriesBefore = loadEnabledEnvironmentFactories();
|
||||
|
@ -127,10 +130,11 @@ public class FeatureDeployerUtil {
|
|||
|
||||
Map<ProviderFactory, Spi> providerFactories = new HashMap<>();
|
||||
for (Spi spi : loader.loadSpis()) {
|
||||
Config.Scope scope = Config.scope(spi.getName(), Config.getProvider(spi.getName()));
|
||||
List<ProviderFactory> 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue