diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java index 1ab763653f3..295f3d76f51 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java @@ -185,8 +185,14 @@ public final class EndpointRequest { protected final boolean hasWebServerNamespace(ApplicationContext applicationContext, WebServerNamespace webServerNamespace) { return WebServerApplicationContext.hasServerNamespace(applicationContext, webServerNamespace.getValue()) - || (webServerNamespace.equals(WebServerNamespace.SERVER) - && !(applicationContext instanceof WebServerApplicationContext)); + || hasImplicitServerNamespace(applicationContext, webServerNamespace); + } + + private boolean hasImplicitServerNamespace(ApplicationContext applicationContext, + WebServerNamespace webServerNamespace) { + return WebServerNamespace.SERVER.equals(webServerNamespace) + && WebServerApplicationContext.getServerNamespace(applicationContext) == null + && applicationContext.getParent() == null; } @Override diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequestTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequestTests.java index ebb958bf385..3c112666eff 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequestTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequestTests.java @@ -349,9 +349,12 @@ class EndpointRequestTests { } private RequestMatcherAssert assertMatcher(RequestMatcher matcher, PathMappedEndpoints pathMappedEndpoints, - RequestMatcherProvider matcherProvider, WebServerNamespace webServerNamespace) { - StaticWebApplicationContext context = (webServerNamespace != null) - ? new NamedStaticWebApplicationContext(webServerNamespace) : new StaticWebApplicationContext(); + RequestMatcherProvider matcherProvider, WebServerNamespace namespace) { + StaticWebApplicationContext context = new StaticWebApplicationContext(); + if (namespace != null && !WebServerNamespace.SERVER.equals(namespace)) { + NamedStaticWebApplicationContext parentContext = new NamedStaticWebApplicationContext(namespace); + context.setParent(parentContext); + } context.registerBean(WebEndpointProperties.class); if (pathMappedEndpoints != null) { context.registerBean(PathMappedEndpoints.class, () -> pathMappedEndpoints); @@ -382,7 +385,7 @@ class EndpointRequestTests { @Override public String getServerNamespace() { - return this.webServerNamespace.getValue(); + return (this.webServerNamespace != null) ? this.webServerNamespace.getValue() : null; } }