Add property to configure base-path for web endpoints.
Also, move properties corresponding to management server under `management.server.*`. Closes gh-10230
This commit is contained in:
@@ -21,7 +21,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointProvider;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
|
||||
import org.springframework.boot.actuate.endpoint.EndpointInfo;
|
||||
import org.springframework.boot.actuate.endpoint.web.WebEndpointOperation;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -36,12 +35,12 @@ public class DefaultEndpointPathProvider implements EndpointPathProvider {
|
||||
|
||||
private final Collection<EndpointInfo<WebEndpointOperation>> endpoints;
|
||||
|
||||
private final String contextPath;
|
||||
private final String basePath;
|
||||
|
||||
public DefaultEndpointPathProvider(EndpointProvider<WebEndpointOperation> provider,
|
||||
ManagementServerProperties managementServerProperties) {
|
||||
WebEndpointProperties webEndpointProperties) {
|
||||
this.endpoints = provider.getEndpoints();
|
||||
this.contextPath = managementServerProperties.getContextPath();
|
||||
this.basePath = webEndpointProperties.getBasePath();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,7 +56,7 @@ public class DefaultEndpointPathProvider implements EndpointPathProvider {
|
||||
}
|
||||
|
||||
private String getPath(EndpointInfo<WebEndpointOperation> endpointInfo) {
|
||||
return this.contextPath + "/" + endpointInfo.getId();
|
||||
return this.basePath + "/" + endpointInfo.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.endpoint.web;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Configuration properties for web management endpoints.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "management.endpoints.web")
|
||||
public class WebEndpointProperties {
|
||||
|
||||
/**
|
||||
* The base-path for the web endpoints. Relative to `server.context-path` or
|
||||
* `management.server.context-path`, if `management.server.port` is different.
|
||||
*/
|
||||
private String basePath = "/application";
|
||||
|
||||
public String getBasePath() {
|
||||
return this.basePath;
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointProvider;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.DefaultEndpointPathProvider;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathProvider;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.web.WebEndpointOperation;
|
||||
import org.springframework.boot.actuate.endpoint.web.jersey.JerseyEndpointResourceFactory;
|
||||
@@ -55,10 +55,10 @@ class JerseyWebEndpointManagementContextConfiguration {
|
||||
@Bean
|
||||
public ResourceConfigCustomizer webEndpointRegistrar(
|
||||
EndpointProvider<WebEndpointOperation> provider,
|
||||
ManagementServerProperties managementServerProperties) {
|
||||
WebEndpointProperties webEndpointProperties) {
|
||||
return (resourceConfig) -> resourceConfig.registerResources(
|
||||
new HashSet<>(new JerseyEndpointResourceFactory().createEndpointResources(
|
||||
new EndpointMapping(managementServerProperties.getContextPath()),
|
||||
new EndpointMapping(webEndpointProperties.getBasePath()),
|
||||
provider.getEndpoints())));
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ class JerseyWebEndpointManagementContextConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
public EndpointPathProvider endpointPathProvider(
|
||||
EndpointProvider<WebEndpointOperation> provider,
|
||||
ManagementServerProperties managementServerProperties) {
|
||||
return new DefaultEndpointPathProvider(provider, managementServerProperties);
|
||||
WebEndpointProperties webEndpointProperties) {
|
||||
return new DefaultEndpointPathProvider(provider, webEndpointProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.web.reactive;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointProvider;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.DefaultEndpointPathProvider;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathProvider;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.web.WebEndpointOperation;
|
||||
import org.springframework.boot.actuate.endpoint.web.reactive.WebFluxEndpointHandlerMapping;
|
||||
@@ -45,9 +45,9 @@ public class WebFluxEndpointManagementContextConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
public WebFluxEndpointHandlerMapping webEndpointReactiveHandlerMapping(
|
||||
EndpointProvider<WebEndpointOperation> provider,
|
||||
ManagementServerProperties managementServerProperties) {
|
||||
WebEndpointProperties webEndpointProperties) {
|
||||
return new WebFluxEndpointHandlerMapping(
|
||||
new EndpointMapping(managementServerProperties.getContextPath()),
|
||||
new EndpointMapping(webEndpointProperties.getBasePath()),
|
||||
provider.getEndpoints());
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ public class WebFluxEndpointManagementContextConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
public EndpointPathProvider endpointPathProvider(
|
||||
EndpointProvider<WebEndpointOperation> provider,
|
||||
ManagementServerProperties managementServerProperties) {
|
||||
return new DefaultEndpointPathProvider(provider, managementServerProperties);
|
||||
WebEndpointProperties webEndpointProperties) {
|
||||
return new DefaultEndpointPathProvider(provider, webEndpointProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.web.servlet;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointProvider;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.DefaultEndpointPathProvider;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathProvider;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
@@ -48,7 +49,7 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||
@ConditionalOnClass(DispatcherServlet.class)
|
||||
@ConditionalOnBean(DispatcherServlet.class)
|
||||
@EnableConfigurationProperties({ CorsEndpointProperties.class,
|
||||
ManagementServerProperties.class })
|
||||
WebEndpointProperties.class, ManagementServerProperties.class })
|
||||
public class WebMvcEndpointManagementContextConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -56,9 +57,9 @@ public class WebMvcEndpointManagementContextConfiguration {
|
||||
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(
|
||||
EndpointProvider<WebEndpointOperation> provider,
|
||||
CorsEndpointProperties corsProperties,
|
||||
ManagementServerProperties managementServerProperties) {
|
||||
WebEndpointProperties webEndpointProperties) {
|
||||
WebMvcEndpointHandlerMapping handlerMapping = new WebMvcEndpointHandlerMapping(
|
||||
new EndpointMapping(managementServerProperties.getContextPath()),
|
||||
new EndpointMapping(webEndpointProperties.getBasePath()),
|
||||
provider.getEndpoints(), getCorsConfiguration(corsProperties));
|
||||
return handlerMapping;
|
||||
}
|
||||
@@ -67,8 +68,8 @@ public class WebMvcEndpointManagementContextConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
public EndpointPathProvider endpointPathProvider(
|
||||
EndpointProvider<WebEndpointOperation> provider,
|
||||
ManagementServerProperties managementServerProperties) {
|
||||
return new DefaultEndpointPathProvider(provider, managementServerProperties);
|
||||
WebEndpointProperties webEndpointProperties) {
|
||||
return new DefaultEndpointPathProvider(provider, webEndpointProperties);
|
||||
}
|
||||
|
||||
private CorsConfiguration getCorsConfiguration(CorsEndpointProperties properties) {
|
||||
|
||||
@@ -69,7 +69,7 @@ public class JolokiaManagementContextConfiguration {
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean<AgentServlet> jolokiaServlet() {
|
||||
String path = this.managementServletContext.getContextPath()
|
||||
String path = this.managementServletContext.getServletPath()
|
||||
+ this.properties.getPath();
|
||||
String urlMapping = (path.endsWith("/") ? path + "*" : path + "/*");
|
||||
ServletRegistrationBean<AgentServlet> registration = new ServletRegistrationBean<>(
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.actuate.autoconfigure.web.server;
|
||||
|
||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextFactory;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
|
||||
@@ -42,8 +43,8 @@ import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for the management context. If the
|
||||
* {@code management.port} is the same as the {@code server.port} the management context
|
||||
* will be the same as the main application context. If the {@code management.port} is
|
||||
* {@code management.server.port} is the same as the {@code server.port} the management context
|
||||
* will be the same as the main application context. If the {@code management.server.port} is
|
||||
* different to the {@code server.port} the management context will be a separate context
|
||||
* that has the main application context as its parent.
|
||||
*
|
||||
@@ -52,7 +53,7 @@ import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
|
||||
@EnableConfigurationProperties(ManagementServerProperties.class)
|
||||
@EnableConfigurationProperties({ WebEndpointProperties.class, ManagementServerProperties.class })
|
||||
public class ManagementContextAutoConfiguration {
|
||||
|
||||
@Configuration
|
||||
@@ -76,7 +77,7 @@ public class ManagementContextAutoConfiguration {
|
||||
}
|
||||
|
||||
private void verifySslConfiguration() {
|
||||
Boolean enabled = this.environment.getProperty("management.ssl.enabled",
|
||||
Boolean enabled = this.environment.getProperty("management.server.ssl.enabled",
|
||||
Boolean.class, false);
|
||||
Assert.state(!enabled,
|
||||
"Management-specific SSL cannot be configured as the management "
|
||||
|
||||
@@ -43,7 +43,7 @@ public enum ManagementPortType {
|
||||
|
||||
static ManagementPortType get(Environment environment) {
|
||||
Integer serverPort = getPortProperty(environment, "server.");
|
||||
Integer managementPort = getPortProperty(environment, "management.");
|
||||
Integer managementPort = getPortProperty(environment, "management.server.");
|
||||
if (managementPort != null && managementPort < 0) {
|
||||
return DISABLED;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.util.StringUtils;
|
||||
* @since 2.0.0
|
||||
* @see ServerProperties
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "management", ignoreUnknownFields = true)
|
||||
@ConfigurationProperties(prefix = "management.server", ignoreUnknownFields = true)
|
||||
public class ManagementServerProperties implements SecurityPrerequisite {
|
||||
|
||||
/**
|
||||
@@ -54,7 +54,7 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
||||
/**
|
||||
* Management endpoint context-path.
|
||||
*/
|
||||
private String contextPath = "/application";
|
||||
private String contextPath = "";
|
||||
|
||||
/**
|
||||
* Add the "X-Application-Context" HTTP header in each response.
|
||||
|
||||
@@ -20,15 +20,16 @@ package org.springframework.boot.actuate.autoconfigure.web.servlet;
|
||||
* Provides information about the management servlet context for MVC controllers to use.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Madhura Bhave
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ManagementServletContext {
|
||||
|
||||
/**
|
||||
* Return the context path of the management server.
|
||||
* @return the context path
|
||||
* Return the servlet path of the management server.
|
||||
* @return the servlet path
|
||||
*/
|
||||
String getContextPath();
|
||||
String getServletPath();
|
||||
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ class ServletManagementChildContextConfiguration {
|
||||
ServerProperties serverProperties) {
|
||||
super.customize(webServerFactory, managementServerProperties,
|
||||
serverProperties);
|
||||
webServerFactory.setContextPath("");
|
||||
webServerFactory.setContextPath(managementServerProperties.getContextPath());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.web.servlet;
|
||||
|
||||
import javax.servlet.Servlet;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
@@ -48,8 +48,8 @@ public class ServletManagementContextAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public ManagementServletContext managementServletContext(
|
||||
ManagementServerProperties properties) {
|
||||
return () -> properties.getContextPath();
|
||||
WebEndpointProperties properties) {
|
||||
return () -> properties.getBasePath();
|
||||
}
|
||||
|
||||
// Put Servlets and Filters in their own nested class so they don't force early
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointProvider;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
|
||||
import org.springframework.boot.actuate.endpoint.DefaultEnablement;
|
||||
import org.springframework.boot.actuate.endpoint.EndpointInfo;
|
||||
import org.springframework.boot.actuate.endpoint.web.WebEndpointOperation;
|
||||
@@ -88,10 +87,10 @@ public class DefaultEndpointPathProviderTests {
|
||||
endpoints.add(new EndpointInfo<>("bar", DefaultEnablement.ENABLED,
|
||||
Collections.emptyList()));
|
||||
given(this.endpointProvider.getEndpoints()).willReturn(endpoints);
|
||||
ManagementServerProperties managementServerProperties = new ManagementServerProperties();
|
||||
managementServerProperties.setContextPath(contextPath);
|
||||
WebEndpointProperties webEndpointProperties = new WebEndpointProperties();
|
||||
webEndpointProperties.setBasePath(contextPath);
|
||||
return new DefaultEndpointPathProvider(this.endpointProvider,
|
||||
managementServerProperties);
|
||||
webEndpointProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.endpoint.web;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link WebEndpointProperties}.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
public class WebEndpointPropertiesTests {
|
||||
|
||||
@Test
|
||||
public void defaultBasePathShouldBeApplication() throws Exception {
|
||||
WebEndpointProperties properties = new WebEndpointProperties();
|
||||
assertThat(properties.getBasePath()).isEqualTo("/application");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,10 +74,10 @@ public class WebMvcEndpointIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endpointsAreSecureByDefaultWithCustomContextPath() throws Exception {
|
||||
public void endpointsAreSecureByDefaultWithCustomBasePath() throws Exception {
|
||||
this.context = new AnnotationConfigWebApplicationContext();
|
||||
this.context.register(SecureConfiguration.class);
|
||||
TestPropertyValues.of("management.context-path:/management")
|
||||
TestPropertyValues.of("management.endpoints.web.base-path:/management")
|
||||
.applyTo(this.context);
|
||||
MockMvc mockMvc = createSecureMockMvc();
|
||||
mockMvc.perform(get("/management/beans").accept(MediaType.APPLICATION_JSON))
|
||||
@@ -85,13 +85,13 @@ public class WebMvcEndpointIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endpointsAreSecureWithActuatorRoleWithCustomContextPath()
|
||||
public void endpointsAreSecureWithActuatorRoleWithCustomBasePath()
|
||||
throws Exception {
|
||||
TestSecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
|
||||
this.context = new AnnotationConfigWebApplicationContext();
|
||||
this.context.register(SecureConfiguration.class);
|
||||
TestPropertyValues.of("management.context-path:/management",
|
||||
TestPropertyValues.of("management.endpoints.web.base-path:/management",
|
||||
"endpoints.default.web.enabled=true").applyTo(this.context);
|
||||
MockMvc mockMvc = createSecureMockMvc();
|
||||
mockMvc.perform(get("/management/beans")).andExpect(status().isOk());
|
||||
|
||||
@@ -76,7 +76,7 @@ public class JolokiaManagementContextConfigurationTests {
|
||||
public void customManagementPath() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("management.jolokia.enabled=true",
|
||||
"management.context-path=/admin")
|
||||
"management.endpoints.web.base-path=/admin")
|
||||
.run(isDefinedOnPath("/admin/jolokia/*"));
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ManagementServerPropertiesTests {
|
||||
public void defaultManagementServerProperties() {
|
||||
ManagementServerProperties properties = new ManagementServerProperties();
|
||||
assertThat(properties.getPort()).isNull();
|
||||
assertThat(properties.getContextPath()).isEqualTo("/application");
|
||||
assertThat(properties.getContextPath()).isEqualTo("");
|
||||
assertThat(properties.getAddApplicationContextHeader()).isEqualTo(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -1197,25 +1197,25 @@ content into your application; rather pick only the properties that you need.
|
||||
endpoints.trace.web.enabled= # Expose the trace endpoint as a Web endpoint.
|
||||
|
||||
# MANAGEMENT HTTP SERVER ({sc-spring-boot-actuator}/autoconfigure/web/ManagementServerProperties.{sc-ext}[ManagementServerProperties])
|
||||
management.add-application-context-header=false # Add the "X-Application-Context" HTTP header in each response.
|
||||
management.address= # Network address that the management endpoints should bind to.
|
||||
management.context-path= # Management endpoint context-path. For instance `/actuator`
|
||||
management.port= # Management endpoint HTTP port. Uses the same port as the application by default. Configure a different port to use management-specific SSL.
|
||||
management.ssl.ciphers= # Supported SSL ciphers. Requires a custom management.port.
|
||||
management.ssl.client-auth= # Whether client authentication is wanted ("want") or needed ("need"). Requires a trust store. Requires a custom management.port.
|
||||
management.ssl.enabled= # Enable SSL support. Requires a custom management.port.
|
||||
management.ssl.enabled-protocols= # Enabled SSL protocols. Requires a custom management.port.
|
||||
management.ssl.key-alias= # Alias that identifies the key in the key store. Requires a custom management.port.
|
||||
management.ssl.key-password= # Password used to access the key in the key store. Requires a custom management.port.
|
||||
management.ssl.key-store= # Path to the key store that holds the SSL certificate (typically a jks file). Requires a custom management.port.
|
||||
management.ssl.key-store-password= # Password used to access the key store. Requires a custom management.port.
|
||||
management.ssl.key-store-provider= # Provider for the key store. Requires a custom management.port.
|
||||
management.ssl.key-store-type= # Type of the key store. Requires a custom management.port.
|
||||
management.ssl.protocol=TLS # SSL protocol to use. Requires a custom management.port.
|
||||
management.ssl.trust-store= # Trust store that holds SSL certificates. Requires a custom management.port.
|
||||
management.ssl.trust-store-password= # Password used to access the trust store. Requires a custom management.port.
|
||||
management.ssl.trust-store-provider= # Provider for the trust store. Requires a custom management.port.
|
||||
management.ssl.trust-store-type= # Type of the trust store. Requires a custom management.port.
|
||||
management.server.add-application-context-header=false # Add the "X-Application-Context" HTTP header in each response. Requires a custom management.server.port.
|
||||
management.server.address= # Network address that the management endpoints should bind to. Requires a custom management.server.port.
|
||||
management.server.context-path= # Management endpoint context-path. For instance `/actuator`. Requires a custom management.server.port
|
||||
management.server.port= # Management endpoint HTTP port. Uses the same port as the application by default. Configure a different port to use management-specific SSL.
|
||||
management.server.ssl.ciphers= # Supported SSL ciphers. Requires a custom management.port.
|
||||
management.server.ssl.client-auth= # Whether client authentication is wanted ("want") or needed ("need"). Requires a trust store. Requires a custom management.server.port.
|
||||
management.server.ssl.enabled= # Enable SSL support. Requires a custom management.server.port.
|
||||
management.server.ssl.enabled-protocols= # Enabled SSL protocols. Requires a custom management.server.port.
|
||||
management.server.ssl.key-alias= # Alias that identifies the key in the key store. Requires a custom management.server.port.
|
||||
management.server.ssl.key-password= # Password used to access the key in the key store. Requires a custom management.server.port.
|
||||
management.server.ssl.key-store= # Path to the key store that holds the SSL certificate (typically a jks file). Requires a custom management.server.port.
|
||||
management.server.ssl.key-store-password= # Password used to access the key store. Requires a custom management.server.port.
|
||||
management.server.ssl.key-store-provider= # Provider for the key store. Requires a custom management.server.port.
|
||||
management.server.ssl.key-store-type= # Type of the key store. Requires a custom management.server.port.
|
||||
management.server.ssl.protocol=TLS # SSL protocol to use. Requires a custom management.server.port.
|
||||
management.server.ssl.trust-store= # Trust store that holds SSL certificates. Requires a custom management.server.port.
|
||||
management.server.ssl.trust-store-password= # Password used to access the trust store. Requires a custom management.server.port.
|
||||
management.server.ssl.trust-store-provider= # Provider for the trust store. Requires a custom management.server.port.
|
||||
management.server.ssl.trust-store-type= # Type of the trust store. Requires a custom management.server.port.
|
||||
|
||||
# CLOUDFOUNDRY
|
||||
management.cloudfoundry.enabled=true # Enable extended Cloud Foundry actuator endpoints.
|
||||
@@ -1229,6 +1229,9 @@ content into your application; rather pick only the properties that you need.
|
||||
management.endpoints.cors.exposed-headers= # Comma-separated list of headers to include in a response.
|
||||
management.endpoints.cors.max-age=1800 # How long, in seconds, the response from a pre-flight request can be cached by clients.
|
||||
|
||||
# ENDPOINTS JMX CONFIGURATION ({sc-spring-boot-actuator}/autoconfigure/endpoint/ManagementEndpointProperties.{sc-ext}[JmxEndpointExporterProperties])
|
||||
management.endpoints.web.base-path # Base path for Web endpoints. Relative to server.context-path or management.server.context-path if management.server.port is configured.
|
||||
|
||||
# ENDPOINTS JMX CONFIGURATION ({sc-spring-boot-actuator}/autoconfigure/endpoint/infrastructure/JmxEndpointExporterProperties.{sc-ext}[JmxEndpointExporterProperties])
|
||||
management.endpoints.jmx.domain=org.springframework.boot # Endpoints JMX domain name. Fallback to 'spring.jmx.default-domain' if set.
|
||||
management.endpoints.jmx.static-names=false # Additional static properties to append to all ObjectNames of MBeans representing Endpoints.
|
||||
|
||||
@@ -2116,9 +2116,9 @@ for more details.
|
||||
=== Change the HTTP port or address of the actuator endpoints
|
||||
In a standalone application the Actuator HTTP port defaults to the same as the main HTTP
|
||||
port. To make the application listen on a different port set the external property
|
||||
`management.port`. To listen on a completely different network address (e.g. if you have
|
||||
`management.server.port`. To listen on a completely different network address (e.g. if you have
|
||||
an internal network for management and an external one for user applications) you can
|
||||
also set `management.address` to a valid IP address that the server is able to bind to.
|
||||
also set `management.server.address` to a valid IP address that the server is able to bind to.
|
||||
|
||||
For more detail look at the
|
||||
{sc-spring-boot-actuator}/autoconfigure/web/ManagementServerProperties.{sc-ext}[`ManagementServerProperties`]
|
||||
|
||||
@@ -567,12 +567,12 @@ is exposed as `/application/health`.
|
||||
=== Customizing the management endpoint paths
|
||||
Sometimes it is useful to customize the prefix for the management endpoints.
|
||||
For example, your application might already use `/application` for another purpose.
|
||||
You can use the `management.context-path` property to change the prefix for your
|
||||
You can use the `management.endpoints.web.base-path` property to change the prefix for your
|
||||
management endpoint:
|
||||
|
||||
[source,properties,indent=0]
|
||||
----
|
||||
management.context-path=/manage
|
||||
management.endpoints.web.base-path=/manage
|
||||
----
|
||||
|
||||
The `application.properties` example above will change the endpoint from `/application/{id}` to
|
||||
@@ -580,7 +580,8 @@ The `application.properties` example above will change the endpoint from `/appli
|
||||
|
||||
NOTE: Unless the management port has been configured to
|
||||
<<production-ready-customizing-management-server-port,expose endpoints using a different
|
||||
HTTP port>>, `management.context-path` is relative to `server.context-path`.
|
||||
HTTP port>>, `management.endpoints.web.base-path` is relative to `server.context-path`. If `management.server.port`
|
||||
is configured, `management.endpoints.web.base-path`, is relative to `management.server.context-path`.
|
||||
|
||||
|
||||
|
||||
@@ -590,11 +591,11 @@ Exposing management endpoints using the default HTTP port is a sensible choice f
|
||||
based deployments. If, however, your application runs inside your own data center you
|
||||
may prefer to expose endpoints using a different HTTP port.
|
||||
|
||||
The `management.port` property can be used to change the HTTP port.
|
||||
The `management.server.port` property can be used to change the HTTP port.
|
||||
|
||||
[source,properties,indent=0]
|
||||
----
|
||||
management.port=8081
|
||||
management.server.port=8081
|
||||
----
|
||||
|
||||
Since your management port is often protected by a firewall, and not exposed to the public
|
||||
@@ -615,7 +616,7 @@ disable the management security in this way, and it might even break the applica
|
||||
[[production-ready-management-specific-ssl]]
|
||||
=== Configuring management-specific SSL
|
||||
When configured to use a custom port, the management server can also be configured with
|
||||
its own SSL using the various `management.ssl.*` properties. For example, this allows a
|
||||
its own SSL using the various `management.server.ssl.*` properties. For example, this allows a
|
||||
management server to be available via HTTP while the main application uses HTTPS:
|
||||
|
||||
[source,properties,indent=0]
|
||||
@@ -624,8 +625,8 @@ management server to be available via HTTP while the main application uses HTTPS
|
||||
server.ssl.enabled=true
|
||||
server.ssl.key-store=classpath:store.jks
|
||||
server.ssl.key-password=secret
|
||||
management.port=8080
|
||||
management.ssl.enabled=false
|
||||
management.server.port=8080
|
||||
management.server.ssl.enabled=false
|
||||
----
|
||||
|
||||
Alternatively, both the main server and the management server can use SSL but with
|
||||
@@ -637,10 +638,10 @@ different key stores:
|
||||
server.ssl.enabled=true
|
||||
server.ssl.key-store=classpath:main.jks
|
||||
server.ssl.key-password=secret
|
||||
management.port=8080
|
||||
management.ssl.enabled=true
|
||||
management.ssl.key-store=classpath:management.jks
|
||||
management.ssl.key-password=secret
|
||||
management.server.port=8080
|
||||
management.server.ssl.enabled=true
|
||||
management.server.ssl.key-store=classpath:management.jks
|
||||
management.server.ssl.key-password=secret
|
||||
----
|
||||
|
||||
|
||||
@@ -648,7 +649,7 @@ different key stores:
|
||||
[[production-ready-customizing-management-server-address]]
|
||||
=== Customizing the management server address
|
||||
You can customize the address that the management endpoints are available on by
|
||||
setting the `management.address` property. This can be useful if you want to
|
||||
setting the `management.server.address` property. This can be useful if you want to
|
||||
listen only on an internal or ops-facing network, or to only listen for connections from
|
||||
`localhost`.
|
||||
|
||||
@@ -660,8 +661,8 @@ connections:
|
||||
|
||||
[source,properties,indent=0]
|
||||
----
|
||||
management.port=8081
|
||||
management.address=127.0.0.1
|
||||
management.server.port=8081
|
||||
management.server.address=127.0.0.1
|
||||
----
|
||||
|
||||
|
||||
@@ -672,7 +673,7 @@ If you don't want to expose endpoints over HTTP you can set the management port
|
||||
|
||||
[source,properties,indent=0]
|
||||
----
|
||||
management.port=-1
|
||||
management.server.port=-1
|
||||
----
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"management.port=0", "management.context-path=/admin" })
|
||||
"management.server.port=0", "management.server.context-path=/management"})
|
||||
@DirtiesContext
|
||||
public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
|
||||
|
||||
@@ -60,7 +60,7 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testSecureActuator() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/health",
|
||||
"http://localhost:" + this.managementPort + "/management/application/health",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testInsecureActuator() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/status",
|
||||
"http://localhost:" + this.managementPort + "/management/application/status",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
@@ -78,7 +78,7 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
|
||||
public void testMissing() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate("admin", "admin")
|
||||
.getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/missing",
|
||||
"http://localhost:" + this.managementPort + "/management/application/missing",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
assertThat(entity.getBody()).contains("\"status\":404");
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"management.port:0" })
|
||||
"management.server.port:0" })
|
||||
@DirtiesContext
|
||||
public class SampleActuatorUiApplicationPortTests {
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ service.name=Phil
|
||||
|
||||
# logging.file=/tmp/logs/app.log
|
||||
# logging.level.org.springframework.security=DEBUG
|
||||
management.address=127.0.0.1
|
||||
management.server.address=127.0.0.1
|
||||
|
||||
endpoints.default.web.enabled=true
|
||||
endpoints.shutdown.enabled=true
|
||||
|
||||
@@ -40,8 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"management.port=0", "management.address=127.0.0.1",
|
||||
"management.context-path:/admin" })
|
||||
"management.server.port=0", "management.server.address=127.0.0.1",
|
||||
"management.server.context-path:/admin" })
|
||||
@DirtiesContext
|
||||
public class ManagementAddressActuatorApplicationTests {
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ManagementAddressActuatorApplicationTests {
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.withBasicAuth("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/admin/health",
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/admin/application/health",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"management.context_path=/admin" })
|
||||
"management.endpoints.web.base-path=/admin" })
|
||||
@DirtiesContext
|
||||
public class ManagementPathSampleActuatorApplicationTests {
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"management.port=0", "management.context-path=/admin" })
|
||||
"management.server.port=0", "management.endpoints.web.base-path=/admin" })
|
||||
@DirtiesContext
|
||||
public class ManagementPortAndPathSampleActuatorApplicationTests {
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"management.port=0" })
|
||||
"management.server.port=0" })
|
||||
@DirtiesContext
|
||||
public class ManagementPortSampleActuatorApplicationTests {
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"management.port=-1" })
|
||||
"management.server.port=-1" })
|
||||
@DirtiesContext
|
||||
public class NoManagementSampleActuatorApplicationTests {
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
server.error.path: /oops
|
||||
management.context-path: /admin
|
||||
management.endpoints.web.base-path: /admin
|
||||
Reference in New Issue
Block a user