diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7846cc0..58ee1ce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,14 +66,14 @@ jobs: additional-profiles: name: Test with ${{ matrix.profile }} - JDK ${{ matrix.java }} - WildFly ${{ matrix.wildfly-version }} - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest timeout-minutes: 30 strategy: fail-fast: false matrix: - os: [ ubuntu-latest, windows-latest ] java: [ '11', '17' ] profile: + - "'-Dsecurity.manager'" - "'-Dprovision.preview'" wildfly-version: ['27.0.1.Final'] @@ -93,13 +93,13 @@ jobs: distribution: 'temurin' cache: 'maven' # Since we need to pass the test.java.home we need different runs for Linux and Windows - - name: Test with Java ${{ matrix.java }} - ${{ matrix.os }} ${{ matrix.profile }} + - name: Test with Java ${{ matrix.java }} - ${{ matrix.profile }} run: | mvn clean install -U -B -fae ${{ matrix.profile }} -Pci '-Dversion.org.wildfly=${{ matrix.wildfly-version }}' - uses: actions/upload-artifact@v3 if: failure() with: - name: surefire-reports-${{ matrix.os }}-${{ matrix.java }} + name: surefire-reports-${{ matrix.profile }}-${{ matrix.java }} path: '**/surefire-reports/*.txt' format-check: diff --git a/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/RestClientBuilderImpl.java b/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/RestClientBuilderImpl.java index 41f7117..67a1199 100644 --- a/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/RestClientBuilderImpl.java +++ b/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/RestClientBuilderImpl.java @@ -268,7 +268,7 @@ public T build(Class aClass, ClientHttpEngine httpEngine) builderDelegate.register(new ExceptionMapping(localProviderInstances), 1); - ClassLoader classLoader = aClass.getClassLoader(); + ClassLoader classLoader = getClassLoader(aClass); T actualClient; ResteasyClient client; @@ -427,7 +427,13 @@ private boolean useURLConnection() { } private Optional selectHttpProxy() { - return ProxySelector.getDefault().select(baseURI).stream() + final ProxySelector selector; + if (System.getSecurityManager() == null) { + selector = ProxySelector.getDefault(); + } else { + selector = AccessController.doPrivileged((PrivilegedAction) ProxySelector::getDefault); + } + return selector.select(baseURI).stream() .filter(proxy -> proxy.type() == java.net.Proxy.Type.HTTP) .map(java.net.Proxy::address) .map(InetSocketAddress.class::cast) @@ -844,6 +850,13 @@ private static Method[] resolveMethods(final Class type) { return type.getMethods(); } + private static ClassLoader getClassLoader(final Class type) { + if (System.getSecurityManager() == null) { + return type.getClassLoader(); + } + return AccessController.doPrivileged((PrivilegedAction) type::getClassLoader); + } + private final MpClientBuilderImpl builderDelegate; private final ConfigurationWrapper configurationWrapper; diff --git a/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/RestClientDelegateBean.java b/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/RestClientDelegateBean.java index b5b4839..41a0e8c 100644 --- a/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/RestClientDelegateBean.java +++ b/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/RestClientDelegateBean.java @@ -30,9 +30,11 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.security.AccessController; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; +import java.security.PrivilegedAction; import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.Collections; @@ -133,7 +135,14 @@ public Set getInjectionPoints() { @Override public Object create(CreationalContext creationalContext) { - RestClientBuilder builder = RestClientBuilder.newBuilder(); + RestClientBuilder builder; + // This can be removed once the below issue is resolved. However, for now we can handle this safely here. + // See https://github.com/eclipse/microprofile-rest-client/issues/353 + if (System.getSecurityManager() == null) { + builder = RestClientBuilder.newBuilder(); + } else { + builder = AccessController.doPrivileged((PrivilegedAction) RestClientBuilder::newBuilder); + } configureUri(builder); diff --git a/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/RestClientListeners.java b/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/RestClientListeners.java index b74f598..36e9454 100644 --- a/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/RestClientListeners.java +++ b/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/RestClientListeners.java @@ -19,12 +19,14 @@ package org.jboss.resteasy.microprofile.client; -import java.util.ArrayList; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.Collection; import java.util.Collections; import java.util.Map; import java.util.ServiceLoader; import java.util.WeakHashMap; +import java.util.stream.Collectors; import org.eclipse.microprofile.rest.client.spi.RestClientListener; @@ -41,14 +43,31 @@ private RestClientListeners() { .synchronizedMap(new WeakHashMap<>()); public static Collection get() { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - Collection c; - c = map.get(loader); - if (c == null) { - c = new ArrayList<>(); - ServiceLoader.load(RestClientListener.class, loader).forEach(c::add); - map.put(loader, Collections.unmodifiableCollection(c)); + ClassLoader loader = getClassLoader(); + if (loader == null) { + return Collections.emptyList(); } - return c; + final PrivilegedAction> action = () -> ServiceLoader + .load(RestClientListener.class, loader) + .stream() + .map(ServiceLoader.Provider::get) + .collect(Collectors.toUnmodifiableList()); + return map.computeIfAbsent(loader, classLoader -> { + if (System.getSecurityManager() == null) { + return action.run(); + } + return AccessController.doPrivileged(action); + }); + } + + private static ClassLoader getClassLoader() { + if (System.getSecurityManager() == null) { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + return cl == null ? RestClientListeners.class.getClassLoader() : cl; + } + return AccessController.doPrivileged((PrivilegedAction) () -> { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + return cl == null ? RestClientListeners.class.getClassLoader() : cl; + }); } } diff --git a/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/header/ClientHeaderProviders.java b/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/header/ClientHeaderProviders.java index 1c06650..ad845fd 100644 --- a/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/header/ClientHeaderProviders.java +++ b/rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/header/ClientHeaderProviders.java @@ -20,6 +20,8 @@ package org.jboss.resteasy.microprofile.client.header; import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.Map; import java.util.Optional; import java.util.ServiceLoader; @@ -139,15 +141,20 @@ private static ClientHeadersFactory construct(final Class fillerFactories = ServiceLoader.load(HeaderFillerFactory.class); - int highestPrio = Integer.MIN_VALUE; - HeaderFillerFactory result = null; - for (HeaderFillerFactory factory : fillerFactories) { - if (factory.getPriority() > highestPrio) { - highestPrio = factory.getPriority(); - result = factory; + final PrivilegedAction action = () -> { + ServiceLoader fillerFactories = ServiceLoader.load(HeaderFillerFactory.class); + int highestPrio = Integer.MIN_VALUE; + HeaderFillerFactory result = null; + for (HeaderFillerFactory factory : fillerFactories) { + if (factory.getPriority() > highestPrio) { + highestPrio = factory.getPriority(); + result = factory; + } } - } + return result; + }; + final HeaderFillerFactory result = System.getSecurityManager() == null ? action.run() + : AccessController.doPrivileged(action); if (result == null) { throw new IllegalStateException("Unable to find a HeaderFillerFactory implementation"); } else { diff --git a/resteasy-microprofile-test-bom/pom.xml b/resteasy-microprofile-test-bom/pom.xml index 74dc749..8275393 100644 --- a/resteasy-microprofile-test-bom/pom.xml +++ b/resteasy-microprofile-test-bom/pom.xml @@ -230,6 +230,19 @@ + + org.jboss.resteasy + arquillian-utils + ${version.org.jboss.resteasy} + test + + + * + * + + + + org.jboss.resteasy resteasy-undertow diff --git a/testsuite/integration-tests/pom.xml b/testsuite/integration-tests/pom.xml index 83438b7..6a895ed 100644 --- a/testsuite/integration-tests/pom.xml +++ b/testsuite/integration-tests/pom.xml @@ -47,6 +47,8 @@ org.jboss.resteasy.microprofile galleon-feature-pack ${project.version} + + @@ -139,6 +141,11 @@ resteasy-json-p-provider test + + org.jboss.resteasy + arquillian-utils + test + org.jboss.resteasy.microprofile @@ -276,6 +283,17 @@ + + security.manager + + + security.manager + + + + -secmgr + + provision.preview.server diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/client/exception/ClientWebApplicationExceptionMicroProfileProxyTest.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/client/exception/ClientWebApplicationExceptionMicroProfileProxyTest.java index b6ce119..61a1e79 100644 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/client/exception/ClientWebApplicationExceptionMicroProfileProxyTest.java +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/client/exception/ClientWebApplicationExceptionMicroProfileProxyTest.java @@ -20,6 +20,7 @@ package org.jboss.resteasy.microprofile.test.client.exception; import java.net.URL; +import java.util.PropertyPermission; import jakarta.ws.rs.RedirectionException; import jakarta.ws.rs.WebApplicationException; @@ -35,6 +36,7 @@ import org.jboss.resteasy.microprofile.test.client.exception.resource.ClientWebApplicationExceptionMicroProfileProxyResource; import org.jboss.resteasy.microprofile.test.client.exception.resource.ClientWebApplicationExceptionProxyResourceInterface; import org.jboss.resteasy.microprofile.test.util.TestEnvironment; +import org.jboss.resteasy.utils.PermissionUtil; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.junit.Assert; @@ -78,7 +80,10 @@ public static Archive deploy() throws Exception { " xsi:schemaLocation=\"https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_3_0.xsd\"\n" + " version=\"3.0\" bean-discovery-mode=\"all\">\n" + - ""), "beans.xml"); + ""), "beans.xml") + .addAsManifestResource(PermissionUtil.createPermissionsXmlAsset( + new PropertyPermission("resteasy.original.webapplicationexception.behavior", "write")), + "permissions.xml"); } @Before diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceDefaultOrdinalFilterTest.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceDefaultOrdinalFilterTest.java index 6a8242b..f306390 100644 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceDefaultOrdinalFilterTest.java +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceDefaultOrdinalFilterTest.java @@ -23,7 +23,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Map; -import java.util.PropertyPermission; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; @@ -34,12 +33,13 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.resteasy.microprofile.config.FilterConfigSource; import org.jboss.resteasy.microprofile.config.ServletContextConfigSource; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigFilter; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigResource; import org.jboss.resteasy.microprofile.test.config.resource.TestConfigApplication; -import org.jboss.resteasy.microprofile.test.util.PermissionUtil; +import org.jboss.resteasy.microprofile.test.util.MicroProfileConfigSystemPropertySetupTask; import org.jboss.resteasy.microprofile.test.util.TestEnvironment; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.asset.EmptyAsset; @@ -56,6 +56,7 @@ */ @RunWith(Arquillian.class) @RunAsClient +@ServerSetup(MicroProfileConfigSystemPropertySetupTask.class) public class ConfigSourceDefaultOrdinalFilterTest { static Client client; @@ -68,9 +69,7 @@ public static Archive deploy() { return TestEnvironment.createWar(ConfigSourceDefaultOrdinalFilterTest.class) .addClasses(TestConfigApplication.class, MicroProfileConfigFilter.class, MicroProfileConfigResource.class) .setWebXML(ConfigSourceDefaultOrdinalFilterTest.class.getPackage(), "web_default_ordinal_filter.xml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsManifestResource(PermissionUtil.createPermissionsXmlAsset( - new PropertyPermission("system", "write")), "permissions.xml"); + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @BeforeClass diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceDefaultOrdinalServletContextListenerTest.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceDefaultOrdinalServletContextListenerTest.java index 14e757e..88ca72c 100644 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceDefaultOrdinalServletContextListenerTest.java +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceDefaultOrdinalServletContextListenerTest.java @@ -23,7 +23,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Map; -import java.util.PropertyPermission; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; @@ -34,12 +33,13 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.resteasy.microprofile.config.ServletConfigSource; import org.jboss.resteasy.microprofile.config.ServletContextConfigSource; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigFilter; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigResource; import org.jboss.resteasy.microprofile.test.config.resource.TestConfigApplication; -import org.jboss.resteasy.microprofile.test.util.PermissionUtil; +import org.jboss.resteasy.microprofile.test.util.MicroProfileConfigSystemPropertySetupTask; import org.jboss.resteasy.microprofile.test.util.TestEnvironment; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.asset.EmptyAsset; @@ -56,6 +56,7 @@ */ @RunWith(Arquillian.class) @RunAsClient +@ServerSetup(MicroProfileConfigSystemPropertySetupTask.class) public class ConfigSourceDefaultOrdinalServletContextListenerTest { static Client client; @@ -69,9 +70,7 @@ public static Archive deploy() { .addClasses(TestConfigApplication.class, MicroProfileConfigFilter.class, MicroProfileConfigResource.class) .setWebXML(ConfigSourceDefaultOrdinalServletContextListenerTest.class.getPackage(), "web_default_ordinal_servlet_context_listener.xml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsManifestResource(PermissionUtil.createPermissionsXmlAsset( - new PropertyPermission("system", "write")), "permissions.xml"); + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @BeforeClass diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceDefaultOrdinalServletTest.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceDefaultOrdinalServletTest.java index adbf091..a8d65af 100644 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceDefaultOrdinalServletTest.java +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceDefaultOrdinalServletTest.java @@ -23,7 +23,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Map; -import java.util.PropertyPermission; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; @@ -34,12 +33,13 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.resteasy.microprofile.config.ServletConfigSource; import org.jboss.resteasy.microprofile.config.ServletContextConfigSource; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigFilter; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigResource; import org.jboss.resteasy.microprofile.test.config.resource.TestConfigApplication; -import org.jboss.resteasy.microprofile.test.util.PermissionUtil; +import org.jboss.resteasy.microprofile.test.util.MicroProfileConfigSystemPropertySetupTask; import org.jboss.resteasy.microprofile.test.util.TestEnvironment; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.asset.EmptyAsset; @@ -56,6 +56,7 @@ */ @RunWith(Arquillian.class) @RunAsClient +@ServerSetup(MicroProfileConfigSystemPropertySetupTask.class) public class ConfigSourceDefaultOrdinalServletTest { static Client client; @@ -68,9 +69,7 @@ public static Archive deploy() { return TestEnvironment.createWar(ConfigSourceDefaultOrdinalServletTest.class) .addClasses(TestConfigApplication.class, MicroProfileConfigFilter.class, MicroProfileConfigResource.class) .setWebXML(ConfigSourceDefaultOrdinalServletTest.class.getPackage(), "web_default_ordinal_servlet.xml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsManifestResource(PermissionUtil.createPermissionsXmlAsset( - new PropertyPermission("system", "write")), "permissions.xml"); + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @BeforeClass diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceOverrideOrdinalFilterTest.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceOverrideOrdinalFilterTest.java index e619dfc..9736def 100644 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceOverrideOrdinalFilterTest.java +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceOverrideOrdinalFilterTest.java @@ -23,7 +23,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Map; -import java.util.PropertyPermission; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; @@ -34,12 +33,13 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.resteasy.microprofile.config.FilterConfigSource; import org.jboss.resteasy.microprofile.config.ServletContextConfigSource; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigFilter; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigResource; import org.jboss.resteasy.microprofile.test.config.resource.TestConfigApplication; -import org.jboss.resteasy.microprofile.test.util.PermissionUtil; +import org.jboss.resteasy.microprofile.test.util.MicroProfileConfigSystemPropertySetupTask; import org.jboss.resteasy.microprofile.test.util.TestEnvironment; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.asset.EmptyAsset; @@ -56,6 +56,7 @@ */ @RunWith(Arquillian.class) @RunAsClient +@ServerSetup(MicroProfileConfigSystemPropertySetupTask.class) public class ConfigSourceOverrideOrdinalFilterTest { static Client client; @@ -68,9 +69,7 @@ public static Archive deploy() { return TestEnvironment.createWar(ConfigSourceOverrideOrdinalFilterTest.class) .addClasses(TestConfigApplication.class, MicroProfileConfigFilter.class, MicroProfileConfigResource.class) .setWebXML(ConfigSourceOverrideOrdinalFilterTest.class.getPackage(), "web_override_ordinal_filter.xml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsManifestResource(PermissionUtil.createPermissionsXmlAsset( - new PropertyPermission("system", "write")), "permissions.xml"); + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @BeforeClass diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceOverrideOrdinalServletContextListenerTest.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceOverrideOrdinalServletContextListenerTest.java index c222cb8..202349e 100644 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceOverrideOrdinalServletContextListenerTest.java +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceOverrideOrdinalServletContextListenerTest.java @@ -23,7 +23,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Map; -import java.util.PropertyPermission; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; @@ -34,12 +33,13 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.resteasy.microprofile.config.ServletConfigSource; import org.jboss.resteasy.microprofile.config.ServletContextConfigSource; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigFilter; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigResource; import org.jboss.resteasy.microprofile.test.config.resource.TestConfigApplication; -import org.jboss.resteasy.microprofile.test.util.PermissionUtil; +import org.jboss.resteasy.microprofile.test.util.MicroProfileConfigSystemPropertySetupTask; import org.jboss.resteasy.microprofile.test.util.TestEnvironment; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.asset.EmptyAsset; @@ -56,6 +56,7 @@ */ @RunWith(Arquillian.class) @RunAsClient +@ServerSetup(MicroProfileConfigSystemPropertySetupTask.class) public class ConfigSourceOverrideOrdinalServletContextListenerTest { static Client client; @@ -69,9 +70,7 @@ public static Archive deploy() { .addClasses(TestConfigApplication.class, MicroProfileConfigFilter.class, MicroProfileConfigResource.class) .setWebXML(ConfigSourceOverrideOrdinalServletContextListenerTest.class.getPackage(), "web_override_ordinal_servlet_context_listener.xml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsManifestResource(PermissionUtil.createPermissionsXmlAsset( - new PropertyPermission("system", "write")), "permissions.xml"); + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @BeforeClass diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceOverrideOrdinalServletTest.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceOverrideOrdinalServletTest.java index 150ecda..8a0d2bd 100644 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceOverrideOrdinalServletTest.java +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/ConfigSourceOverrideOrdinalServletTest.java @@ -23,7 +23,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Map; -import java.util.PropertyPermission; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; @@ -34,12 +33,13 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.resteasy.microprofile.config.ServletConfigSource; import org.jboss.resteasy.microprofile.config.ServletContextConfigSource; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigFilter; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigResource; import org.jboss.resteasy.microprofile.test.config.resource.TestConfigApplication; -import org.jboss.resteasy.microprofile.test.util.PermissionUtil; +import org.jboss.resteasy.microprofile.test.util.MicroProfileConfigSystemPropertySetupTask; import org.jboss.resteasy.microprofile.test.util.TestEnvironment; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.asset.EmptyAsset; @@ -56,6 +56,7 @@ */ @RunWith(Arquillian.class) @RunAsClient +@ServerSetup(MicroProfileConfigSystemPropertySetupTask.class) public class ConfigSourceOverrideOrdinalServletTest { static Client client; @@ -68,9 +69,7 @@ public static Archive deploy() { return TestEnvironment.createWar(ConfigSourceOverrideOrdinalServletTest.class) .addClasses(TestConfigApplication.class, MicroProfileConfigFilter.class, MicroProfileConfigResource.class) .setWebXML(ConfigSourceOverrideOrdinalServletTest.class.getPackage(), "web_override_ordinal_servlet.xml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsManifestResource(PermissionUtil.createPermissionsXmlAsset( - new PropertyPermission("system", "write")), "permissions.xml"); + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @BeforeClass diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/MicroProfileConfigFilterTest.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/MicroProfileConfigFilterTest.java index 37fc0df..9342893 100644 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/MicroProfileConfigFilterTest.java +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/MicroProfileConfigFilterTest.java @@ -22,7 +22,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.util.PropertyPermission; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; @@ -32,10 +31,11 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigFilter; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigResource; import org.jboss.resteasy.microprofile.test.config.resource.TestConfigApplication; -import org.jboss.resteasy.microprofile.test.util.PermissionUtil; +import org.jboss.resteasy.microprofile.test.util.MicroProfileConfigSystemPropertySetupTask; import org.jboss.resteasy.microprofile.test.util.TestEnvironment; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.asset.EmptyAsset; @@ -53,6 +53,7 @@ */ @RunWith(Arquillian.class) @RunAsClient +@ServerSetup(MicroProfileConfigSystemPropertySetupTask.class) public class MicroProfileConfigFilterTest { static Client client; @@ -65,9 +66,7 @@ public static Archive deploy() { return TestEnvironment.createWar(MicroProfileConfigFilterTest.class) .addClasses(TestConfigApplication.class, MicroProfileConfigFilter.class, MicroProfileConfigResource.class) .setWebXML(MicroProfileConfigFilterTest.class.getPackage(), "web_filter.xml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsManifestResource(PermissionUtil.createPermissionsXmlAsset( - new PropertyPermission("system", "write")), "permissions.xml"); + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @BeforeClass diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/MicroProfileConfigServletContextListenerTest.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/MicroProfileConfigServletContextListenerTest.java index 43053d9..2157113 100644 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/MicroProfileConfigServletContextListenerTest.java +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/MicroProfileConfigServletContextListenerTest.java @@ -22,7 +22,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.util.PropertyPermission; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; @@ -32,10 +31,11 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigFilter; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigResource; import org.jboss.resteasy.microprofile.test.config.resource.TestConfigApplication; -import org.jboss.resteasy.microprofile.test.util.PermissionUtil; +import org.jboss.resteasy.microprofile.test.util.MicroProfileConfigSystemPropertySetupTask; import org.jboss.resteasy.microprofile.test.util.TestEnvironment; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.asset.EmptyAsset; @@ -53,6 +53,7 @@ */ @RunWith(Arquillian.class) @RunAsClient +@ServerSetup(MicroProfileConfigSystemPropertySetupTask.class) public class MicroProfileConfigServletContextListenerTest { static Client client; @@ -65,9 +66,7 @@ public static Archive deploy() { return TestEnvironment.createWar(MicroProfileConfigServletContextListenerTest.class) .addClasses(TestConfigApplication.class, MicroProfileConfigFilter.class, MicroProfileConfigResource.class) .setWebXML(MicroProfileConfigServletContextListenerTest.class.getPackage(), "web_servlet_context_listener.xml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsManifestResource(PermissionUtil.createPermissionsXmlAsset( - new PropertyPermission("system", "write")), "permissions.xml"); + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @BeforeClass diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/MicroProfileConfigServletTest.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/MicroProfileConfigServletTest.java index 2c59e39..76af1c6 100644 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/MicroProfileConfigServletTest.java +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/MicroProfileConfigServletTest.java @@ -22,7 +22,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.util.PropertyPermission; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; @@ -32,10 +31,11 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigFilter; import org.jboss.resteasy.microprofile.test.config.resource.MicroProfileConfigResource; import org.jboss.resteasy.microprofile.test.config.resource.TestConfigApplication; -import org.jboss.resteasy.microprofile.test.util.PermissionUtil; +import org.jboss.resteasy.microprofile.test.util.MicroProfileConfigSystemPropertySetupTask; import org.jboss.resteasy.microprofile.test.util.TestEnvironment; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.asset.EmptyAsset; @@ -53,6 +53,7 @@ */ @RunWith(Arquillian.class) @RunAsClient +@ServerSetup(MicroProfileConfigSystemPropertySetupTask.class) public class MicroProfileConfigServletTest { static Client client; @@ -64,9 +65,7 @@ public static Archive deploy() { return TestEnvironment.createWar(MicroProfileConfigServletTest.class) .addClasses(TestConfigApplication.class, MicroProfileConfigFilter.class, MicroProfileConfigResource.class) .setWebXML(MicroProfileConfigServletTest.class.getPackage(), "web_servlet.xml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsManifestResource(PermissionUtil.createPermissionsXmlAsset( - new PropertyPermission("system", "write")), "permissions.xml"); + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @BeforeClass diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/OptionalConfigPropertyInjectionTest.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/OptionalConfigPropertyInjectionTest.java index 4c82cb3..b7923e1 100644 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/OptionalConfigPropertyInjectionTest.java +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/OptionalConfigPropertyInjectionTest.java @@ -20,6 +20,7 @@ package org.jboss.resteasy.microprofile.test.config; import java.net.URL; +import java.util.Map; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; @@ -29,8 +30,10 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.resteasy.microprofile.test.config.resource.OptionalConfigPropertyInjectionResource; import org.jboss.resteasy.microprofile.test.util.TestEnvironment; +import org.jboss.resteasy.setup.SystemPropertySetupTask; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.junit.AfterClass; @@ -47,8 +50,16 @@ */ @RunWith(Arquillian.class) @RunAsClient +@ServerSetup(OptionalConfigPropertyInjectionTest.PropertySetupTask.class) public class OptionalConfigPropertyInjectionTest { + public static class PropertySetupTask extends SystemPropertySetupTask { + public PropertySetupTask() { + super(Map.of(OptionalConfigPropertyInjectionResource.PRESENT_OPTIONAL_PROPERTY_NAME, + OptionalConfigPropertyInjectionResource.OPTIONAL_PROPERTY_VALUE)); + } + } + private static Client client; @ArquillianResource diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/resource/MicroProfileConfigResource.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/resource/MicroProfileConfigResource.java index 309daee..34aff77 100644 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/resource/MicroProfileConfigResource.java +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/resource/MicroProfileConfigResource.java @@ -36,10 +36,6 @@ @Path("/") public class MicroProfileConfigResource { - static { - System.setProperty("system", "system-system"); - } - @Inject Config config; diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/resource/OptionalConfigPropertyInjectionResource.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/resource/OptionalConfigPropertyInjectionResource.java index ee68e44..d9c7672 100644 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/resource/OptionalConfigPropertyInjectionResource.java +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/config/resource/OptionalConfigPropertyInjectionResource.java @@ -36,13 +36,9 @@ public class OptionalConfigPropertyInjectionResource { public static final String PRESENT_OPTIONAL_PROPERTY_PATH = "/presentOptionalProperty"; private static final String MISSING_OPTIONAL_PROPERTY_NAME = "org.jboss.resteasy.test.missingOptionalProperty"; - private static final String PRESENT_OPTIONAL_PROPERTY_NAME = "org.jboss.resteasy.test.presentOptionalProperty"; + public static final String PRESENT_OPTIONAL_PROPERTY_NAME = "org.jboss.resteasy.test.presentOptionalProperty"; public static final String OPTIONAL_PROPERTY_VALUE = "I'm a optional property but I'm here"; - static { - System.setProperty(PRESENT_OPTIONAL_PROPERTY_NAME, OPTIONAL_PROPERTY_VALUE); - } - @Inject @ConfigProperty(name = MISSING_OPTIONAL_PROPERTY_NAME) private Optional missingOptionalProperty; diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/util/MicroProfileConfigSystemPropertySetupTask.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/util/MicroProfileConfigSystemPropertySetupTask.java new file mode 100644 index 0000000..2a10658 --- /dev/null +++ b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/util/MicroProfileConfigSystemPropertySetupTask.java @@ -0,0 +1,38 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2023 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.resteasy.microprofile.test.util; + +import java.util.Map; + +import org.jboss.resteasy.setup.SystemPropertySetupTask; + +/** + * Adds a known system property used for config tests. + * + * @author James R. Perkins + */ +public class MicroProfileConfigSystemPropertySetupTask extends SystemPropertySetupTask { + public static final String KEY = "system"; + public static final String VALUE = "system-system"; + + public MicroProfileConfigSystemPropertySetupTask() { + super(Map.of(KEY, VALUE)); + } +} diff --git a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/util/PermissionUtil.java b/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/util/PermissionUtil.java deleted file mode 100644 index 32f2366..0000000 --- a/testsuite/integration-tests/src/test/java/org/jboss/resteasy/microprofile/test/util/PermissionUtil.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * - * Copyright 2021 Red Hat, Inc., and individual contributors - * as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jboss.resteasy.microprofile.test.util; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; -import java.security.Permission; - -import org.jboss.shrinkwrap.api.asset.Asset; -import org.jboss.shrinkwrap.api.asset.StringAsset; - -import nu.xom.Attribute; -import nu.xom.Document; -import nu.xom.Element; -import nu.xom.Serializer; - -/** - * @author David M. Lloyd - * Taken from: - * https://github.com/wildfly/wildfly-core/blob/master/testsuite/shared/src/main/java/org/jboss/as/test/shared/PermissionUtils.java - */ -public final class PermissionUtil { - public static Asset createPermissionsXmlAsset(Permission... permissions) { - return new StringAsset(new String(createPermissionsXml(permissions), StandardCharsets.UTF_8)); - } - - public static byte[] createPermissionsXml(Permission... permissions) { - final Element permissionsElement = new Element("permissions"); - permissionsElement.setNamespaceURI("http://xmlns.jcp.org/xml/ns/javaee"); - permissionsElement.addAttribute(new Attribute("version", "7")); - for (Permission permission : permissions) { - final Element permissionElement = new Element("permission"); - - final Element classNameElement = new Element("class-name"); - final Element nameElement = new Element("name"); - classNameElement.appendChild(permission.getClass().getName()); - nameElement.appendChild(permission.getName()); - permissionElement.appendChild(classNameElement); - permissionElement.appendChild(nameElement); - - final String actions = permission.getActions(); - if (actions != null && !actions.isEmpty()) { - final Element actionsElement = new Element("actions"); - actionsElement.appendChild(actions); - permissionElement.appendChild(actionsElement); - } - permissionsElement.appendChild(permissionElement); - } - Document document = new Document(permissionsElement); - try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) { - final NiceSerializer serializer = new NiceSerializer(stream); - serializer.setIndent(4); - serializer.setLineSeparator("\n"); - serializer.write(document); - serializer.flush(); - return stream.toByteArray(); - } catch (IOException e) { - throw new IllegalStateException("Generating permissions.xml failed", e); - } - } - - static class NiceSerializer extends Serializer { - - NiceSerializer(final OutputStream out) throws UnsupportedEncodingException { - super(out, "UTF-8"); - } - - protected void writeXMLDeclaration() throws IOException { - super.writeXMLDeclaration(); - super.breakLine(); - } - } -} diff --git a/testsuite/integration-tests/src/test/resources/filtered/arquillian.xml b/testsuite/integration-tests/src/test/resources/filtered/arquillian.xml index 3a9ed1e..832a898 100644 --- a/testsuite/integration-tests/src/test/resources/filtered/arquillian.xml +++ b/testsuite/integration-tests/src/test/resources/filtered/arquillian.xml @@ -26,6 +26,7 @@ ${jboss.home} ${jvm.debug.args} ${jboss.server.config.file.name:standalone.xml} + ${jboss.arguments}