diff --git a/module/spring-boot-security/src/main/java/org/springframework/boot/security/autoconfigure/actuate/web/reactive/EndpointRequest.java b/module/spring-boot-security/src/main/java/org/springframework/boot/security/autoconfigure/actuate/web/reactive/EndpointRequest.java index e2e7b1dfa9c..ea69c5d8101 100644 --- a/module/spring-boot-security/src/main/java/org/springframework/boot/security/autoconfigure/actuate/web/reactive/EndpointRequest.java +++ b/module/spring-boot-security/src/main/java/org/springframework/boot/security/autoconfigure/actuate/web/reactive/EndpointRequest.java @@ -310,17 +310,17 @@ public final class EndpointRequest { public EndpointServerWebExchangeMatcher excluding(Class... endpoints) { List excludes = new ArrayList<>(this.excludes); excludes.addAll(Arrays.asList((Object[]) endpoints)); - return new EndpointServerWebExchangeMatcher(this.includes, excludes, this.includeLinks, null); + return new EndpointServerWebExchangeMatcher(this.includes, excludes, this.includeLinks, this.httpMethod); } public EndpointServerWebExchangeMatcher excluding(String... endpoints) { List excludes = new ArrayList<>(this.excludes); excludes.addAll(Arrays.asList((Object[]) endpoints)); - return new EndpointServerWebExchangeMatcher(this.includes, excludes, this.includeLinks, null); + return new EndpointServerWebExchangeMatcher(this.includes, excludes, this.includeLinks, this.httpMethod); } public EndpointServerWebExchangeMatcher excludingLinks() { - return new EndpointServerWebExchangeMatcher(this.includes, this.excludes, false, null); + return new EndpointServerWebExchangeMatcher(this.includes, this.excludes, false, this.httpMethod); } /** diff --git a/module/spring-boot-security/src/main/java/org/springframework/boot/security/autoconfigure/actuate/web/servlet/EndpointRequest.java b/module/spring-boot-security/src/main/java/org/springframework/boot/security/autoconfigure/actuate/web/servlet/EndpointRequest.java index 4642c0841ae..f36a7461108 100644 --- a/module/spring-boot-security/src/main/java/org/springframework/boot/security/autoconfigure/actuate/web/servlet/EndpointRequest.java +++ b/module/spring-boot-security/src/main/java/org/springframework/boot/security/autoconfigure/actuate/web/servlet/EndpointRequest.java @@ -318,17 +318,17 @@ public final class EndpointRequest { public EndpointRequestMatcher excluding(Class... endpoints) { List excludes = new ArrayList<>(this.excludes); excludes.addAll(Arrays.asList((Object[]) endpoints)); - return new EndpointRequestMatcher(this.includes, excludes, this.includeLinks, null); + return new EndpointRequestMatcher(this.includes, excludes, this.includeLinks, this.httpMethod); } public EndpointRequestMatcher excluding(String... endpoints) { List excludes = new ArrayList<>(this.excludes); excludes.addAll(Arrays.asList((Object[]) endpoints)); - return new EndpointRequestMatcher(this.includes, excludes, this.includeLinks, null); + return new EndpointRequestMatcher(this.includes, excludes, this.includeLinks, this.httpMethod); } public EndpointRequestMatcher excludingLinks() { - return new EndpointRequestMatcher(this.includes, this.excludes, false, null); + return new EndpointRequestMatcher(this.includes, this.excludes, false, this.httpMethod); } /** diff --git a/module/spring-boot-security/src/test/java/org/springframework/boot/security/autoconfigure/actuate/web/reactive/EndpointRequestTests.java b/module/spring-boot-security/src/test/java/org/springframework/boot/security/autoconfigure/actuate/web/reactive/EndpointRequestTests.java index 52621add7a7..28b4db4066a 100644 --- a/module/spring-boot-security/src/test/java/org/springframework/boot/security/autoconfigure/actuate/web/reactive/EndpointRequestTests.java +++ b/module/spring-boot-security/src/test/java/org/springframework/boot/security/autoconfigure/actuate/web/reactive/EndpointRequestTests.java @@ -236,6 +236,33 @@ class EndpointRequestTests { assertMatcher.matches("/bar/"); } + @Test + void toAnyEndpointWithHttpMethodExcludingShouldPreserveHttpMethod() { + ServerWebExchangeMatcher matcher = EndpointRequest.toAnyEndpoint() + .withHttpMethod(HttpMethod.POST) + .excluding(FooEndpoint.class) + .excluding("baz"); + List> endpoints = new ArrayList<>(); + endpoints.add(mockEndpoint(EndpointId.of("foo"), "foo")); + endpoints.add(mockEndpoint(EndpointId.of("bar"), "bar")); + endpoints.add(mockEndpoint(EndpointId.of("baz"), "baz")); + PathMappedEndpoints pathMappedEndpoints = new PathMappedEndpoints("/actuator", () -> endpoints); + assertMatcher(matcher, pathMappedEndpoints).matches(HttpMethod.POST, "/actuator/bar"); + assertMatcher(matcher, pathMappedEndpoints).doesNotMatch(HttpMethod.GET, "/actuator/bar"); + assertMatcher(matcher, pathMappedEndpoints).doesNotMatch("/actuator/foo"); + assertMatcher(matcher, pathMappedEndpoints).doesNotMatch("/actuator/baz"); + } + + @Test + void toAnyEndpointWithHttpMethodExcludingLinksShouldPreserveHttpMethod() { + ServerWebExchangeMatcher matcher = EndpointRequest.toAnyEndpoint() + .withHttpMethod(HttpMethod.POST) + .excludingLinks(); + assertMatcher(matcher).matches(HttpMethod.POST, "/actuator/foo"); + assertMatcher(matcher).doesNotMatch(HttpMethod.GET, "/actuator/foo"); + assertMatcher(matcher).doesNotMatch("/actuator"); + } + @Test void noEndpointPathsBeansShouldNeverMatch() { ServerWebExchangeMatcher matcher = EndpointRequest.toAnyEndpoint(); diff --git a/module/spring-boot-security/src/test/java/org/springframework/boot/security/autoconfigure/actuate/web/servlet/EndpointRequestTests.java b/module/spring-boot-security/src/test/java/org/springframework/boot/security/autoconfigure/actuate/web/servlet/EndpointRequestTests.java index 030c77eab05..b5787b4be95 100644 --- a/module/spring-boot-security/src/test/java/org/springframework/boot/security/autoconfigure/actuate/web/servlet/EndpointRequestTests.java +++ b/module/spring-boot-security/src/test/java/org/springframework/boot/security/autoconfigure/actuate/web/servlet/EndpointRequestTests.java @@ -223,6 +223,31 @@ class EndpointRequestTests { assertMatcher.matches("/bar"); } + @Test + void toAnyEndpointWithHttpMethodExcludingShouldPreserveHttpMethod() { + RequestMatcher matcher = EndpointRequest.toAnyEndpoint() + .withHttpMethod(HttpMethod.POST) + .excluding(FooEndpoint.class) + .excluding("baz"); + List> endpoints = new ArrayList<>(); + endpoints.add(mockEndpoint(EndpointId.of("foo"), "foo")); + endpoints.add(mockEndpoint(EndpointId.of("bar"), "bar")); + endpoints.add(mockEndpoint(EndpointId.of("baz"), "baz")); + PathMappedEndpoints pathMappedEndpoints = new PathMappedEndpoints("/actuator", () -> endpoints); + assertMatcher(matcher, pathMappedEndpoints).matches(HttpMethod.POST, "/actuator/bar"); + assertMatcher(matcher, pathMappedEndpoints).doesNotMatch(HttpMethod.GET, "/actuator/bar"); + assertMatcher(matcher, pathMappedEndpoints).doesNotMatch("/actuator/foo"); + assertMatcher(matcher, pathMappedEndpoints).doesNotMatch("/actuator/baz"); + } + + @Test + void toAnyEndpointWithHttpMethodExcludingLinksShouldPreserveHttpMethod() { + RequestMatcher matcher = EndpointRequest.toAnyEndpoint().withHttpMethod(HttpMethod.POST).excludingLinks(); + assertMatcher(matcher).matches(HttpMethod.POST, "/actuator/foo"); + assertMatcher(matcher).doesNotMatch(HttpMethod.GET, "/actuator/foo"); + assertMatcher(matcher).doesNotMatch("/actuator"); + } + @Test void endpointRequestMatcherShouldUseCustomRequestMatcherProvider() { RequestMatcher matcher = EndpointRequest.toAnyEndpoint();