Polish
This commit is contained in:
@@ -78,6 +78,13 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
||||
|
||||
private final Security security = maybeCreateSecurity();
|
||||
|
||||
private Security maybeCreateSecurity() {
|
||||
if (ClassUtils.isPresent(SECURITY_CHECK_CLASS, null)) {
|
||||
return new Security();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the management port or {@code null} if the
|
||||
* {@link ServerProperties#getPort() server port} should be used.
|
||||
@@ -183,11 +190,4 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
||||
|
||||
}
|
||||
|
||||
private static Security maybeCreateSecurity() {
|
||||
if (ClassUtils.isPresent(SECURITY_CHECK_CLASS, null)) {
|
||||
return new Security();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -152,8 +152,8 @@ public class ManagementWebSecurityAutoConfiguration {
|
||||
List<String> ignored = SpringBootWebSecurityConfiguration
|
||||
.getIgnored(this.security);
|
||||
if (!this.management.getSecurity().isEnabled()) {
|
||||
ignored.addAll(Arrays
|
||||
.asList(getEndpointPaths(this.endpointHandlerMapping)));
|
||||
ignored.addAll(Arrays.asList(EndpointPaths
|
||||
.get(this.endpointHandlerMapping)));
|
||||
}
|
||||
if (ignored.contains("none")) {
|
||||
ignored.remove("none");
|
||||
@@ -333,44 +333,48 @@ public class ManagementWebSecurityAutoConfiguration {
|
||||
private String[] getPaths() {
|
||||
EndpointHandlerMapping endpointHandlerMapping = ManagementWebSecurityConfigurerAdapter.this.endpointHandlerMapping;
|
||||
if (this.sensitive) {
|
||||
return getEndpointPaths(endpointHandlerMapping);
|
||||
return EndpointPaths.get(endpointHandlerMapping);
|
||||
}
|
||||
return getEndpointPaths(endpointHandlerMapping, false);
|
||||
return EndpointPaths.get(endpointHandlerMapping, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static String[] getEndpointPaths(EndpointHandlerMapping endpointHandlerMapping) {
|
||||
return StringUtils.mergeStringArrays(
|
||||
getEndpointPaths(endpointHandlerMapping, false),
|
||||
getEndpointPaths(endpointHandlerMapping, true));
|
||||
}
|
||||
private static class EndpointPaths {
|
||||
|
||||
private static String[] getEndpointPaths(
|
||||
EndpointHandlerMapping endpointHandlerMapping, boolean secure) {
|
||||
if (endpointHandlerMapping == null) {
|
||||
return NO_PATHS;
|
||||
public static String[] get(EndpointHandlerMapping endpointHandlerMapping) {
|
||||
String[] insecure = get(endpointHandlerMapping, false);
|
||||
String[] secure = get(endpointHandlerMapping, true);
|
||||
return StringUtils.mergeStringArrays(insecure, secure);
|
||||
}
|
||||
Set<? extends MvcEndpoint> endpoints = endpointHandlerMapping.getEndpoints();
|
||||
Set<String> paths = new LinkedHashSet<String>(endpoints.size());
|
||||
for (MvcEndpoint endpoint : endpoints) {
|
||||
if (endpoint.isSensitive() == secure) {
|
||||
String path = endpointHandlerMapping.getPath(endpoint.getPath());
|
||||
paths.add(path);
|
||||
if (!path.equals("")) {
|
||||
// Ensure that nested paths are secured
|
||||
paths.add(path + "/**");
|
||||
// Add Spring MVC-generated additional paths
|
||||
paths.add(path + ".*");
|
||||
}
|
||||
else {
|
||||
paths.add("/");
|
||||
|
||||
public static String[] get(EndpointHandlerMapping endpointHandlerMapping,
|
||||
boolean secure) {
|
||||
if (endpointHandlerMapping == null) {
|
||||
return NO_PATHS;
|
||||
}
|
||||
Set<? extends MvcEndpoint> endpoints = endpointHandlerMapping.getEndpoints();
|
||||
Set<String> paths = new LinkedHashSet<String>(endpoints.size());
|
||||
for (MvcEndpoint endpoint : endpoints) {
|
||||
if (endpoint.isSensitive() == secure) {
|
||||
String path = endpointHandlerMapping.getPath(endpoint.getPath());
|
||||
paths.add(path);
|
||||
if (!path.equals("")) {
|
||||
// Ensure that nested paths are secured
|
||||
paths.add(path + "/**");
|
||||
// Add Spring MVC-generated additional paths
|
||||
paths.add(path + ".*");
|
||||
}
|
||||
else {
|
||||
paths.add("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
return paths.toArray(new String[paths.size()]);
|
||||
}
|
||||
return paths.toArray(new String[paths.size()]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class MetricRepositoryAutoConfiguration {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnJava(value = JavaVersion.EIGHT)
|
||||
@ConditionalOnJava(JavaVersion.EIGHT)
|
||||
@ConditionalOnMissingBean(GaugeService.class)
|
||||
static class FastMetricServicesConfiguration {
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ public class ActuatorHalBrowserEndpoint extends ActuatorHalJsonEndpoint implemen
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ActuatorHalJsonEndpoint extends WebMvcConfigurerAdapter implements
|
||||
|
||||
private String getDefaultPath(ManagementServletContext managementServletContext) {
|
||||
if (StringUtils.hasText(managementServletContext.getContextPath())) {
|
||||
return this.path = "";
|
||||
return "";
|
||||
}
|
||||
return "/actuator";
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class DropwizardMetricServices implements CounterService, GaugeService {
|
||||
/**
|
||||
* Simple {@link Gauge} implementation to {@literal double} value.
|
||||
*/
|
||||
private static class SimpleGauge implements Gauge<Double> {
|
||||
private final static class SimpleGauge implements Gauge<Double> {
|
||||
|
||||
private final double value;
|
||||
|
||||
|
||||
@@ -28,7 +28,10 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
*
|
||||
* @author Luke Taylor
|
||||
*/
|
||||
class RedisUtils {
|
||||
final class RedisUtils {
|
||||
|
||||
private RedisUtils() {
|
||||
}
|
||||
|
||||
static <K, V> RedisTemplate<K, V> createRedisTemplate(
|
||||
RedisConnectionFactory connectionFactory, Class<V> valueClass) {
|
||||
|
||||
@@ -121,7 +121,7 @@ public class DropwizardMetricWriter implements MetricWriter {
|
||||
/**
|
||||
* Simple {@link Gauge} implementation to {@literal double} value.
|
||||
*/
|
||||
private static class SimpleGauge implements Gauge<Double> {
|
||||
private final static class SimpleGauge implements Gauge<Double> {
|
||||
|
||||
private final double value;
|
||||
|
||||
|
||||
@@ -21,7 +21,10 @@ package org.springframework.boot.actuate.system;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class SystemProperties {
|
||||
final class SystemProperties {
|
||||
|
||||
private SystemProperties() {
|
||||
}
|
||||
|
||||
public static String get(String... properties) {
|
||||
for (String property : properties) {
|
||||
|
||||
@@ -269,18 +269,18 @@ public class PublicMetricsAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public DataSource tomcatDataSource() {
|
||||
return initializeBuilder().type(org.apache.tomcat.jdbc.pool.DataSource.class)
|
||||
.build();
|
||||
return InitalizedBuilder.create()
|
||||
.type(org.apache.tomcat.jdbc.pool.DataSource.class).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource hikariDS() {
|
||||
return initializeBuilder().type(HikariDataSource.class).build();
|
||||
return InitalizedBuilder.create().type(HikariDataSource.class).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource commonsDbcpDataSource() {
|
||||
return initializeBuilder().type(BasicDataSource.class).build();
|
||||
return InitalizedBuilder.create().type(BasicDataSource.class).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,13 +290,13 @@ public class PublicMetricsAutoConfigurationTests {
|
||||
@Bean
|
||||
@Primary
|
||||
public DataSource myDataSource() {
|
||||
return initializeBuilder().type(org.apache.tomcat.jdbc.pool.DataSource.class)
|
||||
.build();
|
||||
return InitalizedBuilder.create()
|
||||
.type(org.apache.tomcat.jdbc.pool.DataSource.class).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource commonsDbcpDataSource() {
|
||||
return initializeBuilder().type(BasicDataSource.class).build();
|
||||
return InitalizedBuilder.create().type(BasicDataSource.class).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,13 +306,13 @@ public class PublicMetricsAutoConfigurationTests {
|
||||
@Bean
|
||||
@Primary
|
||||
public DataSource myDataSource() {
|
||||
return initializeBuilder().type(org.apache.tomcat.jdbc.pool.DataSource.class)
|
||||
.build();
|
||||
return InitalizedBuilder.create()
|
||||
.type(org.apache.tomcat.jdbc.pool.DataSource.class).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
return initializeBuilder().type(BasicDataSource.class).build();
|
||||
return InitalizedBuilder.create().type(BasicDataSource.class).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,11 +331,6 @@ public class PublicMetricsAutoConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
private static DataSourceBuilder initializeBuilder() {
|
||||
return DataSourceBuilder.create().driverClassName("org.hsqldb.jdbc.JDBCDriver")
|
||||
.url("jdbc:hsqldb:mem:test").username("sa");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class RichGaugeReaderConfig {
|
||||
|
||||
@@ -385,4 +380,13 @@ public class PublicMetricsAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
private static class InitalizedBuilder {
|
||||
|
||||
public static DataSourceBuilder create() {
|
||||
return DataSourceBuilder.create()
|
||||
.driverClassName("org.hsqldb.jdbc.JDBCDriver")
|
||||
.url("jdbc:hsqldb:mem:test").username("sa");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,18 +294,6 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
|
||||
private String name = "654321";
|
||||
|
||||
public static class Bar {
|
||||
private String name = "123456";
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
private Bar bar = new Bar();
|
||||
|
||||
public Bar getBar() {
|
||||
@@ -329,6 +317,18 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
return "Name: " + this.name;
|
||||
}
|
||||
|
||||
public static class Bar {
|
||||
private String name = "123456";
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Cycle extends Foo {
|
||||
@@ -346,6 +346,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
public void setSelf(Foo self) {
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class MapHolder extends Foo {
|
||||
@@ -359,6 +360,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
public void setMap(Map<String, Object> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class ListHolder extends Foo {
|
||||
@@ -372,6 +374,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
public void setList(List<String> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Addressed extends Foo {
|
||||
|
||||
@@ -46,9 +46,9 @@ public class MetricsEndpointTests extends AbstractEndpointTests<MetricsEndpoint>
|
||||
|
||||
private Metric<Number> metric1 = new Metric<Number>("a", 1);
|
||||
|
||||
private Metric<Number> metric2 = new Metric<Number>("b", 2);;
|
||||
private Metric<Number> metric2 = new Metric<Number>("b", 2);
|
||||
|
||||
private Metric<Number> metric3 = new Metric<Number>("c", 3);;
|
||||
private Metric<Number> metric3 = new Metric<Number>("c", 3);
|
||||
|
||||
public MetricsEndpointTests() {
|
||||
super(Config.class, MetricsEndpoint.class, "metrics", true, "endpoints.metrics");
|
||||
|
||||
@@ -170,7 +170,7 @@ public class ElasticsearchHealthIndicatorTests {
|
||||
assertThat((T) details.get(detail), is(equalTo(value)));
|
||||
}
|
||||
|
||||
private static class StubClusterHealthResponse extends ClusterHealthResponse {
|
||||
private final static class StubClusterHealthResponse extends ClusterHealthResponse {
|
||||
|
||||
private final ClusterHealthStatus status;
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ public class MailHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
public void smtpIsDown() throws MessagingException {
|
||||
doThrow(new MessagingException("A test exception")).when(this.mailSender)
|
||||
willThrow(new MessagingException("A test exception")).given(this.mailSender)
|
||||
.testConnection();
|
||||
Health health = this.indicator.health();
|
||||
assertEquals(Status.DOWN, health.getStatus());
|
||||
|
||||
@@ -120,6 +120,7 @@ public class StatsdMetricWriterTests {
|
||||
.getData(), Charset.forName("UTF-8")).trim());
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
@@ -135,6 +136,7 @@ public class StatsdMetricWriterTests {
|
||||
Thread.sleep(50L);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user