Merge branch '2.1.x'
This commit is contained in:
@@ -31,10 +31,12 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
|
||||
import org.springframework.boot.actuate.endpoint.EndpointId;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
|
||||
import org.springframework.boot.security.reactive.ApplicationContextServerWebExchangeMatcher;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.security.web.server.util.matcher.OrServerWebExchangeMatcher;
|
||||
import org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher;
|
||||
@@ -239,9 +241,28 @@ public final class EndpointRequest {
|
||||
@Override
|
||||
protected Mono<MatchResult> matches(ServerWebExchange exchange,
|
||||
Supplier<PathMappedEndpoints> context) {
|
||||
if (!isManagementContext(exchange)) {
|
||||
return MatchResult.notMatch();
|
||||
}
|
||||
return this.delegate.matches(exchange);
|
||||
}
|
||||
|
||||
static boolean isManagementContext(ServerWebExchange exchange) {
|
||||
ApplicationContext applicationContext = exchange.getApplicationContext();
|
||||
if (ManagementPortType.get(applicationContext
|
||||
.getEnvironment()) == ManagementPortType.DIFFERENT) {
|
||||
if (applicationContext.getParent() == null) {
|
||||
return false;
|
||||
}
|
||||
String managementContextId = applicationContext.getParent().getId()
|
||||
+ ":management";
|
||||
if (!managementContextId.equals(applicationContext.getId())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,6 +294,9 @@ public final class EndpointRequest {
|
||||
@Override
|
||||
protected Mono<MatchResult> matches(ServerWebExchange exchange,
|
||||
Supplier<WebEndpointProperties> context) {
|
||||
if (!EndpointServerWebExchangeMatcher.isManagementContext(exchange)) {
|
||||
return MatchResult.notMatch();
|
||||
}
|
||||
return this.delegate.matches(exchange);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
|
||||
import org.springframework.boot.actuate.endpoint.EndpointId;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
|
||||
@@ -43,6 +44,7 @@ import org.springframework.security.web.util.matcher.RequestMatcher;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
/**
|
||||
* Factory that can be used to create a {@link RequestMatcher} for actuator endpoint
|
||||
@@ -133,6 +135,19 @@ public final class EndpointRequest {
|
||||
@Override
|
||||
protected final boolean matches(HttpServletRequest request,
|
||||
Supplier<WebApplicationContext> context) {
|
||||
WebApplicationContext applicationContext = WebApplicationContextUtils
|
||||
.getRequiredWebApplicationContext(request.getServletContext());
|
||||
if (ManagementPortType.get(applicationContext
|
||||
.getEnvironment()) == ManagementPortType.DIFFERENT) {
|
||||
if (applicationContext.getParent() == null) {
|
||||
return false;
|
||||
}
|
||||
String managementContextId = applicationContext.getParent().getId()
|
||||
+ ":management";
|
||||
if (!managementContextId.equals(applicationContext.getId())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return this.delegate.matches(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,16 @@ public enum ManagementPortType {
|
||||
*/
|
||||
DIFFERENT;
|
||||
|
||||
static ManagementPortType get(Environment environment) {
|
||||
/**
|
||||
* Look at the given environment to determine if the {@link ManagementPortType} is
|
||||
* {@link #DISABLED}, {@link #SAME} or {@link #DIFFERENT}.
|
||||
* @param environment the Spring environment
|
||||
* @return {@link #DISABLED} if `management.server.port` is set to a negative value,
|
||||
* {@link #SAME} if `management.server.port` is not specified or equal to
|
||||
* `server.port`and {@link #DIFFERENT} otherwise.
|
||||
* @since 2.1.4
|
||||
*/
|
||||
public static ManagementPortType get(Environment environment) {
|
||||
Integer managementPort = getPortProperty(environment, "management.server.");
|
||||
if (managementPort != null && managementPort < 0) {
|
||||
return DISABLED;
|
||||
|
||||
Reference in New Issue
Block a user