Skip to content

Commit cdae79d

Browse files
committed
Cache management port type in EndpointRequestMatcher
Closes gh-20329
1 parent 421fe77 commit cdae79d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ public static final class EndpointServerWebExchangeMatcher
130130

131131
private volatile ServerWebExchangeMatcher delegate;
132132

133+
private static ManagementPortType managementPortType;
134+
133135
private EndpointServerWebExchangeMatcher(boolean includeLinks) {
134136
this(Collections.emptyList(), Collections.emptyList(), includeLinks);
135137
}
@@ -231,7 +233,10 @@ protected Mono<MatchResult> matches(ServerWebExchange exchange, Supplier<PathMap
231233

232234
static boolean isManagementContext(ServerWebExchange exchange) {
233235
ApplicationContext applicationContext = exchange.getApplicationContext();
234-
if (ManagementPortType.get(applicationContext.getEnvironment()) == ManagementPortType.DIFFERENT) {
236+
if (managementPortType == null) {
237+
managementPortType = ManagementPortType.get(applicationContext.getEnvironment());
238+
}
239+
if (managementPortType == ManagementPortType.DIFFERENT) {
235240
if (applicationContext.getParent() == null) {
236241
return false;
237242
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,18 @@ private abstract static class AbstractRequestMatcher
124124

125125
private volatile RequestMatcher delegate;
126126

127+
private static ManagementPortType managementPortType;
128+
127129
AbstractRequestMatcher() {
128130
super(WebApplicationContext.class);
129131
}
130132

131133
@Override
132134
protected boolean ignoreApplicationContext(WebApplicationContext applicationContext) {
133-
ManagementPortType type = ManagementPortType.get(applicationContext.getEnvironment());
134-
return type == ManagementPortType.DIFFERENT
135+
if (managementPortType == null) {
136+
managementPortType = ManagementPortType.get(applicationContext.getEnvironment());
137+
}
138+
return managementPortType == ManagementPortType.DIFFERENT
135139
&& !WebServerApplicationContext.hasServerNamespace(applicationContext, "management");
136140
}
137141

0 commit comments

Comments
 (0)