Merge branch '1.5.x'
This commit is contained in:
@@ -244,7 +244,8 @@ public class HealthIndicatorAutoConfiguration {
|
||||
|
||||
private final Map<String, LdapOperations> ldapOperations;
|
||||
|
||||
public LdapHealthIndicatorConfiguration(Map<String, LdapOperations> ldapOperations) {
|
||||
public LdapHealthIndicatorConfiguration(
|
||||
Map<String, LdapOperations> ldapOperations) {
|
||||
this.ldapOperations = ldapOperations;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
* @author Christian Dupuis
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@ConfigurationProperties("management.health.status")
|
||||
@ConfigurationProperties(prefix = "management.health.status")
|
||||
public class HealthIndicatorProperties {
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.net.InetAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.springframework.boot.autoconfigure.security.SecurityPrerequisite;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
@@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.context.embedded.Ssl;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -78,7 +79,6 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
||||
/**
|
||||
* Management endpoint context-path.
|
||||
*/
|
||||
@NotNull
|
||||
private String contextPath = "";
|
||||
|
||||
/**
|
||||
@@ -88,6 +88,11 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
||||
|
||||
private final Security security = new Security();
|
||||
|
||||
@PostConstruct
|
||||
private void validate() {
|
||||
Assert.notNull(this.contextPath, "ContextPath must not be null");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the management port or {@code null} if the
|
||||
* {@link ServerProperties#getPort() server port} should be used.
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
* @author Phillip Webb
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@ConfigurationProperties("endpoints.metrics.filter")
|
||||
@ConfigurationProperties(prefix = "endpoints.metrics.filter")
|
||||
public class MetricFilterProperties {
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,11 +16,13 @@
|
||||
|
||||
package org.springframework.boot.actuate.endpoint;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Abstract base for {@link Endpoint} implementations.
|
||||
@@ -31,14 +33,14 @@ import org.springframework.core.env.Environment;
|
||||
*/
|
||||
public abstract class AbstractEndpoint<T> implements Endpoint<T>, EnvironmentAware {
|
||||
|
||||
private static final Pattern ID_PATTERN = Pattern.compile("\\w+");
|
||||
|
||||
private Environment environment;
|
||||
|
||||
/**
|
||||
* Endpoint identifier. With HTTP monitoring the identifier of the endpoint is mapped
|
||||
* to a URL (e.g. 'foo' is mapped to '/foo').
|
||||
*/
|
||||
@NotNull
|
||||
@Pattern(regexp = "\\w+", message = "ID must only contains letters, numbers and '_'")
|
||||
private String id;
|
||||
|
||||
private final boolean sensitiveDefault;
|
||||
@@ -53,6 +55,13 @@ public abstract class AbstractEndpoint<T> implements Endpoint<T>, EnvironmentAwa
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
@PostConstruct
|
||||
private void validate() {
|
||||
Assert.notNull(this.id, "Id must not be null");
|
||||
Assert.isTrue(ID_PATTERN.matcher(this.id).matches(),
|
||||
"ID must only contains letters, numbers and '_'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new sensitive endpoint instance. The endpoint will enabled flag will be
|
||||
* based on the spring {@link Environment} unless explicitly set.
|
||||
|
||||
@@ -62,9 +62,11 @@ public class LiquibaseEndpoint extends AbstractEndpoint<List<LiquibaseReport>> {
|
||||
for (Map.Entry<String, SpringLiquibase> entry : this.liquibases.entrySet()) {
|
||||
try {
|
||||
DataSource dataSource = entry.getValue().getDataSource();
|
||||
JdbcConnection connection = new JdbcConnection(dataSource.getConnection());
|
||||
JdbcConnection connection = new JdbcConnection(
|
||||
dataSource.getConnection());
|
||||
try {
|
||||
Database database = factory.findCorrectDatabaseImplementation(connection);
|
||||
Database database = factory
|
||||
.findCorrectDatabaseImplementation(connection);
|
||||
reports.add(new LiquibaseReport(entry.getKey(),
|
||||
service.queryDatabaseChangeLogTable(database)));
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.mvc;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.EndpointProperties;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
/**
|
||||
@@ -41,8 +41,6 @@ public abstract class AbstractMvcEndpoint extends WebMvcConfigurerAdapter
|
||||
/**
|
||||
* Endpoint URL path.
|
||||
*/
|
||||
@NotNull
|
||||
@Pattern(regexp = "/.*|^$", message = "Path must start with / or be empty")
|
||||
private String path;
|
||||
|
||||
/**
|
||||
@@ -68,6 +66,13 @@ public abstract class AbstractMvcEndpoint extends WebMvcConfigurerAdapter
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void validate() {
|
||||
Assert.notNull(this.path, "Path must not be null");
|
||||
Assert.isTrue(this.path.length() == 0 || this.path.startsWith("/"),
|
||||
"Path must start with / or be empty");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.environment = environment;
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
||||
* @author Dave Syer
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@ConfigurationProperties("endpoints.docs")
|
||||
@ConfigurationProperties(prefix = "endpoints.docs")
|
||||
public class DocsMvcEndpoint extends AbstractNamedMvcEndpoint {
|
||||
|
||||
private static final String DOCS_LOCATION = "classpath:/META-INF/resources/spring-boot-actuator/docs/";
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
* @author Andy Wilkinson
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@ConfigurationProperties("endpoints.actuator")
|
||||
@ConfigurationProperties(prefix = "endpoints.actuator")
|
||||
public class HalJsonMvcEndpoint extends AbstractNamedMvcEndpoint {
|
||||
|
||||
private final ManagementServletContext managementServletContext;
|
||||
|
||||
@@ -53,7 +53,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
* @author Phillip Webb
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@ConfigurationProperties("endpoints.heapdump")
|
||||
@ConfigurationProperties(prefix = "endpoints.heapdump")
|
||||
@HypermediaDisabled
|
||||
public class HeapdumpMvcEndpoint extends AbstractNamedMvcEndpoint {
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.util.Assert;
|
||||
* @author Andy Wilkinson
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@ConfigurationProperties("management.health.diskspace")
|
||||
@ConfigurationProperties(prefix = "management.health.diskspace")
|
||||
public class DiskSpaceHealthIndicatorProperties {
|
||||
|
||||
private static final int MEGABYTES = 1024 * 1024;
|
||||
|
||||
@@ -57,6 +57,7 @@ public class LdapHealthIndicator extends AbstractHealthIndicator {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.util.PatternMatchUtils;
|
||||
* @author Simon Buettner
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@ConfigurationProperties("spring.metrics.export")
|
||||
@ConfigurationProperties(prefix = "spring.metrics.export")
|
||||
public class MetricExportProperties extends TriggerProperties {
|
||||
|
||||
/**
|
||||
|
||||
@@ -541,8 +541,8 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||
public void ldapHealthIndicator() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"management.health.diskspace.enabled:false");
|
||||
this.context.register(LdapConfiguration.class,
|
||||
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
|
||||
this.context.register(LdapConfiguration.class, ManagementServerProperties.class,
|
||||
HealthIndicatorAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
Map<String, HealthIndicator> beans = this.context
|
||||
.getBeansOfType(HealthIndicator.class);
|
||||
@@ -556,8 +556,8 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"management.health.diskspace.enabled:false",
|
||||
"management.health.ldap.enabled:false");
|
||||
this.context.register(LdapConfiguration.class,
|
||||
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
|
||||
this.context.register(LdapConfiguration.class, ManagementServerProperties.class,
|
||||
HealthIndicatorAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
Map<String, HealthIndicator> beans = this.context
|
||||
.getBeansOfType(HealthIndicator.class);
|
||||
|
||||
@@ -62,31 +62,33 @@ public class LdapHealthIndicatorTests {
|
||||
this.context.register(LdapAutoConfiguration.class,
|
||||
LdapDataAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
EndpointAutoConfiguration.class,
|
||||
HealthIndicatorAutoConfiguration.class);
|
||||
EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
LdapTemplate ldapTemplate = this.context.getBean(LdapTemplate.class);
|
||||
assertThat(ldapTemplate).isNotNull();
|
||||
LdapHealthIndicator healthIndicator = this.context.getBean(
|
||||
LdapHealthIndicator.class);
|
||||
LdapHealthIndicator healthIndicator = this.context
|
||||
.getBean(LdapHealthIndicator.class);
|
||||
assertThat(healthIndicator).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void ldapIsUp() {
|
||||
LdapTemplate ldapTemplate = mock(LdapTemplate.class);
|
||||
given(ldapTemplate.executeReadOnly(any(ContextExecutor.class))).willReturn("3");
|
||||
given(ldapTemplate.executeReadOnly((ContextExecutor<String>) any()))
|
||||
.willReturn("3");
|
||||
LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
|
||||
Health health = healthIndicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails().get("version")).isEqualTo("3");
|
||||
verify(ldapTemplate).executeReadOnly(any(ContextExecutor.class));
|
||||
verify(ldapTemplate).executeReadOnly((ContextExecutor<String>) any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void ldapIsDown() {
|
||||
LdapTemplate ldapTemplate = mock(LdapTemplate.class);
|
||||
given(ldapTemplate.executeReadOnly(any(ContextExecutor.class)))
|
||||
given(ldapTemplate.executeReadOnly((ContextExecutor<String>) any()))
|
||||
.willThrow(new CommunicationException(
|
||||
new javax.naming.CommunicationException("Connection failed")));
|
||||
LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
|
||||
@@ -94,7 +96,7 @@ public class LdapHealthIndicatorTests {
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
assertThat((String) health.getDetails().get("error"))
|
||||
.contains("Connection failed");
|
||||
verify(ldapTemplate).executeReadOnly(any(ContextExecutor.class));
|
||||
verify(ldapTemplate).executeReadOnly((ContextExecutor<String>) any());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user