Merge branch '3.4.x'

Closes gh-44191
This commit is contained in:
Andy Wilkinson 2025-02-10 09:37:21 +00:00
commit c86ac9ecaf
2 changed files with 35 additions and 8 deletions

View File

@ -37,6 +37,7 @@ import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints; import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
import org.springframework.boot.actuate.endpoint.web.WebServerNamespace; import org.springframework.boot.actuate.endpoint.web.WebServerNamespace;
import org.springframework.boot.security.reactive.ApplicationContextServerWebExchangeMatcher; import org.springframework.boot.security.reactive.ApplicationContextServerWebExchangeMatcher;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.annotation.MergedAnnotations;
@ -215,11 +216,15 @@ public final class EndpointRequest {
protected final boolean hasWebServerNamespace(ApplicationContext applicationContext, protected final boolean hasWebServerNamespace(ApplicationContext applicationContext,
WebServerNamespace webServerNamespace) { WebServerNamespace webServerNamespace) {
if (applicationContext.getParent() == null) { return WebServerApplicationContext.hasServerNamespace(applicationContext, webServerNamespace.getValue())
return WebServerNamespace.SERVER.equals(webServerNamespace); || hasImplicitServerNamespace(applicationContext, webServerNamespace);
} }
String parentContextId = applicationContext.getParent().getId();
return applicationContext.getId().equals(parentContextId + ":" + webServerNamespace); private boolean hasImplicitServerNamespace(ApplicationContext applicationContext,
WebServerNamespace webServerNamespace) {
return WebServerNamespace.SERVER.equals(webServerNamespace)
&& WebServerApplicationContext.getServerNamespace(applicationContext) == null
&& applicationContext.getParent() == null;
} }
protected final String toString(List<Object> endpoints, String emptyValue) { protected final String toString(List<Object> endpoints, String emptyValue) {

View File

@ -32,6 +32,8 @@ import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoint; import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoint;
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints; import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
import org.springframework.boot.actuate.endpoint.web.WebServerNamespace; import org.springframework.boot.actuate.endpoint.web.WebServerNamespace;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.boot.web.server.WebServer;
import org.springframework.context.support.StaticApplicationContext; import org.springframework.context.support.StaticApplicationContext;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpRequest;
@ -39,6 +41,7 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.http.server.reactive.MockServerHttpResponse; import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher; import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebHandler; import org.springframework.web.server.WebHandler;
import org.springframework.web.server.adapter.HttpWebHandlerAdapter; import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
@ -324,10 +327,8 @@ class EndpointRequestTests {
PathMappedEndpoints pathMappedEndpoints, WebServerNamespace namespace) { PathMappedEndpoints pathMappedEndpoints, WebServerNamespace namespace) {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
if (namespace != null && !WebServerNamespace.SERVER.equals(namespace)) { if (namespace != null && !WebServerNamespace.SERVER.equals(namespace)) {
StaticApplicationContext parentContext = new StaticApplicationContext(); NamedStaticWebApplicationContext parentContext = new NamedStaticWebApplicationContext(namespace);
parentContext.setId("app");
context.setParent(parentContext); context.setParent(parentContext);
context.setId(parentContext.getId() + ":" + namespace);
} }
context.registerBean(WebEndpointProperties.class); context.registerBean(WebEndpointProperties.class);
if (pathMappedEndpoints != null) { if (pathMappedEndpoints != null) {
@ -360,6 +361,27 @@ class EndpointRequestTests {
return endpoint; return endpoint;
} }
static class NamedStaticWebApplicationContext extends StaticWebApplicationContext
implements WebServerApplicationContext {
private final WebServerNamespace webServerNamespace;
NamedStaticWebApplicationContext(WebServerNamespace webServerNamespace) {
this.webServerNamespace = webServerNamespace;
}
@Override
public WebServer getWebServer() {
return null;
}
@Override
public String getServerNamespace() {
return (this.webServerNamespace != null) ? this.webServerNamespace.getValue() : null;
}
}
static class RequestMatcherAssert implements AssertDelegateTarget { static class RequestMatcherAssert implements AssertDelegateTarget {
private final StaticApplicationContext context; private final StaticApplicationContext context;