Skip to content

Commit 1c0253b

Browse files
committed
Align reactive EndpointRequest with servlet equivalent
Closes gh-44189
1 parent 3603cb4 commit 1c0253b

File tree

2 files changed

+36
-9
lines changed
  • spring-boot-project/spring-boot-actuator-autoconfigure/src

2 files changed

+36
-9
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequest.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@
3737
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
3838
import org.springframework.boot.actuate.endpoint.web.WebServerNamespace;
3939
import org.springframework.boot.security.reactive.ApplicationContextServerWebExchangeMatcher;
40+
import org.springframework.boot.web.context.WebServerApplicationContext;
4041
import org.springframework.context.ApplicationContext;
4142
import org.springframework.core.annotation.MergedAnnotation;
4243
import org.springframework.core.annotation.MergedAnnotations;
@@ -211,11 +212,15 @@ protected boolean ignoreApplicationContext(ApplicationContext applicationContext
211212

212213
protected final boolean hasWebServerNamespace(ApplicationContext applicationContext,
213214
WebServerNamespace webServerNamespace) {
214-
if (applicationContext.getParent() == null) {
215-
return WebServerNamespace.SERVER.equals(webServerNamespace);
216-
}
217-
String parentContextId = applicationContext.getParent().getId();
218-
return applicationContext.getId().equals(parentContextId + ":" + webServerNamespace);
215+
return WebServerApplicationContext.hasServerNamespace(applicationContext, webServerNamespace.getValue())
216+
|| hasImplicitServerNamespace(applicationContext, webServerNamespace);
217+
}
218+
219+
private boolean hasImplicitServerNamespace(ApplicationContext applicationContext,
220+
WebServerNamespace webServerNamespace) {
221+
return WebServerNamespace.SERVER.equals(webServerNamespace)
222+
&& WebServerApplicationContext.getServerNamespace(applicationContext) == null
223+
&& applicationContext.getParent() == null;
219224
}
220225

221226
protected final String toString(List<Object> endpoints, String emptyValue) {

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequestTests.java

+25-3
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@
3232
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoint;
3333
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
3434
import org.springframework.boot.actuate.endpoint.web.WebServerNamespace;
35+
import org.springframework.boot.web.context.WebServerApplicationContext;
36+
import org.springframework.boot.web.server.WebServer;
3537
import org.springframework.context.support.StaticApplicationContext;
3638
import org.springframework.http.server.reactive.ServerHttpRequest;
3739
import org.springframework.http.server.reactive.ServerHttpResponse;
3840
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
3941
import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
4042
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
43+
import org.springframework.web.context.support.StaticWebApplicationContext;
4144
import org.springframework.web.server.ServerWebExchange;
4245
import org.springframework.web.server.WebHandler;
4346
import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
@@ -315,10 +318,8 @@ private RequestMatcherAssert assertMatcher(ServerWebExchangeMatcher matcher,
315318
PathMappedEndpoints pathMappedEndpoints, WebServerNamespace namespace) {
316319
StaticApplicationContext context = new StaticApplicationContext();
317320
if (namespace != null && !WebServerNamespace.SERVER.equals(namespace)) {
318-
StaticApplicationContext parentContext = new StaticApplicationContext();
319-
parentContext.setId("app");
321+
NamedStaticWebApplicationContext parentContext = new NamedStaticWebApplicationContext(namespace);
320322
context.setParent(parentContext);
321-
context.setId(parentContext.getId() + ":" + namespace);
322323
}
323324
context.registerBean(WebEndpointProperties.class);
324325
if (pathMappedEndpoints != null) {
@@ -351,6 +352,27 @@ private TestEndpoint mockEndpoint(EndpointId id, String rootPath, WebServerNames
351352
return endpoint;
352353
}
353354

355+
static class NamedStaticWebApplicationContext extends StaticWebApplicationContext
356+
implements WebServerApplicationContext {
357+
358+
private final WebServerNamespace webServerNamespace;
359+
360+
NamedStaticWebApplicationContext(WebServerNamespace webServerNamespace) {
361+
this.webServerNamespace = webServerNamespace;
362+
}
363+
364+
@Override
365+
public WebServer getWebServer() {
366+
return null;
367+
}
368+
369+
@Override
370+
public String getServerNamespace() {
371+
return (this.webServerNamespace != null) ? this.webServerNamespace.getValue() : null;
372+
}
373+
374+
}
375+
354376
static class RequestMatcherAssert implements AssertDelegateTarget {
355377

356378
private final StaticApplicationContext context;

0 commit comments

Comments
 (0)