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 d9b37a93faab0..62fac03831ff8 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 @@ -10,11 +10,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Consumer; import java.util.function.Function; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.ws.rs.Priorities; @@ -41,13 +41,13 @@ import org.jboss.resteasy.reactive.common.model.ResourceDynamicFeature; import org.jboss.resteasy.reactive.common.model.ResourceFeature; import org.jboss.resteasy.reactive.common.model.ResourceInterceptors; -import org.jboss.resteasy.reactive.common.model.ResourceMethod; import org.jboss.resteasy.reactive.common.model.ResourceReader; import org.jboss.resteasy.reactive.common.model.ResourceWriter; import org.jboss.resteasy.reactive.common.processor.AdditionalReaderWriter; import org.jboss.resteasy.reactive.common.processor.AdditionalReaders; import org.jboss.resteasy.reactive.common.processor.AdditionalWriters; import org.jboss.resteasy.reactive.common.processor.DefaultProducesHandler; +import org.jboss.resteasy.reactive.common.processor.EndpointIndexer; import org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames; import org.jboss.resteasy.reactive.common.processor.scanning.ApplicationScanningResult; import org.jboss.resteasy.reactive.common.processor.scanning.ResourceScanningResult; @@ -335,7 +335,7 @@ public void setupEndpoints(Capabilities capabilities, BeanArchiveIndexBuildItem QuarkusServerEndpointIndexer.Builder serverEndpointIndexerBuilder = new QuarkusServerEndpointIndexer.Builder() .addMethodScanners( - methodScanners.stream().map(MethodScannerBuildItem::getMethodScanner).collect(Collectors.toList())) + methodScanners.stream().map(MethodScannerBuildItem::getMethodScanner).collect(toList())) .setIndex(index) .setFactoryCreator(new QuarkusFactoryCreator(recorder, beanContainerBuildItem.getValue())) .setEndpointInvokerFactory(new QuarkusInvokerFactory(generatedClassBuildItemBuildProducer, recorder)) @@ -353,13 +353,20 @@ public void setupEndpoints(Capabilities capabilities, BeanArchiveIndexBuildItem .setClassLevelExceptionMappers( classLevelExceptionMappers.isPresent() ? classLevelExceptionMappers.get().getMappers() : Collections.emptyMap()) - .setResourceMethodCallback(new Consumer>() { + .setResourceMethodCallback(new Consumer<>() { @Override - public void accept(Map.Entry entry) { - MethodInfo method = entry.getKey(); + public void accept(EndpointIndexer.ResourceMethodCallbackData entry) { + MethodInfo method = entry.getMethodInfo(); String source = ResteasyReactiveProcessor.class.getSimpleName() + " > " + method.declaringClass() + "[" + method + "]"; + ClassInfo classInfoWithSecurity = consumeStandardSecurityAnnotations(method, + entry.getActualEndpointInfo(), index, c -> c); + if (classInfoWithSecurity != null) { + reflectiveClass.produce(new ReflectiveClassBuildItem(false, true, false, + entry.getActualEndpointInfo().name().toString())); + } + reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem.Builder() .type(method.returnType()) .index(index) @@ -648,21 +655,29 @@ MethodScannerBuildItem integrateEagerSecurity(Capabilities capabilities, Combine @Override public List scan(MethodInfo method, ClassInfo actualEndpointClass, Map methodContext) { - if (SecurityTransformerUtils.hasStandardSecurityAnnotation(method)) { - return Collections.singletonList(new EagerSecurityHandler.Customizer()); - } - ClassInfo c = actualEndpointClass; - while (c.superName() != null) { - if (SecurityTransformerUtils.hasStandardSecurityAnnotation(c)) { - return Collections.singletonList(new EagerSecurityHandler.Customizer()); - } - c = index.getClassByName(c.superName()); - } - return Collections.emptyList(); + return Objects.requireNonNullElse( + consumeStandardSecurityAnnotations(method, actualEndpointClass, index, + (c) -> Collections.singletonList(new EagerSecurityHandler.Customizer())), + Collections.emptyList()); } }); } + private T consumeStandardSecurityAnnotations(MethodInfo methodInfo, ClassInfo classInfo, IndexView index, + Function function) { + if (SecurityTransformerUtils.hasStandardSecurityAnnotation(methodInfo)) { + return function.apply(methodInfo.declaringClass()); + } + ClassInfo c = classInfo; + while (c.superName() != null) { + if (SecurityTransformerUtils.hasStandardSecurityAnnotation(c)) { + return function.apply(c); + } + c = index.getClassByName(c.superName()); + } + return null; + } + private Optional getAppPath(Optional newPropertyValue) { Optional legacyProperty = ConfigProvider.getConfig().getOptionalValue("quarkus.rest.path", String.class); if (legacyProperty.isPresent()) { diff --git a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/EndpointIndexer.java b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/EndpointIndexer.java index 7620df556c91d..46a374068d1d9 100644 --- a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/EndpointIndexer.java +++ b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/EndpointIndexer.java @@ -177,7 +177,7 @@ public abstract class EndpointIndexer> classLevelExceptionMappers; private final Function> factoryCreator; - private final Consumer> resourceMethodCallback; + private final Consumer resourceMethodCallback; protected EndpointIndexer(Builder builder) { this.index = builder.index; @@ -549,7 +549,7 @@ private ResourceMethod createResourceMethod(ClassInfo currentClassInfo, ClassInf handleAdditionalMethodProcessing((METHOD) method, currentClassInfo, currentMethodInfo); if (resourceMethodCallback != null) { - resourceMethodCallback.accept(new AbstractMap.SimpleEntry<>(currentMethodInfo, method)); + resourceMethodCallback.accept(new ResourceMethodCallbackData(currentMethodInfo, actualEndpointInfo, method)); } return method; } catch (Exception e) { @@ -1144,7 +1144,7 @@ public static abstract class Builder, B private AdditionalWriters additionalWriters; private boolean hasRuntimeConverters; private Map> classLevelExceptionMappers; - private Consumer> resourceMethodCallback; + private Consumer resourceMethodCallback; public B setDefaultBlocking(BlockingDefault defaultBlocking) { this.defaultBlocking = defaultBlocking; @@ -1206,7 +1206,7 @@ public B setClassLevelExceptionMappers(Map> classLe return (B) this; } - public B setResourceMethodCallback(Consumer> resourceMethodCallback) { + public B setResourceMethodCallback(Consumer resourceMethodCallback) { this.resourceMethodCallback = resourceMethodCallback; return (B) this; } @@ -1214,4 +1214,28 @@ public B setResourceMethodCallback(Consumer