diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/CorsEndpointProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/CorsEndpointProperties.java index de1a4edad5d..ea9dee1b126 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/CorsEndpointProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/CorsEndpointProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfigurationTests.java index 0c9d5efd422..94a864b0572 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfigurationTests.java @@ -54,19 +54,16 @@ public class DataSourcePoolMetricsAutoConfigurationTests { @Test public void autoConfiguredDataSourceIsInstrumented() { - this.contextRunner - .run((context) -> { - context.getBean(DataSource.class).getConnection().getMetaData(); - MeterRegistry registry = context.getBean(MeterRegistry.class); - registry.get("jdbc.connections.max").tags("name", "dataSource") - .meter(); - }); + this.contextRunner.run((context) -> { + context.getBean(DataSource.class).getConnection().getMetaData(); + MeterRegistry registry = context.getBean(MeterRegistry.class); + registry.get("jdbc.connections.max").tags("name", "dataSource").meter(); + }); } @Test public void dataSourceInstrumentationCanBeDisabled() { - this.contextRunner - .withPropertyValues("management.metrics.enable.jdbc=false") + this.contextRunner.withPropertyValues("management.metrics.enable.jdbc=false") .run((context) -> { context.getBean(DataSource.class).getConnection().getMetaData(); MeterRegistry registry = context.getBean(MeterRegistry.class); @@ -92,23 +89,20 @@ public class DataSourcePoolMetricsAutoConfigurationTests { @Test public void autoConfiguredHikariDataSourceIsInstrumented() { - this.contextRunner - .run((context) -> { - context.getBean(DataSource.class).getConnection(); - MeterRegistry registry = context.getBean(MeterRegistry.class); - registry.get("hikaricp.connections").meter(); - }); + this.contextRunner.run((context) -> { + context.getBean(DataSource.class).getConnection(); + MeterRegistry registry = context.getBean(MeterRegistry.class); + registry.get("hikaricp.connections").meter(); + }); } @Test public void hikariDataSourceInstrumentationCanBeDisabled() { - this.contextRunner - .withPropertyValues("management.metrics.enable.hikaricp=false") + this.contextRunner.withPropertyValues("management.metrics.enable.hikaricp=false") .run((context) -> { context.getBean(DataSource.class).getConnection(); MeterRegistry registry = context.getBean(MeterRegistry.class); - assertThat(registry.find("hikaricp.connections").meter()) - .isNull(); + assertThat(registry.find("hikaricp.connections").meter()).isNull(); }); } @@ -135,7 +129,7 @@ public class DataSourcePoolMetricsAutoConfigurationTests { MeterRegistry registry = context.getBean(MeterRegistry.class); assertThat(registry.get("hikaricp.connections").meter().getId() .getTags()) - .containsExactly(Tag.of("pool", "firstDataSource")); + .containsExactly(Tag.of("pool", "firstDataSource")); }); } @@ -215,8 +209,7 @@ public class DataSourcePoolMetricsAutoConfigurationTests { private org.apache.tomcat.jdbc.pool.DataSource createTomcatDataSource() { String url = "jdbc:hsqldb:mem:test-" + UUID.randomUUID(); - return DataSourceBuilder - .create().url(url) + return DataSourceBuilder.create().url(url) .type(org.apache.tomcat.jdbc.pool.DataSource.class).build(); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/SecurityContext.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/SecurityContext.java index 9838e177941..ac0ded3136c 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/SecurityContext.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/SecurityContext.java @@ -26,6 +26,20 @@ import java.security.Principal; */ public interface SecurityContext { + public static SecurityContext NONE = new SecurityContext() { + + @Override + public Principal getPrincipal() { + return null; + } + + @Override + public boolean isUserInRole(String role) { + return false; + } + + }; + /** * Return the currently authenticated {@link Principal} or {@code null}. * @return the principal or {@code null} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java index f669ab8372c..f9f848aecee 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java @@ -16,7 +16,6 @@ package org.springframework.boot.actuate.endpoint.jmx; -import java.security.Principal; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -100,7 +99,7 @@ public class EndpointMBean implements DynamicMBean { .map(JmxOperationParameter::getName).toArray(String[]::new); Map arguments = getArguments(parameterNames, params); Object result = operation - .invoke(new InvocationContext(new JmxSecurityContext(), arguments)); + .invoke(new InvocationContext(SecurityContext.NONE, arguments)); if (REACTOR_PRESENT) { result = ReactiveHandler.handle(result); } @@ -152,18 +151,4 @@ public class EndpointMBean implements DynamicMBean { } - private static final class JmxSecurityContext implements SecurityContext { - - @Override - public Principal getPrincipal() { - return null; - } - - @Override - public boolean isUserInRole(String role) { - return false; - } - - } - } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java index 89dfb0c6c72..e212595461b 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java @@ -271,14 +271,16 @@ public abstract class AbstractWebFluxEndpointHandlerMapping private ReactiveWebOperationAdapter(OperationInvoker invoker) { this.invoker = invoker; + this.securityContextSupplier = getSecurityContextSupplier(); + } + + private Supplier> getSecurityContextSupplier() { if (ClassUtils.isPresent( "org.springframework.security.core.context.ReactiveSecurityContextHolder", getClass().getClassLoader())) { - this.securityContextSupplier = this::springSecurityContext; - } - else { - this.securityContextSupplier = this::emptySecurityContext; + return this::springSecurityContext; } + return this::emptySecurityContext; } public Mono springSecurityContext() { @@ -289,19 +291,7 @@ public abstract class AbstractWebFluxEndpointHandlerMapping } public Mono emptySecurityContext() { - return Mono.just(new SecurityContext() { - - @Override - public Principal getPrincipal() { - return null; - } - - @Override - public boolean isUserInRole(String role) { - return false; - } - - }); + return Mono.just(SecurityContext.NONE); } @Override diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java index 7952e8d9318..35c054d02a4 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java @@ -84,8 +84,8 @@ public class DataSourcePoolMetrics implements MeterBinder { private void bindDataSource(MeterRegistry registry, String metricName, Function function) { if (function.apply(this.dataSource) != null) { - registry.gauge("jdbc.connections." + metricName, this.tags, - this.dataSource, (m) -> function.apply(m).doubleValue()); + registry.gauge("jdbc.connections." + metricName, this.tags, this.dataSource, + (m) -> function.apply(m).doubleValue()); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java index e07a2a972e5..e411e3b0f2f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcProperties.java index 5e998819f16..58b27295530 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java index a3b95ece559..4a31f1aa0e2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionProperties.java index 8ab158a788e..4e1923887be 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/AggregateBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/AggregateBinder.java index 6e30d659e2c..b1c50b19081 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/AggregateBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/AggregateBinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BeanBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BeanBinder.java index 37cda540e71..ca7bb27ac95 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BeanBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BeanBinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindContext.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindContext.java index 6f69cbb9b83..16ca63c1a4a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindContext.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationFormat.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationFormat.java index f12ab642f25..41b1aec364e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationFormat.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationFormat.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationUnit.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationUnit.java index 83db732401f..d98739b0223 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationUnit.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationUnit.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/StringToEnumIgnoringCaseConverterFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/StringToEnumIgnoringCaseConverterFactory.java index b9009e7505d..565cdc0e3f3 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/StringToEnumIgnoringCaseConverterFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/StringToEnumIgnoringCaseConverterFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jta/narayana/NarayanaProperties.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jta/narayana/NarayanaProperties.java index 5c0824dbc4d..909f22ac22c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jta/narayana/NarayanaProperties.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jta/narayana/NarayanaProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java index 28d096e42bc..7d0a1877d9c 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java @@ -79,10 +79,10 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -989,6 +989,7 @@ public class ConfigurationPropertiesTests { } return null; } + } @Configuration