33import static io .quarkus .resteasy .reactive .common .deployment .QuarkusResteasyReactiveDotNames .HTTP_SERVER_REQUEST ;
44import static io .quarkus .resteasy .reactive .common .deployment .QuarkusResteasyReactiveDotNames .HTTP_SERVER_RESPONSE ;
55import static io .quarkus .resteasy .reactive .common .deployment .QuarkusResteasyReactiveDotNames .ROUTING_CONTEXT ;
6+ import static io .quarkus .security .spi .SecurityTransformer .AuthorizationType .AUTHORIZATION_POLICY ;
7+ import static io .quarkus .security .spi .SecurityTransformer .AuthorizationType .SECURITY_CHECK ;
8+ import static io .quarkus .security .spi .SecurityTransformerBuildItem .createSecurityTransformer ;
69import static io .quarkus .vertx .http .deployment .EagerSecurityInterceptorMethodsBuildItem .collectInterceptedMethods ;
710import static java .util .stream .Collectors .toList ;
811import static org .jboss .resteasy .reactive .common .processor .ResteasyReactiveDotNames .DATE_FORMAT ;
218221import io .quarkus .security .AuthenticationRedirectException ;
219222import io .quarkus .security .ForbiddenException ;
220223import io .quarkus .security .spi .PermissionsAllowedMetaAnnotationBuildItem ;
221- import io .quarkus .security .spi .SecurityTransformerUtils ;
224+ import io .quarkus .security .spi .SecurityTransformer ;
225+ import io .quarkus .security .spi .SecurityTransformerBuildItem ;
222226import io .quarkus .vertx .http .deployment .AuthorizationPolicyInstancesBuildItem ;
223227import io .quarkus .vertx .http .deployment .EagerSecurityInterceptorMethodsBuildItem ;
224228import io .quarkus .vertx .http .deployment .FilterBuildItem ;
225- import io .quarkus .vertx .http .deployment .HttpSecurityUtils ;
226229import io .quarkus .vertx .http .deployment .RouteBuildItem ;
227230import io .quarkus .vertx .http .runtime .RouteConstants ;
228231import io .quarkus .vertx .http .runtime .VertxHttpBuildTimeConfig ;
@@ -1765,10 +1768,13 @@ public void securityExceptionMappers(BuildProducer<ExceptionMapperBuildItem> exc
17651768 MethodScannerBuildItem integrateEagerSecurity (Capabilities capabilities , CombinedIndexBuildItem indexBuildItem ,
17661769 Optional <AuthorizationPolicyInstancesBuildItem > authorizationPolicyInstancesItemOpt ,
17671770 List <EagerSecurityInterceptorMethodsBuildItem > eagerSecurityInterceptors , JaxRsSecurityConfig securityConfig ,
1768- Optional <PermissionsAllowedMetaAnnotationBuildItem > permsAllowedMetaAnnotationItemOptional ) {
1771+ Optional <PermissionsAllowedMetaAnnotationBuildItem > permsAllowedMetaAnnotationItemOptional ,
1772+ Optional <SecurityTransformerBuildItem > securityTransformerBuildItem ) {
17691773 if (!capabilities .isPresent (Capability .SECURITY )) {
17701774 return null ;
17711775 }
1776+ SecurityTransformer securityTransformer = SecurityTransformerBuildItem .createSecurityTransformer (
1777+ indexBuildItem .getIndex (), securityTransformerBuildItem );
17721778 var authZPolicyInstancesItem = authorizationPolicyInstancesItemOpt .get ();
17731779 var permsAllowedMetaAnnotationItem = permsAllowedMetaAnnotationItemOptional .get ();
17741780
@@ -1787,17 +1793,19 @@ public List<HandlerChainCustomizer> scan(MethodInfo method, ClassInfo actualEndp
17871793 boolean isMethodIntercepted = interceptedMethods .containsKey (endpointImpl );
17881794 if (isMethodIntercepted ) {
17891795 return createEagerSecCustomizerWithInterceptor (interceptedMethods , endpointImpl , method , endpointImpl ,
1790- withDefaultSecurityCheck , applyAuthorizationPolicy , permsAllowedMetaAnnotationItem );
1796+ withDefaultSecurityCheck , applyAuthorizationPolicy , permsAllowedMetaAnnotationItem ,
1797+ securityTransformer );
17911798 } else {
17921799 isMethodIntercepted = interceptedMethods .containsKey (method );
17931800 if (isMethodIntercepted && !endpointImpl .equals (method )) {
17941801 return createEagerSecCustomizerWithInterceptor (interceptedMethods , method , method , endpointImpl ,
1795- withDefaultSecurityCheck , applyAuthorizationPolicy , permsAllowedMetaAnnotationItem );
1802+ withDefaultSecurityCheck , applyAuthorizationPolicy , permsAllowedMetaAnnotationItem ,
1803+ securityTransformer );
17961804 }
17971805 }
17981806 }
17991807 return List .of (newEagerSecurityHandlerCustomizerInstance (method , endpointImpl , withDefaultSecurityCheck ,
1800- applyAuthorizationPolicy , permsAllowedMetaAnnotationItem ));
1808+ applyAuthorizationPolicy , permsAllowedMetaAnnotationItem , securityTransformer ));
18011809 }
18021810 });
18031811 }
@@ -1810,28 +1818,32 @@ private static boolean shouldApplyAuthZPolicy(MethodInfo method, MethodInfo endp
18101818 private static List <HandlerChainCustomizer > createEagerSecCustomizerWithInterceptor (
18111819 Map <MethodInfo , Boolean > interceptedMethods , MethodInfo method , MethodInfo originalMethod , MethodInfo endpointImpl ,
18121820 boolean withDefaultSecurityCheck , boolean applyAuthorizationPolicy ,
1813- PermissionsAllowedMetaAnnotationBuildItem permsAllowedMetaAnnotationItem ) {
1821+ PermissionsAllowedMetaAnnotationBuildItem permsAllowedMetaAnnotationItem ,
1822+ SecurityTransformer securityTransformer ) {
18141823 var requiresSecurityCheck = interceptedMethods .get (method );
18151824 final HandlerChainCustomizer eagerSecCustomizer ;
18161825 if (requiresSecurityCheck && !applyAuthorizationPolicy ) {
18171826 // standard security annotation and possibly authorization using configuration
18181827 eagerSecCustomizer = new HttpPermissionsAndSecurityChecksCustomizer ();
18191828 } else {
18201829 eagerSecCustomizer = newEagerSecurityHandlerCustomizerInstance (originalMethod , endpointImpl ,
1821- withDefaultSecurityCheck , applyAuthorizationPolicy , permsAllowedMetaAnnotationItem );
1830+ withDefaultSecurityCheck , applyAuthorizationPolicy , permsAllowedMetaAnnotationItem ,
1831+ securityTransformer );
18221832 }
18231833 return List .of (EagerSecurityInterceptorHandler .Customizer .newInstance (), eagerSecCustomizer );
18241834 }
18251835
18261836 private static HandlerChainCustomizer newEagerSecurityHandlerCustomizerInstance (MethodInfo method , MethodInfo endpointImpl ,
18271837 boolean withDefaultSecurityCheck , boolean applyAuthorizationPolicy ,
1828- PermissionsAllowedMetaAnnotationBuildItem permsAllowedMetaAnnotationItem ) {
1838+ PermissionsAllowedMetaAnnotationBuildItem permsAllowedMetaAnnotationItem ,
1839+ SecurityTransformer securityTransformer ) {
18291840 if (applyAuthorizationPolicy ) {
18301841 // @AuthorizationPolicy and possibly authorization using configuration
18311842 return new AuthZPolicyCustomizer ();
18321843 }
18331844 if (withDefaultSecurityCheck
1834- || consumesStandardSecurityAnnotations (method , endpointImpl , permsAllowedMetaAnnotationItem )) {
1845+ || consumesStandardSecurityAnnotations (method , endpointImpl , permsAllowedMetaAnnotationItem ,
1846+ securityTransformer )) {
18351847 // standard security annotation and possibly authorization using configuration
18361848 return new HttpPermissionsAndSecurityChecksCustomizer ();
18371849 }
@@ -1904,25 +1916,27 @@ void registerSecurityBeans(Capabilities capabilities,
19041916 }
19051917
19061918 private static boolean consumesStandardSecurityAnnotations (MethodInfo methodInfo , MethodInfo endpointImpl ,
1907- PermissionsAllowedMetaAnnotationBuildItem permsAllowedMetaAnnotationItem ) {
1919+ PermissionsAllowedMetaAnnotationBuildItem permsAllowedMetaAnnotationItem ,
1920+ SecurityTransformer securityTransformer ) {
19081921 // invoked method
1909- if (consumesStandardSecurityAnnotations (endpointImpl , permsAllowedMetaAnnotationItem )) {
1922+ if (consumesStandardSecurityAnnotations (endpointImpl , permsAllowedMetaAnnotationItem , securityTransformer )) {
19101923 return true ;
19111924 }
19121925
19131926 // fallback to original behavior
19141927 return !endpointImpl .equals (methodInfo )
1915- && consumesStandardSecurityAnnotations (methodInfo , permsAllowedMetaAnnotationItem );
1928+ && consumesStandardSecurityAnnotations (methodInfo , permsAllowedMetaAnnotationItem , securityTransformer );
19161929 }
19171930
19181931 private static boolean consumesStandardSecurityAnnotations (MethodInfo methodInfo ,
1919- PermissionsAllowedMetaAnnotationBuildItem permsAllowedMetaAnnotationItem ) {
1920- boolean hasMethodLevelSecurityAnnotation = SecurityTransformerUtils .hasSecurityAnnotation (methodInfo )
1932+ PermissionsAllowedMetaAnnotationBuildItem permsAllowedMetaAnnotationItem ,
1933+ SecurityTransformer securityTransformer ) {
1934+ boolean hasMethodLevelSecurityAnnotation = securityTransformer .hasSecurityAnnotation (methodInfo , SECURITY_CHECK )
19211935 || permsAllowedMetaAnnotationItem .hasPermissionsAllowed (methodInfo );
19221936 if (hasMethodLevelSecurityAnnotation ) {
19231937 return true ;
19241938 }
1925- if (HttpSecurityUtils . hasAuthorizationPolicyAnnotation (methodInfo )) {
1939+ if (securityTransformer . hasSecurityAnnotation (methodInfo , AUTHORIZATION_POLICY )) {
19261940 // security annotations cannot be combined
19271941 // and the most specific wins, so if we have both class-level security check
19281942 // and the method-level @AuthorizationPolicy, the policy wins as it is more specific
@@ -1931,7 +1945,7 @@ private static boolean consumesStandardSecurityAnnotations(MethodInfo methodInfo
19311945 // on a method level thanks to validation
19321946 return false ;
19331947 }
1934- return SecurityTransformerUtils .hasSecurityAnnotation (methodInfo .declaringClass ())
1948+ return securityTransformer .hasSecurityAnnotation (methodInfo .declaringClass (), SECURITY_CHECK )
19351949 || permsAllowedMetaAnnotationItem .hasPermissionsAllowed (methodInfo .declaringClass ());
19361950 }
19371951
0 commit comments