WebFlux now uses ParsingPathMatcher
Fixes gh-4388
This commit is contained in:
@@ -22,10 +22,10 @@ import java.util.Map;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.PathMatcher;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.util.pattern.ParsingPathMatcher;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,9 @@ import reactor.core.publisher.Mono;
|
||||
* @since 5.0
|
||||
*/
|
||||
public final class PathMatcherServerWebExchangeMatcher implements ServerWebExchangeMatcher {
|
||||
private PathMatcher pathMatcher = new AntPathMatcher();
|
||||
private static final PathMatcher DEFAULT_PATH_MATCHER = new ParsingPathMatcher();
|
||||
|
||||
private PathMatcher pathMatcher = DEFAULT_PATH_MATCHER;
|
||||
|
||||
private final String pattern;
|
||||
private final HttpMethod method;
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class ServerWebExchangeMatchers {
|
||||
|
||||
public static ServerWebExchangeMatcher antMatchers(HttpMethod method, String... patterns) {
|
||||
public static ServerWebExchangeMatcher pathMatchers(HttpMethod method, String... patterns) {
|
||||
List<ServerWebExchangeMatcher> matchers = new ArrayList<>(patterns.length);
|
||||
for (String pattern : patterns) {
|
||||
matchers.add(new PathMatcherServerWebExchangeMatcher(pattern, method));
|
||||
@@ -38,8 +38,8 @@ public abstract class ServerWebExchangeMatchers {
|
||||
return new OrServerWebExchangeMatcher(matchers);
|
||||
}
|
||||
|
||||
public static ServerWebExchangeMatcher antMatchers(String... patterns) {
|
||||
return antMatchers(null, patterns);
|
||||
public static ServerWebExchangeMatcher pathMatchers(String... patterns) {
|
||||
return pathMatchers(null, patterns);
|
||||
}
|
||||
|
||||
public static ServerWebExchangeMatcher matchers(ServerWebExchangeMatcher... matchers) {
|
||||
|
||||
@@ -27,7 +27,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers.antMatchers;
|
||||
import static org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers.pathMatchers;
|
||||
import static org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers.anyExchange;
|
||||
|
||||
/**
|
||||
@@ -38,28 +38,28 @@ public class ServerWebExchangeMatchersTests {
|
||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
||||
|
||||
@Test
|
||||
public void antMatchersWhenSingleAndSamePatternThenMatches() throws Exception {
|
||||
assertThat(antMatchers("/").matches(exchange).block().isMatch()).isTrue();
|
||||
public void pathMatchersWhenSingleAndSamePatternThenMatches() throws Exception {
|
||||
assertThat(pathMatchers("/").matches(exchange).block().isMatch()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void antMatchersWhenSingleAndSamePatternAndMethodThenMatches() throws Exception {
|
||||
assertThat(antMatchers(HttpMethod.GET, "/").matches(exchange).block().isMatch()).isTrue();
|
||||
public void pathMatchersWhenSingleAndSamePatternAndMethodThenMatches() throws Exception {
|
||||
assertThat(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/").matches(exchange).block().isMatch()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void antMatchersWhenSingleAndSamePatternAndDiffMethodThenDoesNotMatch() throws Exception {
|
||||
assertThat(antMatchers(HttpMethod.POST, "/").matches(exchange).block().isMatch()).isFalse();
|
||||
public void pathMatchersWhenSingleAndSamePatternAndDiffMethodThenDoesNotMatch() throws Exception {
|
||||
assertThat(ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, "/").matches(exchange).block().isMatch()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void antMatchersWhenSingleAndDifferentPatternThenDoesNotMatch() throws Exception {
|
||||
assertThat(antMatchers("/foobar").matches(exchange).block().isMatch()).isFalse();
|
||||
public void pathMatchersWhenSingleAndDifferentPatternThenDoesNotMatch() throws Exception {
|
||||
assertThat(pathMatchers("/foobar").matches(exchange).block().isMatch()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void antMatchersWhenMultiThenMatches() throws Exception {
|
||||
assertThat(antMatchers("/foobar", "/").matches(exchange).block().isMatch()).isTrue();
|
||||
public void pathMatchersWhenMultiThenMatches() throws Exception {
|
||||
assertThat(pathMatchers("/foobar", "/").matches(exchange).block().isMatch()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,7 +74,7 @@ public class ServerWebExchangeMatchersTests {
|
||||
/**
|
||||
* If a LinkedMap is used and anyRequest equals anyRequest then the following is added:
|
||||
* anyRequest() -> authenticated()
|
||||
* antMatchers("/admin/**") -> hasRole("ADMIN")
|
||||
* pathMatchers("/admin/**") -> hasRole("ADMIN")
|
||||
* anyRequest() -> permitAll
|
||||
*
|
||||
* will result in the first entry being overridden
|
||||
|
||||
Reference in New Issue
Block a user