diff --git a/extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java b/extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java index 79b25f6c51a89..fe6a716a9985b 100644 --- a/extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java +++ b/extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java @@ -31,6 +31,8 @@ import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; +import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.jandex.IndexView; @@ -174,8 +176,7 @@ void setupClientProxies(JaxrsClientReactiveRecorder recorder, .setIndex(index) .setExistingConverters(new HashMap<>()) .setScannedResourcePaths(result.getScannedResourcePaths()) - .setConfig(new org.jboss.resteasy.reactive.common.ResteasyReactiveConfig(config.inputBufferSize.asLongValue(), - config.singleDefaultProduces, config.defaultProduces)) + .setConfig(createRestReactiveConfig(config)) .setAdditionalReaders(additionalReaders) .setHttpAnnotationToMethod(result.getHttpAnnotationToMethod()) .setInjectableBeans(new HashMap<>()) @@ -238,6 +239,24 @@ void setupClientProxies(JaxrsClientReactiveRecorder recorder, } + private org.jboss.resteasy.reactive.common.ResteasyReactiveConfig createRestReactiveConfig(ResteasyReactiveConfig config) { + Config mpConfig = ConfigProvider.getConfig(); + + return new org.jboss.resteasy.reactive.common.ResteasyReactiveConfig( + getEffectivePropertyValue("input-buffer-size", config.inputBufferSize.asLongValue(), Long.class, mpConfig), + getEffectivePropertyValue("single-default-produces", config.singleDefaultProduces, Boolean.class, mpConfig), + getEffectivePropertyValue("default-produces", config.defaultProduces, Boolean.class, mpConfig)); + } + + private T getEffectivePropertyValue(String legacyPropertyName, T newPropertyValue, Class propertyType, + Config mpConfig) { + Optional legacyPropertyValue = mpConfig.getOptionalValue("quarkus.rest." + legacyPropertyName, propertyType); + if (legacyPropertyValue.isPresent()) { + return legacyPropertyValue.get(); + } + return newPropertyValue; + } + private String defaultMediaType(List defaultMediaTypes, String defaultMediaType) { if (defaultMediaTypes == null || defaultMediaTypes.isEmpty()) { return defaultMediaType; diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/deployment/src/main/java/io/quarkus/resteasy/reactive/common/deployment/ResteasyReactiveCommonProcessor.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/deployment/src/main/java/io/quarkus/resteasy/reactive/common/deployment/ResteasyReactiveCommonProcessor.java index 38a8dc8b417c1..ef9de95ea6db0 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/deployment/src/main/java/io/quarkus/resteasy/reactive/common/deployment/ResteasyReactiveCommonProcessor.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/deployment/src/main/java/io/quarkus/resteasy/reactive/common/deployment/ResteasyReactiveCommonProcessor.java @@ -43,7 +43,6 @@ import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.util.JandexUtil; -import io.quarkus.resteasy.reactive.common.runtime.JaxRsSecurityConfig; import io.quarkus.resteasy.reactive.common.runtime.ResteasyReactiveConfig; import io.quarkus.resteasy.reactive.spi.AbstractInterceptorBuildItem; import io.quarkus.resteasy.reactive.spi.ContainerRequestFilterBuildItem; @@ -64,7 +63,7 @@ public class ResteasyReactiveCommonProcessor { @BuildStep void setUpDenyAllJaxRs(CombinedIndexBuildItem index, - JaxRsSecurityConfig config, + ResteasyReactiveConfig config, Optional resteasyDeployment, BuildProducer additionalSecuredClasses) { if (config.denyJaxRs && resteasyDeployment.isPresent()) { diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/JaxRsSecurityConfig.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/JaxRsSecurityConfig.java deleted file mode 100644 index 781feb25b5715..0000000000000 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/JaxRsSecurityConfig.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.quarkus.resteasy.reactive.common.runtime; - -import io.quarkus.runtime.annotations.ConfigItem; -import io.quarkus.runtime.annotations.ConfigPhase; -import io.quarkus.runtime.annotations.ConfigRoot; - -/** - * @author Michal Szynkiewicz, michal.l.szynkiewicz@gmail.com - */ -@ConfigRoot(name = "security.jaxrs", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) -public class JaxRsSecurityConfig { - /** - * if set to true, access to all JAX-RS resources will be denied by default - */ - @ConfigItem(name = "deny-unannotated-endpoints") - public boolean denyJaxRs; -} diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ResteasyReactiveConfig.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ResteasyReactiveConfig.java index 6e3405f60d495..5d2d26ae86657 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ResteasyReactiveConfig.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ResteasyReactiveConfig.java @@ -6,7 +6,7 @@ import io.quarkus.runtime.configuration.MemorySize; import io.smallrye.common.annotation.Experimental; -@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED, name = "rest") +@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED, name = "resteasy-reactive") public class ResteasyReactiveConfig { /** @@ -41,4 +41,10 @@ public class ResteasyReactiveConfig { */ @ConfigItem(defaultValue = "true") public boolean buildTimeConditionAware; + + /** + * If set to true, access to all JAX-RS resources will be denied by default + */ + @ConfigItem(name = "deny-unannotated-endpoints") + public boolean denyJaxRs; } diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java index ccbefc71b2664..647750e415240 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java @@ -24,6 +24,8 @@ import javax.ws.rs.ext.MessageBodyReader; import javax.ws.rs.ext.MessageBodyWriter; +import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.AnnotationValue; @@ -318,8 +320,7 @@ public void setupEndpoints(Capabilities capabilities, BeanArchiveIndexBuildItem .setBytecodeTransformerBuildProducer(bytecodeTransformerBuildItemBuildProducer) .setReflectiveClassProducer(reflectiveClassBuildItemBuildProducer) .setExistingConverters(existingConverters).setScannedResourcePaths(scannedResourcePaths) - .setConfig(new org.jboss.resteasy.reactive.common.ResteasyReactiveConfig( - config.inputBufferSize.asLongValue(), config.singleDefaultProduces, config.defaultProduces)) + .setConfig(createRestReactiveConfig(config)) .setAdditionalReaders(additionalReaders) .setHttpAnnotationToMethod(result.getHttpAnnotationToMethod()) .setInjectableBeans(injectableBeans) @@ -501,7 +502,7 @@ private boolean hasAnnotation(MethodInfo method, short paramPosition, DotName an BeanFactory initClassFactory = recorder.factory(QUARKUS_INIT_CLASS, beanContainerBuildItem.getValue()); - String applicationPath = determineApplicationPath(index, serverConfig.path); + String applicationPath = determineApplicationPath(index, getAppPath(serverConfig.path)); // spec allows the path contain encoded characters if ((applicationPath != null) && applicationPath.contains("%")) { applicationPath = Encode.decodePath(applicationPath); @@ -513,8 +514,7 @@ private boolean hasAnnotation(MethodInfo method, short paramPosition, DotName an Class applicationClass = application == null ? Application.class : application.getClass(); DeploymentInfo deploymentInfo = new DeploymentInfo() .setInterceptors(interceptors.sort()) - .setConfig(new org.jboss.resteasy.reactive.common.ResteasyReactiveConfig( - config.inputBufferSize.asLongValue(), config.singleDefaultProduces, config.defaultProduces)) + .setConfig(createRestReactiveConfig(config)) .setExceptionMapping(exceptionMapping) .setCtxResolvers(contextResolvers) .setFeatures(feats) @@ -556,6 +556,24 @@ private boolean hasAnnotation(MethodInfo method, short paramPosition, DotName an } } + private org.jboss.resteasy.reactive.common.ResteasyReactiveConfig createRestReactiveConfig(ResteasyReactiveConfig config) { + Config mpConfig = ConfigProvider.getConfig(); + + return new org.jboss.resteasy.reactive.common.ResteasyReactiveConfig( + getEffectivePropertyValue("input-buffer-size", config.inputBufferSize.asLongValue(), Long.class, mpConfig), + getEffectivePropertyValue("single-default-produces", config.singleDefaultProduces, Boolean.class, mpConfig), + getEffectivePropertyValue("default-produces", config.defaultProduces, Boolean.class, mpConfig)); + } + + private T getEffectivePropertyValue(String legacyPropertyName, T newPropertyValue, Class propertyType, + Config mpConfig) { + Optional legacyPropertyValue = mpConfig.getOptionalValue("quarkus.rest." + legacyPropertyName, propertyType); + if (legacyPropertyValue.isPresent()) { + return legacyPropertyValue.get(); + } + return newPropertyValue; + } + @BuildStep @Record(ExecutionTime.RUNTIME_INIT) public void applyRuntimeConfig(ResteasyReactiveRuntimeRecorder recorder, @@ -602,6 +620,15 @@ public List scan(MethodInfo method, Map }); } + private Optional getAppPath(Optional newPropertyValue) { + Optional legacyProperty = ConfigProvider.getConfig().getOptionalValue("quarkus.rest.path", String.class); + if (legacyProperty.isPresent()) { + return legacyProperty; + } + + return newPropertyValue; + } + private String determineApplicationPath(IndexView index, Optional defaultPath) { Collection applicationPaths = index.getAnnotations(ResteasyReactiveDotNames.APPLICATION_PATH); if (applicationPaths.isEmpty()) { diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveServerConfig.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveServerConfig.java index 4c9721d275321..8d47329bd4535 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveServerConfig.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveServerConfig.java @@ -5,7 +5,7 @@ import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigRoot; -@ConfigRoot(name = "rest") +@ConfigRoot(name = "resteasy-reactive") public class ResteasyReactiveServerConfig { /** diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/path/RelativeRestPathTestCase.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/path/RelativeRestPathTestCase.java index 8d7c22e65d5eb..3f880abb457f2 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/path/RelativeRestPathTestCase.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/path/RelativeRestPathTestCase.java @@ -14,7 +14,7 @@ public class RelativeRestPathTestCase { @RegisterExtension static QuarkusUnitTest test = new QuarkusUnitTest() .withConfigurationResource("empty.properties") - .overrideConfigKey("quarkus.rest.path", "foo") + .overrideConfigKey("quarkus.resteasy-reactive.path", "foo") .overrideConfigKey("quarkus.http.root-path", "/app") .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) .addClass(HelloResource.class)); diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/path/RestApplicationPathTestCase.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/path/RestApplicationPathTestCase.java index 97ad921ff0e10..72814a37331e0 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/path/RestApplicationPathTestCase.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/path/RestApplicationPathTestCase.java @@ -17,7 +17,7 @@ public class RestApplicationPathTestCase { @RegisterExtension static QuarkusUnitTest test = new QuarkusUnitTest() .withConfigurationResource("empty.properties") - .overrideConfigKey("quarkus.rest.path", "/foo") + .overrideConfigKey("quarkus.resteasy-reactive.path", "/foo") .overrideConfigKey("quarkus.http.root-path", "/app") .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) .addClasses(HelloResource.class, BarApp.class, BaseApplication.class)); diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/path/RestPathTestCase.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/path/RestPathTestCase.java index 379f4c84644b5..96acfeb0d4fcc 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/path/RestPathTestCase.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/path/RestPathTestCase.java @@ -14,7 +14,7 @@ public class RestPathTestCase { @RegisterExtension static QuarkusUnitTest test = new QuarkusUnitTest() .withConfigurationResource("empty.properties") - .overrideConfigKey("quarkus.rest.path", "/foo") + .overrideConfigKey("quarkus.resteasy-reactive.path", "/foo") .overrideConfigKey("quarkus.http.root-path", "/app") .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) .addClass(HelloResource.class)); @@ -22,7 +22,7 @@ public class RestPathTestCase { @Test public void testRestPath() { RestAssured.basePath = "/"; - RestAssured.when().get("/app/foo/hello").then().body(Matchers.is("hello")); - RestAssured.when().get("/app/foo/hello/nested").then().body(Matchers.is("world hello")); + RestAssured.when().get("/app/foo/hello").then().statusCode(200).body(Matchers.is("hello")); + RestAssured.when().get("/app/foo/hello/nested").then().statusCode(200).body(Matchers.is("world hello")); } } diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/security/DenyAllJaxRsTest.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/security/DenyAllJaxRsTest.java index 1ed546f18cef3..916a5e166c2e0 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/security/DenyAllJaxRsTest.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/security/DenyAllJaxRsTest.java @@ -25,7 +25,7 @@ public class DenyAllJaxRsTest { TestIdentityProvider.class, TestIdentityController.class, UnsecuredSubResource.class) - .addAsResource(new StringAsset("quarkus.security.jaxrs.deny-unannotated-endpoints = true\n"), + .addAsResource(new StringAsset("quarkus.resteasy-reactive.deny-unannotated-endpoints = true\n"), "application.properties")); @BeforeAll diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/ResteasyReactiveTestHttpProvider.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/ResteasyReactiveTestHttpProvider.java index aad96fe47e6e8..995b090653838 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/ResteasyReactiveTestHttpProvider.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/ResteasyReactiveTestHttpProvider.java @@ -7,6 +7,7 @@ import javax.ws.rs.Path; +import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.ConfigProvider; import io.quarkus.runtime.test.TestHttpEndpointProvider; @@ -27,7 +28,7 @@ public String apply(Class aClass) { //TODO: there is not really any way to handle @ApplicationPath, we could do something for @QuarkusTest apps but we can't for //native apps, so we just have to document the limitation String path = "/"; - Optional appPath = ConfigProvider.getConfig().getOptionalValue("quarkus.rest.path", String.class); + Optional appPath = getAppPath(); if (appPath.isPresent()) { path = appPath.get(); } @@ -40,6 +41,16 @@ public String apply(Class aClass) { }; } + private Optional getAppPath() { + Config config = ConfigProvider.getConfig(); + Optional legacyProperty = config.getOptionalValue("quarkus.rest.path", String.class); + if (legacyProperty.isPresent()) { + return legacyProperty; + } + + return config.getOptionalValue("quarkus.resteasy-reactive.path", String.class); + } + private String getPath(Class aClass) { String value = null; for (Annotation annotation : aClass.getAnnotations()) {