Skip to content

Commit 3603cb4

Browse files
committed
Fix matching against context with implicit server namespace
Closes gh-44188
1 parent fafcfb4 commit 3603cb4

File tree

2 files changed

+17
-8
lines changed
  • spring-boot-project/spring-boot-actuator-autoconfigure/src

2 files changed

+17
-8
lines changed

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

+9-3
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.
@@ -184,8 +184,14 @@ protected boolean ignoreApplicationContext(WebApplicationContext applicationCont
184184
protected final boolean hasWebServerNamespace(ApplicationContext applicationContext,
185185
WebServerNamespace webServerNamespace) {
186186
return WebServerApplicationContext.hasServerNamespace(applicationContext, webServerNamespace.getValue())
187-
|| (webServerNamespace.equals(WebServerNamespace.SERVER)
188-
&& !(applicationContext instanceof WebServerApplicationContext));
187+
|| hasImplicitServerNamespace(applicationContext, webServerNamespace);
188+
}
189+
190+
private boolean hasImplicitServerNamespace(ApplicationContext applicationContext,
191+
WebServerNamespace webServerNamespace) {
192+
return WebServerNamespace.SERVER.equals(webServerNamespace)
193+
&& WebServerApplicationContext.getServerNamespace(applicationContext) == null
194+
&& applicationContext.getParent() == null;
189195
}
190196

191197
@Override

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

+8-5
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.
@@ -340,9 +340,12 @@ private RequestMatcherAssert assertMatcher(RequestMatcher matcher, PathMappedEnd
340340
}
341341

342342
private RequestMatcherAssert assertMatcher(RequestMatcher matcher, PathMappedEndpoints pathMappedEndpoints,
343-
RequestMatcherProvider matcherProvider, WebServerNamespace webServerNamespace) {
344-
StaticWebApplicationContext context = (webServerNamespace != null)
345-
? new NamedStaticWebApplicationContext(webServerNamespace) : new StaticWebApplicationContext();
343+
RequestMatcherProvider matcherProvider, WebServerNamespace namespace) {
344+
StaticWebApplicationContext context = new StaticWebApplicationContext();
345+
if (namespace != null && !WebServerNamespace.SERVER.equals(namespace)) {
346+
NamedStaticWebApplicationContext parentContext = new NamedStaticWebApplicationContext(namespace);
347+
context.setParent(parentContext);
348+
}
346349
context.registerBean(WebEndpointProperties.class);
347350
if (pathMappedEndpoints != null) {
348351
context.registerBean(PathMappedEndpoints.class, () -> pathMappedEndpoints);
@@ -373,7 +376,7 @@ public WebServer getWebServer() {
373376

374377
@Override
375378
public String getServerNamespace() {
376-
return this.webServerNamespace.getValue();
379+
return (this.webServerNamespace != null) ? this.webServerNamespace.getValue() : null;
377380
}
378381

379382
}

0 commit comments

Comments
 (0)