Disable Jolokia by default

To be consistent with Actuator web endpoints, Jolokia is now disabled
by default.

Closes gh-10090
This commit is contained in:
Stephane Nicoll 2017-08-28 10:18:19 +02:00
parent def094b844
commit da65158eae
6 changed files with 43 additions and 39 deletions

View File

@ -54,7 +54,7 @@ import org.springframework.web.servlet.mvc.ServletWrappingController;
@ManagementContextConfiguration
@ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnClass({ AgentServlet.class, ServletWrappingController.class })
@ConditionalOnProperty(value = "management.jolokia.enabled", matchIfMissing = true)
@ConditionalOnProperty(value = "management.jolokia.enabled", havingValue = "true")
@EnableConfigurationProperties(JolokiaProperties.class)
public class JolokiaManagementContextConfiguration {

View File

@ -35,7 +35,7 @@ public class JolokiaProperties {
/**
* Enable Jolokia.
*/
private boolean enabled = true;
private boolean enabled;
/**
* Path at which Jolokia will be available.

View File

@ -58,7 +58,8 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
@TestPropertySource(properties = "management.security.enabled=false")
@TestPropertySource(properties = { "management.jolokia.enabled=true",
"management.security.enabled=false" })
public class JolokiaManagementContextConfigurationIntegrationTests {
@Autowired

View File

@ -44,47 +44,49 @@ public class JolokiaManagementContextConfigurationTests {
@Test
public void jolokiaIsEnabledByDefault() {
this.contextRunner.run((context) -> {
assertThat(context).hasSingleBean(ServletRegistrationBean.class);
ServletRegistrationBean<?> registrationBean = context
.getBean(ServletRegistrationBean.class);
assertThat(registrationBean.getUrlMappings())
.contains("/application/jolokia/*");
assertThat(registrationBean.getInitParameters()).isEmpty();
});
}
@Test
public void jolokiaCanBeDisabled() {
this.contextRunner.withPropertyValues("management.jolokia.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(ServletRegistrationBean.class));
}
@Test
public void customPath() {
this.contextRunner.withPropertyValues("management.jolokia.path=/lokia")
.run(isDefinedOnPath("/application/lokia/*"));
}
@Test
public void customManagementPath() {
this.contextRunner.withPropertyValues("management.context-path=/admin")
.run(isDefinedOnPath("/admin/jolokia/*"));
}
@Test
public void customInitParameters() {
this.contextRunner.withPropertyValues("management.jolokia.config.debug=true")
this.contextRunner.withPropertyValues("management.jolokia.enabled=true")
.run((context) -> {
assertThat(context).hasSingleBean(ServletRegistrationBean.class);
ServletRegistrationBean<?> registrationBean = context
.getBean(ServletRegistrationBean.class);
assertThat(registrationBean.getInitParameters())
.containsOnly(entry("debug", "true"));
assertThat(registrationBean.getUrlMappings())
.contains("/application/jolokia/*");
assertThat(registrationBean.getInitParameters()).isEmpty();
});
}
@Test
public void jolokiaIsDisabledByDefault() {
this.contextRunner.run((context) -> assertThat(context)
.doesNotHaveBean(ServletRegistrationBean.class));
}
@Test
public void customPath() {
this.contextRunner.withPropertyValues("management.jolokia.enabled=true",
"management.jolokia.path=/lokia").run(
isDefinedOnPath("/application/lokia/*"));
}
@Test
public void customManagementPath() {
this.contextRunner.withPropertyValues("management.jolokia.enabled=true",
"management.context-path=/admin").run(
isDefinedOnPath("/admin/jolokia/*"));
}
@Test
public void customInitParameters() {
this.contextRunner.withPropertyValues("management.jolokia.enabled=true",
"management.jolokia.config.debug=true").run((context) -> {
assertThat(context).hasSingleBean(ServletRegistrationBean.class);
ServletRegistrationBean<?> registrationBean = context
.getBean(ServletRegistrationBean.class);
assertThat(registrationBean.getInitParameters())
.containsOnly(entry("debug", "true"));
});
}
private ContextConsumer<AssertableWebApplicationContext> isDefinedOnPath(
String path) {
return (context) -> {

View File

@ -1274,7 +1274,7 @@ content into your application; rather pick only the properties that you need.
# JOLOKIA ({sc-spring-boot-actuator}/autoconfigure/jolokia/JolokiaProperties.{sc-ext}[JolokiaProperties])
management.jolokia.config.*= # Jolokia settings. See the Jolokia manual for details.
management.jolokia.enabled=true # Enable Jolokia.
management.jolokia.enabled=false # Enable Jolokia.
management.jolokia.path=/jolokia # Path at which Jolokia will be available.
# TRACING ({sc-spring-boot-actuator}/trace/TraceProperties.{sc-ext}[TraceProperties])

View File

@ -1,2 +1,3 @@
health.diskspace.enabled=false
endpoints.all.web.enabled=true
endpoints.all.web.enabled=true
management.jolokia.enabled=true