|
@@ -191,9 +191,11 @@ import org.springframework.web.cors.reactive.CorsConfigurationSource;
|
|
|
import org.springframework.web.cors.reactive.CorsProcessor;
|
|
|
import org.springframework.web.cors.reactive.CorsWebFilter;
|
|
|
import org.springframework.web.cors.reactive.DefaultCorsProcessor;
|
|
|
+import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;
|
|
|
import org.springframework.web.server.ServerWebExchange;
|
|
|
import org.springframework.web.server.WebFilter;
|
|
|
import org.springframework.web.server.WebFilterChain;
|
|
|
+import org.springframework.web.util.pattern.PathPatternParser;
|
|
|
|
|
|
/**
|
|
|
* A {@link ServerHttpSecurity} is similar to Spring Security's {@code HttpSecurity} but
|
|
@@ -1661,6 +1663,18 @@ public class ServerHttpSecurity {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private <T> T getBeanOrNull(String beanName, Class<T> requiredClass) {
|
|
|
+ if (this.context == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return this.context.getBean(beanName, requiredClass);
|
|
|
+ }
|
|
|
+ catch (Exception ex) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private <T> String[] getBeanNamesForTypeOrEmpty(Class<T> beanClass) {
|
|
|
if (this.context == null) {
|
|
|
return new String[0];
|
|
@@ -1681,6 +1695,8 @@ public class ServerHttpSecurity {
|
|
|
*/
|
|
|
public class AuthorizeExchangeSpec extends AbstractServerWebExchangeMatcherRegistry<AuthorizeExchangeSpec.Access> {
|
|
|
|
|
|
+ private static final String REQUEST_MAPPING_HANDLER_MAPPING_BEAN_NAME = "requestMappingHandlerMapping";
|
|
|
+
|
|
|
private DelegatingReactiveAuthorizationManager.Builder managerBldr = DelegatingReactiveAuthorizationManager
|
|
|
.builder();
|
|
|
|
|
@@ -1688,6 +1704,8 @@ public class ServerHttpSecurity {
|
|
|
|
|
|
private boolean anyExchangeRegistered;
|
|
|
|
|
|
+ private PathPatternParser pathPatternParser;
|
|
|
+
|
|
|
/**
|
|
|
* Allows method chaining to continue configuring the {@link ServerHttpSecurity}
|
|
|
* @return the {@link ServerHttpSecurity} to continue configuring
|
|
@@ -1710,6 +1728,22 @@ public class ServerHttpSecurity {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ protected PathPatternParser getPathPatternParser() {
|
|
|
+ if (this.pathPatternParser != null) {
|
|
|
+ return this.pathPatternParser;
|
|
|
+ }
|
|
|
+ RequestMappingHandlerMapping requestMappingHandlerMapping = getBeanOrNull(
|
|
|
+ REQUEST_MAPPING_HANDLER_MAPPING_BEAN_NAME, RequestMappingHandlerMapping.class);
|
|
|
+ if (requestMappingHandlerMapping != null) {
|
|
|
+ this.pathPatternParser = requestMappingHandlerMapping.getPathPatternParser();
|
|
|
+ }
|
|
|
+ if (this.pathPatternParser == null) {
|
|
|
+ this.pathPatternParser = PathPatternParser.defaultInstance;
|
|
|
+ }
|
|
|
+ return this.pathPatternParser;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected Access registerMatcher(ServerWebExchangeMatcher matcher) {
|
|
|
Assert.state(!this.anyExchangeRegistered, () -> "Cannot register " + matcher
|