From 9098b6be44958e7bd2e8a809e1c09decb3639312 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Thu, 4 Jul 2024 17:27:18 +0100 Subject: [PATCH] Remove SecurityManager --- .../config/inject/ConfigExtension.java | 4 +- .../inject/ConfigMappingInjectionBean.java | 4 +- .../config/inject/ConfigProducer.java | 4 +- .../inject/ConfigPropertiesInjectionBean.java | 4 +- .../config/inject/SecuritySupport.java | 22 +------ .../AbstractLocationConfigSourceLoader.java | 4 +- .../config/ConfigMappingGenerator.java | 5 +- .../java/io/smallrye/config/Converters.java | 2 +- .../io/smallrye/config/EnvConfigSource.java | 9 +-- .../smallrye/config/ImplicitConverters.java | 7 ++- .../io/smallrye/config/SecuritySupport.java | 63 ++----------------- .../config/SmallRyeConfigBuilder.java | 2 +- .../config/SmallRyeConfigFactory.java | 7 +-- .../SmallRyeConfigProviderResolver.java | 51 +++++---------- .../smallrye/config/SysPropConfigSource.java | 9 +-- .../DotEnvConfigSourceProviderTest.java | 13 ++-- 16 files changed, 47 insertions(+), 163 deletions(-) diff --git a/cdi/src/main/java/io/smallrye/config/inject/ConfigExtension.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigExtension.java index 4cf745669..7aed84171 100644 --- a/cdi/src/main/java/io/smallrye/config/inject/ConfigExtension.java +++ b/cdi/src/main/java/io/smallrye/config/inject/ConfigExtension.java @@ -20,7 +20,6 @@ import static io.smallrye.config.ConfigMappings.ConfigClassWithPrefix.configClassWithPrefix; import static io.smallrye.config.inject.ConfigProducer.isClassHandledByConfigProducer; import static io.smallrye.config.inject.InjectionMessages.formatInjectionPoint; -import static io.smallrye.config.inject.SecuritySupport.getContextClassLoader; import static java.util.stream.Collectors.toSet; import java.lang.reflect.ParameterizedType; @@ -183,7 +182,8 @@ protected void registerCustomBeans(@Observes AfterBeanDiscovery abd, BeanManager } protected void validate(@Observes AfterDeploymentValidation adv) { - SmallRyeConfig config = ConfigProvider.getConfig(getContextClassLoader()).unwrap(SmallRyeConfig.class); + SmallRyeConfig config = ConfigProvider.getConfig(Thread.currentThread().getContextClassLoader()) + .unwrap(SmallRyeConfig.class); Set configNames = StreamSupport.stream(config.getPropertyNames().spliterator(), false).collect(toSet()); for (InjectionPoint injectionPoint : getConfigPropertyInjectionPoints()) { Type type = injectionPoint.getType(); diff --git a/cdi/src/main/java/io/smallrye/config/inject/ConfigMappingInjectionBean.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigMappingInjectionBean.java index ed88adb33..e72280030 100644 --- a/cdi/src/main/java/io/smallrye/config/inject/ConfigMappingInjectionBean.java +++ b/cdi/src/main/java/io/smallrye/config/inject/ConfigMappingInjectionBean.java @@ -1,7 +1,5 @@ package io.smallrye.config.inject; -import static io.smallrye.config.inject.SecuritySupport.getContextClassLoader; - import java.lang.annotation.Annotation; import java.lang.reflect.Type; import java.util.Collections; @@ -52,7 +50,7 @@ public T create(final CreationalContext creationalContext) { } } - SmallRyeConfig config = ConfigProvider.getConfig(getContextClassLoader()).unwrap(SmallRyeConfig.class); + SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class); return config.getConfigMapping(getBeanClass(), prefix); } diff --git a/cdi/src/main/java/io/smallrye/config/inject/ConfigProducer.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigProducer.java index 104c3770c..94ad0a7b9 100644 --- a/cdi/src/main/java/io/smallrye/config/inject/ConfigProducer.java +++ b/cdi/src/main/java/io/smallrye/config/inject/ConfigProducer.java @@ -15,8 +15,6 @@ */ package io.smallrye.config.inject; -import static io.smallrye.config.inject.SecuritySupport.getContextClassLoader; - import java.lang.reflect.Type; import java.util.*; import java.util.function.Supplier; @@ -42,7 +40,7 @@ public class ConfigProducer { @Produces protected SmallRyeConfig getConfig() { - return ConfigProvider.getConfig(getContextClassLoader()).unwrap(SmallRyeConfig.class); + return ConfigProvider.getConfig().unwrap(SmallRyeConfig.class); } @Dependent diff --git a/cdi/src/main/java/io/smallrye/config/inject/ConfigPropertiesInjectionBean.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigPropertiesInjectionBean.java index d0653ee06..f51c59ffd 100644 --- a/cdi/src/main/java/io/smallrye/config/inject/ConfigPropertiesInjectionBean.java +++ b/cdi/src/main/java/io/smallrye/config/inject/ConfigPropertiesInjectionBean.java @@ -1,7 +1,5 @@ package io.smallrye.config.inject; -import static io.smallrye.config.inject.SecuritySupport.getContextClassLoader; - import java.lang.annotation.Annotation; import java.lang.reflect.Type; import java.util.Collections; @@ -47,7 +45,7 @@ public T create(final CreationalContext creationalContext) { } } - SmallRyeConfig config = ConfigProvider.getConfig(getContextClassLoader()).unwrap(SmallRyeConfig.class); + SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class); return config.getConfigMapping(getBeanClass(), prefix); } diff --git a/cdi/src/main/java/io/smallrye/config/inject/SecuritySupport.java b/cdi/src/main/java/io/smallrye/config/inject/SecuritySupport.java index 229133270..c59ae8656 100644 --- a/cdi/src/main/java/io/smallrye/config/inject/SecuritySupport.java +++ b/cdi/src/main/java/io/smallrye/config/inject/SecuritySupport.java @@ -13,35 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.smallrye.config.inject; -import java.security.AccessController; -import java.security.PrivilegedAction; - -import io.smallrye.config._private.ConfigLogging; - /** * @author Jeff Mesnil (c) 2018 Red Hat inc. */ +@Deprecated(forRemoval = true) class SecuritySupport { private SecuritySupport() { } static ClassLoader getContextClassLoader() { - if (System.getSecurityManager() == null) { - return Thread.currentThread().getContextClassLoader(); - } else { - return AccessController.doPrivileged((PrivilegedAction) () -> { - ClassLoader tccl = null; - try { - tccl = Thread.currentThread().getContextClassLoader(); - } catch (SecurityException ex) { - ConfigLogging.log.failedToRetrieveClassloader(ex); - } - return tccl; - }); - } + return Thread.currentThread().getContextClassLoader(); } - } diff --git a/implementation/src/main/java/io/smallrye/config/AbstractLocationConfigSourceLoader.java b/implementation/src/main/java/io/smallrye/config/AbstractLocationConfigSourceLoader.java index 68c7f09ba..77ffc3a7c 100644 --- a/implementation/src/main/java/io/smallrye/config/AbstractLocationConfigSourceLoader.java +++ b/implementation/src/main/java/io/smallrye/config/AbstractLocationConfigSourceLoader.java @@ -88,7 +88,7 @@ protected List loadConfigSources(final String location, final int } protected List loadConfigSources(final String[] locations, final int ordinal) { - return loadConfigSources(locations, ordinal, SecuritySupport.getContextClassLoader()); + return loadConfigSources(locations, ordinal, Thread.currentThread().getContextClassLoader()); } protected List loadConfigSources(final String[] locations, final int ordinal, final ClassLoader classLoader) { @@ -136,7 +136,7 @@ protected List tryFileSystem(final URI uri, final int ordinal) { protected List tryClassPath(final URI uri, final int ordinal, final ClassLoader classLoader) { final List configSources = new ArrayList<>(); - final ClassLoader useClassloader = classLoader != null ? classLoader : SecuritySupport.getContextClassLoader(); + final ClassLoader useClassloader = classLoader != null ? classLoader : Thread.currentThread().getContextClassLoader(); try { consumeAsPaths(useClassloader, uri.getPath(), new ConfigSourcePathConsumer(ordinal, configSources)); } catch (IOException e) { diff --git a/implementation/src/main/java/io/smallrye/config/ConfigMappingGenerator.java b/implementation/src/main/java/io/smallrye/config/ConfigMappingGenerator.java index 1edac5b65..043b92717 100644 --- a/implementation/src/main/java/io/smallrye/config/ConfigMappingGenerator.java +++ b/implementation/src/main/java/io/smallrye/config/ConfigMappingGenerator.java @@ -56,8 +56,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -89,8 +87,7 @@ public class ConfigMappingGenerator { private static final Pattern ARRAY_FORMAT_REGEX = Pattern.compile("([<;])L(.*)\\[];"); static { - usefulDebugInfo = Boolean.parseBoolean(AccessController.doPrivileged( - (PrivilegedAction) () -> System.getProperty("io.smallrye.config.mapper.useful-debug-info"))); + usefulDebugInfo = Boolean.parseBoolean(System.getProperty("io.smallrye.config.mapper.useful-debug-info")); } private static final String I_CLASS = getInternalName(Class.class); diff --git a/implementation/src/main/java/io/smallrye/config/Converters.java b/implementation/src/main/java/io/smallrye/config/Converters.java index 969e05042..23190fd8e 100644 --- a/implementation/src/main/java/io/smallrye/config/Converters.java +++ b/implementation/src/main/java/io/smallrye/config/Converters.java @@ -116,7 +116,7 @@ private Converters() { static final Converter> CLASS_CONVERTER = BuiltInConverter.of(6, newTrimmingConverter(newEmptyValueConverter(value -> { try { - return Class.forName(value, true, SecuritySupport.getContextClassLoader()); + return Class.forName(value, true, Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException e) { throw ConfigMessages.msg.classConverterNotFound(e, value); } diff --git a/implementation/src/main/java/io/smallrye/config/EnvConfigSource.java b/implementation/src/main/java/io/smallrye/config/EnvConfigSource.java index b701a5035..db8336c36 100644 --- a/implementation/src/main/java/io/smallrye/config/EnvConfigSource.java +++ b/implementation/src/main/java/io/smallrye/config/EnvConfigSource.java @@ -21,10 +21,8 @@ import static io.smallrye.config.common.utils.StringUtil.replaceNonAlphanumericByUnderscores; import static io.smallrye.config.common.utils.StringUtil.toLowerCaseAndDotted; import static java.lang.Character.toLowerCase; -import static java.security.AccessController.doPrivileged; import java.io.Serializable; -import java.security.PrivilegedAction; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -109,12 +107,7 @@ boolean hasPropertyName(final String propertyName) { * instantiated in the heap. */ private static Map getEnvProperties() { - return doPrivileged(new PrivilegedAction>() { - @Override - public Map run() { - return new HashMap<>(System.getenv()); - } - }); + return new HashMap<>(System.getenv()); } private static int getEnvOrdinal(final Map properties, final int ordinal) { diff --git a/implementation/src/main/java/io/smallrye/config/ImplicitConverters.java b/implementation/src/main/java/io/smallrye/config/ImplicitConverters.java index a3fc35339..b9c177506 100644 --- a/implementation/src/main/java/io/smallrye/config/ImplicitConverters.java +++ b/implementation/src/main/java/io/smallrye/config/ImplicitConverters.java @@ -17,6 +17,7 @@ import java.io.ObjectStreamException; import java.io.Serializable; +import java.lang.reflect.AccessibleObject; import java.lang.reflect.Constructor; import java.lang.reflect.Executable; import java.lang.reflect.InvocationTargetException; @@ -74,9 +75,9 @@ static Converter getConverter(Class clazz) { private static Converter getConverterFromConstructor(Class clazz, Class paramType) { try { - final Constructor declaredConstructor = SecuritySupport.getDeclaredConstructor(clazz, paramType); + final Constructor declaredConstructor = clazz.getDeclaredConstructor(paramType); if (!isAccessible(declaredConstructor)) { - SecuritySupport.setAccessible(declaredConstructor, true); + ((AccessibleObject) declaredConstructor).setAccessible(true); } return new ConstructorConverter<>(declaredConstructor); } catch (NoSuchMethodException e) { @@ -96,7 +97,7 @@ private static Converter getConverterFromStaticMethod(Class return null; } if (!isAccessible(method)) { - SecuritySupport.setAccessible(method, true); + ((AccessibleObject) method).setAccessible(true); } return new StaticMethodConverter<>(clazz, method); } catch (NoSuchMethodException e) { diff --git a/implementation/src/main/java/io/smallrye/config/SecuritySupport.java b/implementation/src/main/java/io/smallrye/config/SecuritySupport.java index 92974214d..77be62cc8 100644 --- a/implementation/src/main/java/io/smallrye/config/SecuritySupport.java +++ b/implementation/src/main/java/io/smallrye/config/SecuritySupport.java @@ -13,84 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.smallrye.config; import java.lang.reflect.AccessibleObject; import java.lang.reflect.Constructor; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.Arrays; - -import io.smallrye.config._private.ConfigLogging; /** * @author Jeff Mesnil (c) 2018 Red Hat inc. */ +@Deprecated(forRemoval = true) class SecuritySupport { private SecuritySupport() { } static ClassLoader getContextClassLoader() { - if (System.getSecurityManager() == null) { - return Thread.currentThread().getContextClassLoader(); - } else { - return AccessController.doPrivileged((PrivilegedAction) () -> { - ClassLoader tccl = null; - try { - tccl = Thread.currentThread().getContextClassLoader(); - } catch (SecurityException ex) { - ConfigLogging.log.failedToRetrieveClassloader(ex); - } - return tccl; - }); - } + return Thread.currentThread().getContextClassLoader(); } static void setAccessible(AccessibleObject object, boolean flag) { - if (System.getSecurityManager() == null) { - object.setAccessible(flag); - } else { - AccessController.doPrivileged((PrivilegedAction) () -> { - - try { - object.setAccessible(flag); - } catch (SecurityException ex) { - ConfigLogging.log.failedToSetAccessible(ex, object.toString()); - } - return null; - }); - } + object.setAccessible(flag); } static Constructor getDeclaredConstructor(Class clazz, Class... paramTypes) throws NoSuchMethodException { - if (System.getSecurityManager() == null) { - return clazz.getDeclaredConstructor(paramTypes); - } else { - try { - return AccessController.doPrivileged((PrivilegedExceptionAction>) () -> { - Constructor constructor = null; - try { - constructor = clazz.getDeclaredConstructor(paramTypes); - - } catch (SecurityException ex) { - ConfigLogging.log.failedToRetrieveDeclaredConstructor(ex, clazz.toString(), - Arrays.toString(paramTypes)); - } - return constructor; - }); - } catch (PrivilegedActionException e) { - Exception e2 = e.getException(); - if (e2 instanceof NoSuchMethodException) { - throw (NoSuchMethodException) e2; - } else { - throw new RuntimeException(e2); - } - } - } + return clazz.getDeclaredConstructor(paramTypes); } - } diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java index d75056dbf..f3b8c33e3 100644 --- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java +++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java @@ -75,7 +75,7 @@ public class SmallRyeConfigBuilder implements ConfigBuilder { private ConfigValidator validator = ConfigValidator.EMPTY; private final Map defaultValues = new HashMap<>(); private final MappingBuilder mappingsBuilder = new MappingBuilder(); - private ClassLoader classLoader = SecuritySupport.getContextClassLoader(); + private ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); private boolean addDiscoveredCustomizers = false; private boolean addDefaultSources = false; private boolean addSystemSources = false; diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigFactory.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigFactory.java index c5f6f57a0..1352d368c 100644 --- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigFactory.java +++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigFactory.java @@ -14,14 +14,9 @@ */ public abstract class SmallRyeConfigFactory { /** - * Construct a new instance. Callers will be checked for the {@code getClassLoader} - * {@link RuntimePermission}. + * Construct a new instance. */ protected SmallRyeConfigFactory() { - final SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("getClassLoader")); - } } /** diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigProviderResolver.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigProviderResolver.java index a45e1eca5..049b2940e 100644 --- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigProviderResolver.java +++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigProviderResolver.java @@ -15,10 +15,6 @@ */ package io.smallrye.config; -import static io.smallrye.config.SecuritySupport.getContextClassLoader; - -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Iterator; import java.util.Map; import java.util.ServiceLoader; @@ -36,17 +32,7 @@ public class SmallRyeConfigProviderResolver extends ConfigProviderResolver { private final Map configsForClassLoader = new ConcurrentHashMap<>(); - static final ClassLoader SYSTEM_CL; - - static { - final SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - SYSTEM_CL = AccessController - .doPrivileged((PrivilegedAction) SmallRyeConfigProviderResolver::calculateSystemClassLoader); - } else { - SYSTEM_CL = calculateSystemClassLoader(); - } - } + private static final ClassLoader SYSTEM_CL = calculateSystemClassLoader(); public SmallRyeConfigProviderResolver() { } @@ -63,19 +49,19 @@ private static ClassLoader calculateSystemClassLoader() { @Override public Config getConfig() { - return getConfig(getContextClassLoader()); + return getConfig(Thread.currentThread().getContextClassLoader()); } @Override public Config getConfig(ClassLoader classLoader) { - final ClassLoader realClassLoader = getRealClassLoader(classLoader); - final Map configsForClassLoader = this.configsForClassLoader; + ClassLoader realClassLoader = getRealClassLoader(classLoader); + Map configsForClassLoader = this.configsForClassLoader; Config config = configsForClassLoader.get(realClassLoader); if (config == null) { synchronized (configsForClassLoader) { config = configsForClassLoader.get(realClassLoader); if (config == null) { - config = getFactoryFor(realClassLoader, false).getConfigFor(this, classLoader); + config = getFactoryFor(realClassLoader).getConfigFor(this, classLoader); // don't cache null, as that would leak class loaders if (config == null) { throw ConfigMessages.msg.noConfigForClassloader(); @@ -87,18 +73,9 @@ public Config getConfig(ClassLoader classLoader) { return config; } - SmallRyeConfigFactory getFactoryFor(final ClassLoader classLoader, final boolean privileged) { - final SecurityManager sm = System.getSecurityManager(); - if (sm != null && !privileged) { - // run privileged so that the only things on the access control stack are us and the provider - return AccessController.doPrivileged(new PrivilegedAction() { - public SmallRyeConfigFactory run() { - return getFactoryFor(classLoader, true); - } - }); - } - final ServiceLoader serviceLoader = ServiceLoader.load(SmallRyeConfigFactory.class, classLoader); - final Iterator iterator = serviceLoader.iterator(); + SmallRyeConfigFactory getFactoryFor(final ClassLoader classLoader) { + ServiceLoader serviceLoader = ServiceLoader.load(SmallRyeConfigFactory.class, classLoader); + Iterator iterator = serviceLoader.iterator(); return iterator.hasNext() ? iterator.next() : SmallRyeConfigFactory.Default.INSTANCE; } @@ -112,8 +89,8 @@ public void registerConfig(Config config, ClassLoader classLoader) { if (config == null) { throw ConfigMessages.msg.configIsNull(); } - final ClassLoader realClassLoader = getRealClassLoader(classLoader); - final Map configsForClassLoader = this.configsForClassLoader; + ClassLoader realClassLoader = getRealClassLoader(classLoader); + Map configsForClassLoader = this.configsForClassLoader; synchronized (configsForClassLoader) { final Config existing = configsForClassLoader.putIfAbsent(realClassLoader, config); if (existing != null) { @@ -126,15 +103,15 @@ public void registerConfig(Config config, ClassLoader classLoader) { public void releaseConfig(Config config) { // todo: see https://github.com/eclipse/microprofile-config/issues/136#issuecomment-535962313 // todo: see https://github.com/eclipse/microprofile-config/issues/471 - final Map configsForClassLoader = this.configsForClassLoader; + Map configsForClassLoader = this.configsForClassLoader; synchronized (configsForClassLoader) { configsForClassLoader.values().removeIf(v -> v == config); } } public void releaseConfig(ClassLoader classLoader) { - final ClassLoader realClassLoader = getRealClassLoader(classLoader); - final Map configsForClassLoader = this.configsForClassLoader; + ClassLoader realClassLoader = getRealClassLoader(classLoader); + Map configsForClassLoader = this.configsForClassLoader; synchronized (configsForClassLoader) { configsForClassLoader.remove(realClassLoader); } @@ -142,7 +119,7 @@ public void releaseConfig(ClassLoader classLoader) { static ClassLoader getRealClassLoader(ClassLoader classLoader) { if (classLoader == null) { - classLoader = getContextClassLoader(); + classLoader = Thread.currentThread().getContextClassLoader(); } if (classLoader == null) { classLoader = SYSTEM_CL; diff --git a/implementation/src/main/java/io/smallrye/config/SysPropConfigSource.java b/implementation/src/main/java/io/smallrye/config/SysPropConfigSource.java index f40b37f56..10e8a2f26 100644 --- a/implementation/src/main/java/io/smallrye/config/SysPropConfigSource.java +++ b/implementation/src/main/java/io/smallrye/config/SysPropConfigSource.java @@ -16,12 +16,9 @@ package io.smallrye.config; import static io.smallrye.config.common.utils.ConfigSourceUtil.propertiesToMap; -import static java.security.AccessController.doPrivileged; import static java.util.Collections.unmodifiableMap; -import java.security.PrivilegedAction; import java.util.Map; -import java.util.Properties; import java.util.Set; import io.smallrye.config.common.AbstractConfigSource; @@ -49,11 +46,11 @@ public Set getPropertyNames() { } @Override - public String getValue(String s) { - return doPrivileged((PrivilegedAction) () -> System.getProperty(s)); + public String getValue(String propertyName) { + return System.getProperty(propertyName); } private static Map getSystemProperties() { - return unmodifiableMap(propertiesToMap(doPrivileged((PrivilegedAction) System::getProperties))); + return unmodifiableMap(propertiesToMap(System.getProperties())); } } diff --git a/implementation/src/test/java/io/smallrye/config/DotEnvConfigSourceProviderTest.java b/implementation/src/test/java/io/smallrye/config/DotEnvConfigSourceProviderTest.java index 96bfdfe0e..9451bb207 100644 --- a/implementation/src/test/java/io/smallrye/config/DotEnvConfigSourceProviderTest.java +++ b/implementation/src/test/java/io/smallrye/config/DotEnvConfigSourceProviderTest.java @@ -1,7 +1,6 @@ package io.smallrye.config; import static io.smallrye.config.DotEnvConfigSourceProvider.dotEnvSources; -import static io.smallrye.config.SecuritySupport.getContextClassLoader; import static java.util.Collections.emptyMap; import static java.util.stream.Collectors.toSet; import static java.util.stream.StreamSupport.stream; @@ -29,7 +28,8 @@ void dotEnvSource(@TempDir Path tempDir) throws Exception { SmallRyeConfig config = new SmallRyeConfigBuilder() .addDefaultInterceptors() - .withSources(dotEnvSources(tempDir.resolve(".env").toFile().toURI().toString(), getContextClassLoader())) + .withSources(dotEnvSources(tempDir.resolve(".env").toFile().toURI().toString(), + Thread.currentThread().getContextClassLoader())) .build(); assertEquals("1234", config.getRawValue("my.prop")); @@ -69,7 +69,8 @@ void dotEnvSourceProfiles(@TempDir Path tempDir) throws Exception { SmallRyeConfig config = new SmallRyeConfigBuilder() .addDefaultInterceptors() .withProfile("common,dev") - .withSources(dotEnvSources(tempDir.resolve(".env").toFile().toURI().toString(), getContextClassLoader())) + .withSources(dotEnvSources(tempDir.resolve(".env").toFile().toURI().toString(), + Thread.currentThread().getContextClassLoader())) .build(); assertEquals("main", config.getRawValue("my.prop.main")); @@ -91,7 +92,8 @@ void dotEnvSourceConvertNames(@TempDir Path tempDir) throws Exception { SmallRyeConfig config = new SmallRyeConfigBuilder() .addDefaultInterceptors() - .withSources(dotEnvSources(tempDir.resolve(".env").toFile().toURI().toString(), getContextClassLoader())) + .withSources(dotEnvSources(tempDir.resolve(".env").toFile().toURI().toString(), + Thread.currentThread().getContextClassLoader())) .build(); assertEquals("1234", config.getRawValue("my.prop")); @@ -124,7 +126,8 @@ void dottedDashedEnvNames(@TempDir Path tempDir) throws Exception { SmallRyeConfig config = new SmallRyeConfigBuilder() .withMapping(DashedEnvNames.class) .withSources(new EnvConfigSource(emptyMap(), 300)) - .withSources(dotEnvSources(tempDir.resolve(".env").toFile().toURI().toString(), getContextClassLoader())) + .withSources(dotEnvSources(tempDir.resolve(".env").toFile().toURI().toString(), + Thread.currentThread().getContextClassLoader())) .withProfile("dev") .build();