Skip to content

Commit c86ac9e

Browse files
committed
Merge branch '3.4.x'
Closes gh-44191
2 parents 4212ee7 + 1c0253b commit c86ac9e

File tree

2 files changed

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

2 files changed

+35
-8
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -215,11 +216,15 @@ protected boolean ignoreApplicationContext(ApplicationContext applicationContext
215216

216217
protected final boolean hasWebServerNamespace(ApplicationContext applicationContext,
217218
WebServerNamespace webServerNamespace) {
218-
if (applicationContext.getParent() == null) {
219-
return WebServerNamespace.SERVER.equals(webServerNamespace);
220-
}
221-
String parentContextId = applicationContext.getParent().getId();
222-
return applicationContext.getId().equals(parentContextId + ":" + webServerNamespace);
219+
return WebServerApplicationContext.hasServerNamespace(applicationContext, webServerNamespace.getValue())
220+
|| hasImplicitServerNamespace(applicationContext, webServerNamespace);
221+
}
222+
223+
private boolean hasImplicitServerNamespace(ApplicationContext applicationContext,
224+
WebServerNamespace webServerNamespace) {
225+
return WebServerNamespace.SERVER.equals(webServerNamespace)
226+
&& WebServerApplicationContext.getServerNamespace(applicationContext) == null
227+
&& applicationContext.getParent() == null;
223228
}
224229

225230
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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@
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.HttpMethod;
3739
import org.springframework.http.server.reactive.ServerHttpRequest;
3840
import org.springframework.http.server.reactive.ServerHttpResponse;
3941
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
4042
import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
4143
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
44+
import org.springframework.web.context.support.StaticWebApplicationContext;
4245
import org.springframework.web.server.ServerWebExchange;
4346
import org.springframework.web.server.WebHandler;
4447
import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
@@ -324,10 +327,8 @@ private RequestMatcherAssert assertMatcher(ServerWebExchangeMatcher matcher,
324327
PathMappedEndpoints pathMappedEndpoints, WebServerNamespace namespace) {
325328
StaticApplicationContext context = new StaticApplicationContext();
326329
if (namespace != null && !WebServerNamespace.SERVER.equals(namespace)) {
327-
StaticApplicationContext parentContext = new StaticApplicationContext();
328-
parentContext.setId("app");
330+
NamedStaticWebApplicationContext parentContext = new NamedStaticWebApplicationContext(namespace);
329331
context.setParent(parentContext);
330-
context.setId(parentContext.getId() + ":" + namespace);
331332
}
332333
context.registerBean(WebEndpointProperties.class);
333334
if (pathMappedEndpoints != null) {
@@ -360,6 +361,27 @@ private TestEndpoint mockEndpoint(EndpointId id, String rootPath, WebServerNames
360361
return endpoint;
361362
}
362363

364+
static class NamedStaticWebApplicationContext extends StaticWebApplicationContext
365+
implements WebServerApplicationContext {
366+
367+
private final WebServerNamespace webServerNamespace;
368+
369+
NamedStaticWebApplicationContext(WebServerNamespace webServerNamespace) {
370+
this.webServerNamespace = webServerNamespace;
371+
}
372+
373+
@Override
374+
public WebServer getWebServer() {
375+
return null;
376+
}
377+
378+
@Override
379+
public String getServerNamespace() {
380+
return (this.webServerNamespace != null) ? this.webServerNamespace.getValue() : null;
381+
}
382+
383+
}
384+
363385
static class RequestMatcherAssert implements AssertDelegateTarget {
364386

365387
private final StaticApplicationContext context;

0 commit comments

Comments
 (0)