Skip to content

Commit

Permalink
Move all RESTEasy Reactive configuration under 'quarkus.resteasy-reac…
Browse files Browse the repository at this point in the history
…tive'

For the time being, the old 'quarkus.rest' config root is still supported,
but that support will be removed once the 'vertx-4' branch has been merged
into main (at which point the TCK will be updated to use the new values).

However the old 'quarkus.security.jaxrs.deny-unannotated-endpoints' is not
supported
  • Loading branch information
geoand committed Apr 7, 2021
1 parent e37f1d2 commit 9112619
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<>())
Expand Down Expand Up @@ -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> T getEffectivePropertyValue(String legacyPropertyName, T newPropertyValue, Class<T> propertyType,
Config mpConfig) {
Optional<T> legacyPropertyValue = mpConfig.getOptionalValue("quarkus.rest." + legacyPropertyName, propertyType);
if (legacyPropertyValue.isPresent()) {
return legacyPropertyValue.get();
}
return newPropertyValue;
}

private String defaultMediaType(List<? extends MediaTypeWithPriority> defaultMediaTypes, String defaultMediaType) {
if (defaultMediaTypes == null || defaultMediaTypes.isEmpty()) {
return defaultMediaType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -64,7 +63,7 @@ public class ResteasyReactiveCommonProcessor {

@BuildStep
void setUpDenyAllJaxRs(CombinedIndexBuildItem index,
JaxRsSecurityConfig config,
ResteasyReactiveConfig config,
Optional<ResourceScanningResultBuildItem> resteasyDeployment,
BuildProducer<AdditionalSecuredClassesBuildIem> additionalSecuredClasses) {
if (config.denyJaxRs && resteasyDeployment.isPresent()) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -501,7 +502,7 @@ private boolean hasAnnotation(MethodInfo method, short paramPosition, DotName an
BeanFactory<ResteasyReactiveInitialiser> 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);
Expand All @@ -513,8 +514,7 @@ private boolean hasAnnotation(MethodInfo method, short paramPosition, DotName an
Class<? extends Application> 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)
Expand Down Expand Up @@ -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> T getEffectivePropertyValue(String legacyPropertyName, T newPropertyValue, Class<T> propertyType,
Config mpConfig) {
Optional<T> 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,
Expand Down Expand Up @@ -602,6 +620,15 @@ public List<HandlerChainCustomizer> scan(MethodInfo method, Map<String, Object>
});
}

private Optional<String> getAppPath(Optional<String> newPropertyValue) {
Optional<String> legacyProperty = ConfigProvider.getConfig().getOptionalValue("quarkus.rest.path", String.class);
if (legacyProperty.isPresent()) {
return legacyProperty;
}

return newPropertyValue;
}

private String determineApplicationPath(IndexView index, Optional<String> defaultPath) {
Collection<AnnotationInstance> applicationPaths = index.getAnnotations(ResteasyReactiveDotNames.APPLICATION_PATH);
if (applicationPaths.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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));

@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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> appPath = ConfigProvider.getConfig().getOptionalValue("quarkus.rest.path", String.class);
Optional<String> appPath = getAppPath();
if (appPath.isPresent()) {
path = appPath.get();
}
Expand All @@ -40,6 +41,16 @@ public String apply(Class<?> aClass) {
};
}

private Optional<String> getAppPath() {
Config config = ConfigProvider.getConfig();
Optional<String> 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()) {
Expand Down

0 comments on commit 9112619

Please sign in to comment.