From cdae79dad9bbf995bf359b81d0856d36c3cf7565 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Wed, 26 Feb 2020 14:59:54 -0800 Subject: [PATCH] Cache management port type in EndpointRequestMatcher Closes gh-20329 --- .../autoconfigure/security/reactive/EndpointRequest.java | 7 ++++++- .../autoconfigure/security/servlet/EndpointRequest.java | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequest.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequest.java index 05ced303eb..de585dbb02 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequest.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequest.java @@ -130,6 +130,8 @@ public final class EndpointRequest { private volatile ServerWebExchangeMatcher delegate; + private static ManagementPortType managementPortType; + private EndpointServerWebExchangeMatcher(boolean includeLinks) { this(Collections.emptyList(), Collections.emptyList(), includeLinks); } @@ -231,7 +233,10 @@ public final class EndpointRequest { static boolean isManagementContext(ServerWebExchange exchange) { ApplicationContext applicationContext = exchange.getApplicationContext(); - if (ManagementPortType.get(applicationContext.getEnvironment()) == ManagementPortType.DIFFERENT) { + if (managementPortType == null) { + managementPortType = ManagementPortType.get(applicationContext.getEnvironment()); + } + if (managementPortType == ManagementPortType.DIFFERENT) { if (applicationContext.getParent() == null) { return false; } 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 f8f8e4729c..d169021212 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 @@ -124,14 +124,18 @@ public final class EndpointRequest { private volatile RequestMatcher delegate; + private static ManagementPortType managementPortType; + AbstractRequestMatcher() { super(WebApplicationContext.class); } @Override protected boolean ignoreApplicationContext(WebApplicationContext applicationContext) { - ManagementPortType type = ManagementPortType.get(applicationContext.getEnvironment()); - return type == ManagementPortType.DIFFERENT + if (managementPortType == null) { + managementPortType = ManagementPortType.get(applicationContext.getEnvironment()); + } + return managementPortType == ManagementPortType.DIFFERENT && !WebServerApplicationContext.hasServerNamespace(applicationContext, "management"); }