From 6f5e103dec835717790df995f9f1c57f17850be7 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Thu, 12 Sep 2024 11:51:35 -0600 Subject: [PATCH] Use AnnotationTemplateExpressionDefaults in Reactive Issue gh-15097 --- ...orizationManagerMethodSecurityConfiguration.java | 9 +++++++++ .../PostAuthorizeReactiveAuthorizationManager.java | 13 +++++++++++++ ...ilterAuthorizationReactiveMethodInterceptor.java | 13 +++++++++++++ .../PreAuthorizeReactiveAuthorizationManager.java | 13 +++++++++++++ ...ilterAuthorizationReactiveMethodInterceptor.java | 13 +++++++++++++ 5 files changed, 61 insertions(+) diff --git a/config/src/main/java/org/springframework/security/config/annotation/method/configuration/ReactiveAuthorizationManagerMethodSecurityConfiguration.java b/config/src/main/java/org/springframework/security/config/annotation/method/configuration/ReactiveAuthorizationManagerMethodSecurityConfiguration.java index e9388dfc2c..995e57d589 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/method/configuration/ReactiveAuthorizationManagerMethodSecurityConfiguration.java +++ b/config/src/main/java/org/springframework/security/config/annotation/method/configuration/ReactiveAuthorizationManagerMethodSecurityConfiguration.java @@ -43,6 +43,7 @@ import org.springframework.security.authorization.method.PreAuthorizeReactiveAut import org.springframework.security.authorization.method.PreFilterAuthorizationReactiveMethodInterceptor; import org.springframework.security.authorization.method.PrePostTemplateDefaults; import org.springframework.security.config.core.GrantedAuthorityDefaults; +import org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults; /** * Configuration for a {@link ReactiveAuthenticationManager} based Method Security. @@ -108,6 +109,14 @@ final class ReactiveAuthorizationManagerMethodSecurityConfiguration this.postFilterMethodInterceptor.setTemplateDefaults(templateDefaults); } + @Autowired(required = false) + void setTemplateDefaults(AnnotationTemplateExpressionDefaults templateDefaults) { + this.preFilterMethodInterceptor.setTemplateDefaults(templateDefaults); + this.preAuthorizeAuthorizationManager.setTemplateDefaults(templateDefaults); + this.postAuthorizeAuthorizationManager.setTemplateDefaults(templateDefaults); + this.postFilterMethodInterceptor.setTemplateDefaults(templateDefaults); + } + @Autowired(required = false) void setObservationRegistry(ObservationRegistry registry) { if (registry.isNoop()) { diff --git a/core/src/main/java/org/springframework/security/authorization/method/PostAuthorizeReactiveAuthorizationManager.java b/core/src/main/java/org/springframework/security/authorization/method/PostAuthorizeReactiveAuthorizationManager.java index 475a7a2604..2b09d0fd61 100644 --- a/core/src/main/java/org/springframework/security/authorization/method/PostAuthorizeReactiveAuthorizationManager.java +++ b/core/src/main/java/org/springframework/security/authorization/method/PostAuthorizeReactiveAuthorizationManager.java @@ -27,6 +27,7 @@ import org.springframework.security.authorization.AuthorizationDecision; import org.springframework.security.authorization.AuthorizationResult; import org.springframework.security.authorization.ReactiveAuthorizationManager; import org.springframework.security.core.Authentication; +import org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults; import org.springframework.util.Assert; /** @@ -63,6 +64,18 @@ public final class PostAuthorizeReactiveAuthorizationManager this.registry.setTemplateDefaults(defaults); } + /** + * Configure pre/post-authorization template resolution + *

+ * By default, this value is null, which indicates that templates should + * not be resolved. + * @param defaults - whether to resolve pre/post-authorization templates parameters + * @since 6.4 + */ + public void setTemplateDefaults(AnnotationTemplateExpressionDefaults defaults) { + this.registry.setTemplateDefaults(defaults); + } + public void setApplicationContext(ApplicationContext context) { this.registry.setApplicationContext(context); } diff --git a/core/src/main/java/org/springframework/security/authorization/method/PostFilterAuthorizationReactiveMethodInterceptor.java b/core/src/main/java/org/springframework/security/authorization/method/PostFilterAuthorizationReactiveMethodInterceptor.java index 072bb5b75d..78079be150 100644 --- a/core/src/main/java/org/springframework/security/authorization/method/PostFilterAuthorizationReactiveMethodInterceptor.java +++ b/core/src/main/java/org/springframework/security/authorization/method/PostFilterAuthorizationReactiveMethodInterceptor.java @@ -33,6 +33,7 @@ import org.springframework.security.access.expression.method.DefaultMethodSecuri import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; import org.springframework.security.access.expression.method.MethodSecurityExpressionOperations; import org.springframework.security.access.prepost.PostFilter; +import org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults; import org.springframework.util.Assert; /** @@ -78,6 +79,18 @@ public final class PostFilterAuthorizationReactiveMethodInterceptor implements A this.registry.setTemplateDefaults(defaults); } + /** + * Configure pre/post-authorization template resolution + *

+ * By default, this value is null, which indicates that templates should + * not be resolved. + * @param defaults - whether to resolve pre/post-authorization templates parameters + * @since 6.4 + */ + public void setTemplateDefaults(AnnotationTemplateExpressionDefaults defaults) { + this.registry.setTemplateDefaults(defaults); + } + /** * Filters the returned object from the {@link MethodInvocation} by evaluating an * expression from the {@link PostFilter} annotation. diff --git a/core/src/main/java/org/springframework/security/authorization/method/PreAuthorizeReactiveAuthorizationManager.java b/core/src/main/java/org/springframework/security/authorization/method/PreAuthorizeReactiveAuthorizationManager.java index cc768d861d..86829e6020 100644 --- a/core/src/main/java/org/springframework/security/authorization/method/PreAuthorizeReactiveAuthorizationManager.java +++ b/core/src/main/java/org/springframework/security/authorization/method/PreAuthorizeReactiveAuthorizationManager.java @@ -27,6 +27,7 @@ import org.springframework.security.authorization.AuthorizationDecision; import org.springframework.security.authorization.AuthorizationResult; import org.springframework.security.authorization.ReactiveAuthorizationManager; import org.springframework.security.core.Authentication; +import org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults; import org.springframework.util.Assert; /** @@ -63,6 +64,18 @@ public final class PreAuthorizeReactiveAuthorizationManager this.registry.setTemplateDefaults(defaults); } + /** + * Configure pre/post-authorization template resolution + *

+ * By default, this value is null, which indicates that templates should + * not be resolved. + * @param defaults - whether to resolve pre/post-authorization templates parameters + * @since 6.4 + */ + public void setTemplateDefaults(AnnotationTemplateExpressionDefaults defaults) { + this.registry.setTemplateDefaults(defaults); + } + public void setApplicationContext(ApplicationContext context) { this.registry.setApplicationContext(context); } diff --git a/core/src/main/java/org/springframework/security/authorization/method/PreFilterAuthorizationReactiveMethodInterceptor.java b/core/src/main/java/org/springframework/security/authorization/method/PreFilterAuthorizationReactiveMethodInterceptor.java index 19775eb126..2b9f9a4894 100644 --- a/core/src/main/java/org/springframework/security/authorization/method/PreFilterAuthorizationReactiveMethodInterceptor.java +++ b/core/src/main/java/org/springframework/security/authorization/method/PreFilterAuthorizationReactiveMethodInterceptor.java @@ -36,6 +36,7 @@ import org.springframework.security.access.expression.method.DefaultMethodSecuri import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; import org.springframework.security.access.expression.method.MethodSecurityExpressionOperations; import org.springframework.security.access.prepost.PreFilter; +import org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults; import org.springframework.security.core.parameters.DefaultSecurityParameterNameDiscoverer; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -81,6 +82,18 @@ public final class PreFilterAuthorizationReactiveMethodInterceptor implements Au this.registry.setTemplateDefaults(defaults); } + /** + * Configure pre/post-authorization template resolution + *

+ * By default, this value is null, which indicates that templates should + * not be resolved. + * @param defaults - whether to resolve pre/post-authorization templates parameters + * @since 6.4 + */ + public void setTemplateDefaults(AnnotationTemplateExpressionDefaults defaults) { + this.registry.setTemplateDefaults(defaults); + } + /** * Sets the {@link ParameterNameDiscoverer}. * @param parameterNameDiscoverer the {@link ParameterNameDiscoverer} to use