Use AnnotationTemplateExpressionDefaults in Reactive

Issue gh-15097
This commit is contained in:
Josh Cummings 2024-09-12 11:51:35 -06:00
parent 86f64e7e86
commit 6f5e103dec
5 changed files with 61 additions and 0 deletions

View File

@ -43,6 +43,7 @@ import org.springframework.security.authorization.method.PreAuthorizeReactiveAut
import org.springframework.security.authorization.method.PreFilterAuthorizationReactiveMethodInterceptor; import org.springframework.security.authorization.method.PreFilterAuthorizationReactiveMethodInterceptor;
import org.springframework.security.authorization.method.PrePostTemplateDefaults; import org.springframework.security.authorization.method.PrePostTemplateDefaults;
import org.springframework.security.config.core.GrantedAuthorityDefaults; import org.springframework.security.config.core.GrantedAuthorityDefaults;
import org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults;
/** /**
* Configuration for a {@link ReactiveAuthenticationManager} based Method Security. * Configuration for a {@link ReactiveAuthenticationManager} based Method Security.
@ -108,6 +109,14 @@ final class ReactiveAuthorizationManagerMethodSecurityConfiguration
this.postFilterMethodInterceptor.setTemplateDefaults(templateDefaults); 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) @Autowired(required = false)
void setObservationRegistry(ObservationRegistry registry) { void setObservationRegistry(ObservationRegistry registry) {
if (registry.isNoop()) { if (registry.isNoop()) {

View File

@ -27,6 +27,7 @@ import org.springframework.security.authorization.AuthorizationDecision;
import org.springframework.security.authorization.AuthorizationResult; import org.springframework.security.authorization.AuthorizationResult;
import org.springframework.security.authorization.ReactiveAuthorizationManager; import org.springframework.security.authorization.ReactiveAuthorizationManager;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
@ -63,6 +64,18 @@ public final class PostAuthorizeReactiveAuthorizationManager
this.registry.setTemplateDefaults(defaults); this.registry.setTemplateDefaults(defaults);
} }
/**
* Configure pre/post-authorization template resolution
* <p>
* By default, this value is <code>null</code>, 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) { public void setApplicationContext(ApplicationContext context) {
this.registry.setApplicationContext(context); this.registry.setApplicationContext(context);
} }

View File

@ -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.MethodSecurityExpressionHandler;
import org.springframework.security.access.expression.method.MethodSecurityExpressionOperations; import org.springframework.security.access.expression.method.MethodSecurityExpressionOperations;
import org.springframework.security.access.prepost.PostFilter; import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
@ -78,6 +79,18 @@ public final class PostFilterAuthorizationReactiveMethodInterceptor implements A
this.registry.setTemplateDefaults(defaults); this.registry.setTemplateDefaults(defaults);
} }
/**
* Configure pre/post-authorization template resolution
* <p>
* By default, this value is <code>null</code>, 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 * Filters the returned object from the {@link MethodInvocation} by evaluating an
* expression from the {@link PostFilter} annotation. * expression from the {@link PostFilter} annotation.

View File

@ -27,6 +27,7 @@ import org.springframework.security.authorization.AuthorizationDecision;
import org.springframework.security.authorization.AuthorizationResult; import org.springframework.security.authorization.AuthorizationResult;
import org.springframework.security.authorization.ReactiveAuthorizationManager; import org.springframework.security.authorization.ReactiveAuthorizationManager;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
@ -63,6 +64,18 @@ public final class PreAuthorizeReactiveAuthorizationManager
this.registry.setTemplateDefaults(defaults); this.registry.setTemplateDefaults(defaults);
} }
/**
* Configure pre/post-authorization template resolution
* <p>
* By default, this value is <code>null</code>, 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) { public void setApplicationContext(ApplicationContext context) {
this.registry.setApplicationContext(context); this.registry.setApplicationContext(context);
} }

View File

@ -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.MethodSecurityExpressionHandler;
import org.springframework.security.access.expression.method.MethodSecurityExpressionOperations; import org.springframework.security.access.expression.method.MethodSecurityExpressionOperations;
import org.springframework.security.access.prepost.PreFilter; import org.springframework.security.access.prepost.PreFilter;
import org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults;
import org.springframework.security.core.parameters.DefaultSecurityParameterNameDiscoverer; import org.springframework.security.core.parameters.DefaultSecurityParameterNameDiscoverer;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -81,6 +82,18 @@ public final class PreFilterAuthorizationReactiveMethodInterceptor implements Au
this.registry.setTemplateDefaults(defaults); this.registry.setTemplateDefaults(defaults);
} }
/**
* Configure pre/post-authorization template resolution
* <p>
* By default, this value is <code>null</code>, 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}. * Sets the {@link ParameterNameDiscoverer}.
* @param parameterNameDiscoverer the {@link ParameterNameDiscoverer} to use * @param parameterNameDiscoverer the {@link ParameterNameDiscoverer} to use