From f3379668ac664e9d2ce3c5e6f76ffb877e76530f Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 18 Jan 2018 23:10:28 -0800 Subject: [PATCH] Polish --- .../condition/ConditionsReportEndpoint.java | 2 +- .../metrics/MetricsAutoConfiguration.java | 7 ++-- .../amqp/RabbitMetricsConfiguration.java | 3 +- .../export/datadog/DatadogProperties.java | 1 + .../metrics/export/jmx/JmxProperties.java | 1 + .../jmx/JmxPropertiesConfigAdapter.java | 2 +- .../security/servlet/EndpointRequest.java | 2 +- ...veManagementChildContextConfiguration.java | 2 +- ...iveManagementContextAutoConfiguration.java | 2 +- .../amqp/RabbitMetricsConfigurationTests.java | 13 ++++---- .../servlet/EndpointRequestTests.java | 2 +- .../actuate/metrics/amqp/RabbitMetrics.java | 8 ++--- .../metrics/amqp/RabbitMetricsTests.java | 8 ++--- .../autoconfigure/amqp/RabbitProperties.java | 2 +- .../security/StaticResourceRequest.java | 2 +- .../web/embedded/jetty/JettyCustomizer.java | 2 +- .../web/embedded/tomcat/TomcatCustomizer.java | 1 - .../embedded/undertow/UndertowCustomizer.java | 1 - .../ReactiveWebServerAutoConfiguration.java | 2 +- .../web/servlet/WebMvcProperties.java | 2 ++ .../error/ErrorMvcAutoConfiguration.java | 17 +++++----- .../error/ErrorMvcAutoConfigurationTests.java | 30 +++++++++-------- .../ServiceCapabilitiesReportGenerator.java | 32 ++++++++++--------- ...DevToolsPropertyDefaultsPostProcessor.java | 2 +- .../main/asciidoc/spring-boot-features.adoc | 13 ++++++-- ...andomPortTestRestTemplateExampleTests.java | 2 +- ...stContextBootstrapperIntegrationTests.java | 2 +- ...strapperWithContextConfigurationTests.java | 2 +- .../DescriptionExtractorTests.java | 11 +++---- .../specific/AnnotatedGetter.java | 4 +-- .../boot/gradle/plugin/JavaPluginAction.java | 2 +- .../logback/DefaultLogbackConfiguration.java | 2 +- ...cationContextServerWebExchangeMatcher.java | 4 +-- .../ApplicationContextRequestMatcher.java | 2 +- .../jetty/ForwardHeadersCustomizer.java | 1 + .../embedded/jetty/JettyHandlerWrappers.java | 1 + .../jetty/JettyServletWebServerFactory.java | 7 ++-- .../embedded/netty/SslServerCustomizer.java | 1 + .../tomcat/TomcatConnectorCustomizer.java | 2 +- .../tomcat/TomcatServletWebServerFactory.java | 8 +++-- .../UndertowServletWebServerFactory.java | 10 ++++-- .../ConfigurableServletWebServerFactory.java | 22 ------------- .../boot/web/servlet/server/Session.java | 2 +- ...ApplicationContextRequestMatcherTests.java | 2 +- .../JettyServletWebServerFactoryTests.java | 2 +- ...AbstractReactiveWebServerFactoryTests.java | 11 ++----- .../AbstractServletWebServerFactoryTests.java | 10 ------ .../customsecurity/SecurityConfiguration.java | 2 +- ...ampleSecureWebFluxCustomSecurityTests.java | 22 ++++++------- .../SampleSessionApplicationTests.java | 2 +- .../SampleMethodSecurityApplication.java | 2 +- 51 files changed, 139 insertions(+), 158 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.java index 7dbb50b82d..00822ebce1 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.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/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.java index 8886316ed5..541f1b6037 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.java @@ -61,6 +61,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.integration.config.EnableIntegrationManagement; import org.springframework.integration.support.management.IntegrationManagementConfigurer; +import org.springframework.util.Assert; /** * {@link EnableAutoConfiguration Auto-configuration} for Micrometer-based metrics. @@ -96,10 +97,8 @@ public class MetricsAutoConfiguration { .forEach((configurer) -> configurer.configureRegistry(composite)); exporters.getIfAvailable(Collections::emptyList).forEach((exporter) -> { MeterRegistry childRegistry = exporter.registry(); - if (composite == childRegistry) { - throw new IllegalStateException( - "cannot add a CompositeMeterRegistry to itself"); - } + Assert.state(composite != childRegistry, + "cannot add a CompositeMeterRegistry to itself"); composite.add(childRegistry); }); return composite; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfiguration.java index a24e0f3bd3..5eda78a281 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfiguration.java @@ -80,7 +80,8 @@ public class RabbitMetricsConfiguration { private String getConnectionFactoryName(String beanName) { if (beanName.length() > CONNECTION_FACTORY_SUFFIX.length() && StringUtils.endsWithIgnoreCase(beanName, CONNECTION_FACTORY_SUFFIX)) { - return beanName.substring(0, beanName.length() - CONNECTION_FACTORY_SUFFIX.length()); + return beanName.substring(0, + beanName.length() - CONNECTION_FACTORY_SUFFIX.length()); } return beanName; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java index c1600031bd..55d4c704aa 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java @@ -96,4 +96,5 @@ public class DatadogProperties extends StepRegistryProperties { public void setUri(String uri) { this.uri = uri; } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxProperties.java index ae73fb4bc7..b48f8d269d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxProperties.java @@ -41,4 +41,5 @@ public class JmxProperties { public void setStep(Duration step) { this.step = step; } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapter.java index 1741a6496f..db39ef2824 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapter.java @@ -35,7 +35,7 @@ class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter } @Override - public String get(String k) { + public String get(String key) { return null; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java index d17f60019b..afcf3df8e3 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.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/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfiguration.java index accc1517b9..a2be93b9d2 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfiguration.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/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementContextAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementContextAutoConfiguration.java index b4b480c33d..25b48da8cf 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementContextAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementContextAutoConfiguration.java @@ -26,7 +26,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** - * {@link EnableAutoConfiguration Auto-configuration} for Servlet-specific management + * {@link EnableAutoConfiguration Auto-configuration} for Reactive-specific management * context concerns. * * @author Phillip Webb diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfigurationTests.java index 129db56741..d92518bb92 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfigurationTests.java @@ -42,7 +42,6 @@ public class RabbitMetricsConfigurationTests { RabbitAutoConfiguration.class)) .withPropertyValues("management.metrics.use-global-registry=false"); - @Test public void autoConfiguredConnectionFactoryIsInstrumented() { this.contextRunner.run((context) -> { @@ -67,14 +66,14 @@ public class RabbitMetricsConfigurationTests { @Test public void rabbitmqNativeConnectionFactoryInstrumentationCanBeDisabled() { this.contextRunner - .withPropertyValues( - "management.metrics.rabbitmq.instrument=false").run((context) -> { - MeterRegistry registry = context.getBean(MeterRegistry.class); - assertThat(registry.find("rabbitmq.connections").meter()).isNotPresent(); - }); + .withPropertyValues("management.metrics.rabbitmq.instrument=false") + .run((context) -> { + MeterRegistry registry = context.getBean(MeterRegistry.class); + assertThat(registry.find("rabbitmq.connections").meter()) + .isNotPresent(); + }); } - @Configuration static class RegistryConfiguration { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequestTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequestTests.java index 026e9214b6..53bdcef796 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequestTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequestTests.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/src/main/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetrics.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetrics.java index 6b663b45d6..a83dfc3830 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetrics.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetrics.java @@ -42,7 +42,7 @@ public class RabbitMetrics implements MeterBinder { private final ConnectionFactory connectionFactory; /** - * Create a new meter binder recording the specified {@link ConnectionFactory}. + * Create a new meter binder recording the specified {@link ConnectionFactory}. * @param connectionFactory the {@link ConnectionFactory} to instrument * @param name the name prefix of the metrics * @param tags tags to apply to all recorded metrics @@ -53,13 +53,13 @@ public class RabbitMetrics implements MeterBinder { Assert.notNull(name, "Name must not be null"); this.connectionFactory = connectionFactory; this.name = name; - this.tags = (tags != null ? tags : Collections.EMPTY_LIST); + this.tags = (tags != null ? tags : Collections.emptyList()); } @Override public void bindTo(MeterRegistry registry) { - this.connectionFactory.setMetricsCollector(new MicrometerMetricsCollector( - registry, this.name, this.tags)); + this.connectionFactory.setMetricsCollector( + new MicrometerMetricsCollector(registry, this.name, this.tags)); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java index 51e3edd565..621861abba 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java @@ -45,10 +45,10 @@ public class RabbitMetricsTests { SimpleMeterRegistry registry = new SimpleMeterRegistry(); new RabbitMetrics(connectionFactory, "test", Tags.zip("env", "prod")) .bindTo(registry); - assertThat(registry.find("test.connections") - .tags("env", "prod").meter()).isPresent(); - assertThat(registry.find("test.connections") - .tags("env", "dev").meter()).isNotPresent(); + assertThat(registry.find("test.connections").tags("env", "prod").meter()) + .isPresent(); + assertThat(registry.find("test.connections").tags("env", "dev").meter()) + .isNotPresent(); } private ConnectionFactory mockConnectionFactory() { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java index ab9fd4d1e7..d3920717d2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.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/StaticResourceRequest.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/StaticResourceRequest.java index ef37eb852d..8710c1a94a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/StaticResourceRequest.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/StaticResourceRequest.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/web/embedded/jetty/JettyCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/jetty/JettyCustomizer.java index c9a132da4d..aab35adf26 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/jetty/JettyCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/jetty/JettyCustomizer.java @@ -62,7 +62,6 @@ public final class JettyCustomizer { if (jettyProperties.getMaxHttpPostSize() > 0) { customizeMaxHttpPostSize(factory, jettyProperties.getMaxHttpPostSize()); } - if (serverProperties.getConnectionTimeout() != null) { customizeConnectionTimeout(factory, serverProperties.getConnectionTimeout()); } @@ -176,4 +175,5 @@ public final class JettyCustomizer { server.setRequestLog(log); }); } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/tomcat/TomcatCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/tomcat/TomcatCustomizer.java index 1f20e8a584..f5b8291322 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/tomcat/TomcatCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/tomcat/TomcatCustomizer.java @@ -197,7 +197,6 @@ public final class TomcatCustomizer { private static void customizeAccessLog(ServerProperties.Tomcat tomcatProperties, ConfigurableTomcatWebServerFactory factory) { - AccessLogValve valve = new AccessLogValve(); valve.setPattern(tomcatProperties.getAccesslog().getPattern()); valve.setDirectory(tomcatProperties.getAccesslog().getDirectory()); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/undertow/UndertowCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/undertow/UndertowCustomizer.java index 7467738957..09a9ea76b1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/undertow/UndertowCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/undertow/UndertowCustomizer.java @@ -38,7 +38,6 @@ public final class UndertowCustomizer { public static void customizeUndertow(ServerProperties serverProperties, Environment environment, ConfigurableUndertowWebServerFactory factory) { - ServerProperties.Undertow undertowProperties = serverProperties.getUndertow(); ServerProperties.Undertow.Accesslog accesslogProperties = undertowProperties .getAccesslog(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerAutoConfiguration.java index 574123a291..1e9d264389 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerAutoConfiguration.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/web/servlet/WebMvcProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java index 27555b92c0..aa9a0429fa 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java @@ -327,6 +327,7 @@ public class WebMvcProperties { public void setParameterName(String parameterName) { this.parameterName = parameterName; } + } public static class PathMatch { @@ -360,6 +361,7 @@ public class WebMvcProperties { public void setUseRegisteredSuffixPattern(boolean useRegisteredSuffixPattern) { this.useRegisteredSuffixPattern = useRegisteredSuffixPattern; } + } public enum LocaleResolver { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java index 4aaa2661ea..5cc2a40009 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java @@ -238,22 +238,21 @@ public class ErrorMvcAutoConfiguration { if (response.getContentType() == null) { response.setContentType(getContentType()); } - PlaceholderResolver resolver = new ExpressionResolver(getExpressions(), model); + PlaceholderResolver resolver = new ExpressionResolver(getExpressions(), + model); String result = this.helper.replacePlaceholders(this.template, resolver); response.getWriter().append(result); } private String getMessage(Map model) { - StringBuilder builder = new StringBuilder(); - builder.append("Cannot render error page for request [") - .append(model.get("path")).append("]"); + Object path = model.get("path"); + String message = "Cannot render error page for request [" + path + "]"; if (model.get("message") != null) { - builder.append(" and exception [").append(model.get("message")) - .append("]"); + message += " and exception [" + model.get("message") + "]"; } - return builder.append("] as the response has already been committed.") - .append("As a result, the response may have the wrong status code.") - .toString(); + message += " as the response has already been committed."; + message += " As a result, the response may have the wrong status code."; + return message; } private Map getExpressions() { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfigurationTests.java index b9b44cbfc7..562b934057 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfigurationTests.java @@ -25,12 +25,11 @@ import org.springframework.boot.test.rule.OutputCapture; import org.springframework.boot.web.servlet.error.ErrorAttributes; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.web.context.request.WebRequest; +import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.servlet.View; import org.springframework.web.servlet.handler.DispatcherServletWebRequest; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.containsString; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link ErrorMvcAutoConfiguration}. @@ -50,26 +49,31 @@ public class ErrorMvcAutoConfigurationTests { this.contextRunner.run((context) -> { View errorView = context.getBean("error", View.class); ErrorAttributes errorAttributes = context.getBean(ErrorAttributes.class); - DispatcherServletWebRequest webRequest = - createCommittedWebRequest(new IllegalStateException("Exception message")); + DispatcherServletWebRequest webRequest = createCommittedWebRequest( + new IllegalStateException("Exception message")); errorView.render(errorAttributes.getErrorAttributes(webRequest, true), webRequest.getRequest(), webRequest.getResponse()); - this.outputCapture.expect(allOf( - containsString("Cannot render error page for request [/path]" + - " and exception [Exception message]] as the response has already been committed."), - containsString("As a result, the response may have the wrong status code."))); + assertThat(this.outputCapture.toString()) + .contains("Cannot render error page for request [/path] " + + "and exception [Exception message] as the response has " + + "already been committed. As a result, the response may " + + "have the wrong status code."); }); } - protected DispatcherServletWebRequest createCommittedWebRequest(Exception e) { + protected DispatcherServletWebRequest createCommittedWebRequest(Exception ex) { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/path"); MockHttpServletResponse response = new MockHttpServletResponse(); - DispatcherServletWebRequest webRequest = new DispatcherServletWebRequest(request, response); - webRequest.setAttribute("javax.servlet.error.exception", e, WebRequest.SCOPE_REQUEST); - webRequest.setAttribute("javax.servlet.error.request_uri", "/path", WebRequest.SCOPE_REQUEST); + DispatcherServletWebRequest webRequest = new DispatcherServletWebRequest(request, + response); + webRequest.setAttribute("javax.servlet.error.exception", ex, + RequestAttributes.SCOPE_REQUEST); + webRequest.setAttribute("javax.servlet.error.request_uri", "/path", + RequestAttributes.SCOPE_REQUEST); response.setCommitted(true); response.setOutputStreamAccessAllowed(false); response.setWriterAccessAllowed(false); return webRequest; } + } diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ServiceCapabilitiesReportGenerator.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ServiceCapabilitiesReportGenerator.java index 11e6bf13b0..b462a4fe28 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ServiceCapabilitiesReportGenerator.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ServiceCapabilitiesReportGenerator.java @@ -36,6 +36,8 @@ import java.util.TreeSet; */ class ServiceCapabilitiesReportGenerator { + private static final String NEW_LINE = System.lineSeparator(); + private final InitializrService initializrService; /** @@ -64,29 +66,29 @@ class ServiceCapabilitiesReportGenerator { private String generateHelp(String url, InitializrServiceMetadata metadata) { String header = "Capabilities of " + url; StringBuilder report = new StringBuilder(); - report.append(repeat("=", header.length()) + System.lineSeparator()); - report.append(header + System.lineSeparator()); - report.append(repeat("=", header.length()) + System.lineSeparator()); - report.append(System.lineSeparator()); + report.append(repeat("=", header.length()) + NEW_LINE); + report.append(header + NEW_LINE); + report.append(repeat("=", header.length()) + NEW_LINE); + report.append(NEW_LINE); reportAvailableDependencies(metadata, report); - report.append(System.lineSeparator()); + report.append(NEW_LINE); reportAvailableProjectTypes(metadata, report); - report.append(System.lineSeparator()); + report.append(NEW_LINE); reportDefaults(report, metadata); return report.toString(); } private void reportAvailableDependencies(InitializrServiceMetadata metadata, StringBuilder report) { - report.append("Available dependencies:" + System.lineSeparator()); - report.append("-----------------------" + System.lineSeparator()); + report.append("Available dependencies:" + NEW_LINE); + report.append("-----------------------" + NEW_LINE); List dependencies = getSortedDependencies(metadata); for (Dependency dependency : dependencies) { report.append(dependency.getId() + " - " + dependency.getName()); if (dependency.getDescription() != null) { report.append(": " + dependency.getDescription()); } - report.append(System.lineSeparator()); + report.append(NEW_LINE); } } @@ -98,8 +100,8 @@ class ServiceCapabilitiesReportGenerator { private void reportAvailableProjectTypes(InitializrServiceMetadata metadata, StringBuilder report) { - report.append("Available project types:" + System.lineSeparator()); - report.append("------------------------" + System.lineSeparator()); + report.append("Available project types:" + NEW_LINE); + report.append("------------------------" + NEW_LINE); SortedSet> entries = new TreeSet<>( Comparator.comparing(Entry::getKey)); entries.addAll(metadata.getProjectTypes().entrySet()); @@ -112,7 +114,7 @@ class ServiceCapabilitiesReportGenerator { if (type.isDefaultType()) { report.append(" (default)"); } - report.append(System.lineSeparator()); + report.append(NEW_LINE); } } @@ -132,13 +134,13 @@ class ServiceCapabilitiesReportGenerator { private void reportDefaults(StringBuilder report, InitializrServiceMetadata metadata) { - report.append("Defaults:" + System.lineSeparator()); - report.append("---------" + System.lineSeparator()); + report.append("Defaults:" + NEW_LINE); + report.append("---------" + NEW_LINE); List defaultsKeys = new ArrayList<>(metadata.getDefaults().keySet()); Collections.sort(defaultsKeys); for (String defaultsKey : defaultsKeys) { String defaultsValue = metadata.getDefaults().get(defaultsKey); - report.append(defaultsKey + ": " + defaultsValue + System.lineSeparator()); + report.append(defaultsKey + ": " + defaultsValue + NEW_LINE); } } diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java index dbf06c0c62..175a2eb6a6 100755 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.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-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index b5b811fad6..08bd0a9af8 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -2939,8 +2939,10 @@ for the properties of the user). * Form-based login or HTTP Basic security (depending on Content-Type) for the entire application (including actuator endpoints if actuator is on the classpath). -== MVC Security + +[[boot-features-security-mvc]] +== MVC Security The default security configuration is implemented in `SecurityAutoConfiguration` and in the classes imported from there (`SpringBootWebSecurityConfiguration` for web security and `AuthenticationManagerConfiguration` for authentication configuration, which is also @@ -2960,8 +2962,10 @@ that is based on the `management.endpoints.web.base-path` property. `StaticResourceRequest` can be used to create a `RequestMatcher` for static resources in commonly used locations. -== WebFlux Security + +[[boot-features-security-webflux]] +== WebFlux Security The default security configuration is implemented in `ReactiveSecurityAutoConfiguration` and in the classes imported from there (`WebFluxSecurityConfiguration` for web security and `ReactiveAuthenticationManagerConfiguration` for authentication configuration, which is also @@ -2977,12 +2981,15 @@ Boot provides convenience methods that can be used to override access rules for endpoints and static resources. `EndpointRequest` can be used to create a `ServerWebExchangeMatcher` that is based on the `management.endpoints.web.base-path` property. + + [[boot-features-security-oauth2]] === OAuth2 - https://oauth.net/2/[OAuth2] is a widely used authorization framework that is supported by Spring. + +[[boot-features-security-oauth2-client]] ==== Client If you have `spring-security-oauth2-client` on your classpath, you can take advantage of some auto-configuration to make it easy to set up an OAuth2 Client. This configuration diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/test/web/RandomPortTestRestTemplateExampleTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/test/web/RandomPortTestRestTemplateExampleTests.java index e7d361e0de..d712c7056a 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/test/web/RandomPortTestRestTemplateExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/test/web/RandomPortTestRestTemplateExampleTests.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-test/src/test/java/org/springframework/boot/test/context/bootstrap/SpringBootTestContextBootstrapperIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/SpringBootTestContextBootstrapperIntegrationTests.java index 338267df92..d66f1b1834 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/SpringBootTestContextBootstrapperIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/SpringBootTestContextBootstrapperIntegrationTests.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-test/src/test/java/org/springframework/boot/test/context/bootstrap/SpringBootTestContextBootstrapperWithContextConfigurationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/SpringBootTestContextBootstrapperWithContextConfigurationTests.java index 80475ca2ff..207810b1cb 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/SpringBootTestContextBootstrapperWithContextConfigurationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/SpringBootTestContextBootstrapperWithContextConfigurationTests.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-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/DescriptionExtractorTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/DescriptionExtractorTests.java index b15df58936..ed42644fe6 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/DescriptionExtractorTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/DescriptionExtractorTests.java @@ -27,6 +27,8 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class DescriptionExtractorTests { + private static final String NEW_LINE = System.lineSeparator(); + private DescriptionExtractor extractor = new DescriptionExtractor(); @Test @@ -39,16 +41,14 @@ public class DescriptionExtractorTests { @Test public void extractShortDescriptionNewLineBeforeDot() { String description = this.extractor.getShortDescription( - "My short" + System.lineSeparator() + "description." - + System.lineSeparator() + "More stuff."); + "My short" + NEW_LINE + "description." + NEW_LINE + "More stuff."); assertThat(description).isEqualTo("My short description."); } @Test public void extractShortDescriptionNewLineBeforeDotWithSpaces() { String description = this.extractor.getShortDescription( - "My short " + System.lineSeparator() + " description. " - + System.lineSeparator() + "More stuff."); + "My short " + NEW_LINE + " description. " + NEW_LINE + "More stuff."); assertThat(description).isEqualTo("My short description."); } @@ -61,8 +61,7 @@ public class DescriptionExtractorTests { @Test public void extractShortDescriptionNoDotMultipleLines() { String description = this.extractor - .getShortDescription("My short description " + System.lineSeparator() - + " More stuff"); + .getShortDescription("My short description " + NEW_LINE + " More stuff"); assertThat(description).isEqualTo("My short description"); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/specific/AnnotatedGetter.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/specific/AnnotatedGetter.java index 2e1872f837..c6c12e0ac6 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/specific/AnnotatedGetter.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/specific/AnnotatedGetter.java @@ -21,8 +21,8 @@ import javax.validation.constraints.NotEmpty; import org.springframework.boot.configurationsample.ConfigurationProperties; /** - * An annotated getter with {@code NotEmpty} that triggers a different class type - * in the compiler. See #11512 + * An annotated getter with {@code NotEmpty} that triggers a different class type in the + * compiler. See #11512 * * @author Stephane Nicoll */ diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java index 5cb0987d80..cbe347be07 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.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/logging/logback/DefaultLogbackConfiguration.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java index d0d29b0269..c7af583b71 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.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/security/reactive/ApplicationContextServerWebExchangeMatcher.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/reactive/ApplicationContextServerWebExchangeMatcher.java index f75c2856a9..1b95e3d85a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/reactive/ApplicationContextServerWebExchangeMatcher.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/reactive/ApplicationContextServerWebExchangeMatcher.java @@ -85,9 +85,7 @@ public abstract class ApplicationContextServerWebExchangeMatcher @SuppressWarnings("unchecked") private C createContext(ServerWebExchange exchange) { ApplicationContext context = exchange.getApplicationContext(); - if (context == null) { - throw new IllegalStateException("No WebApplicationContext found."); - } + Assert.state(context != null, "No WebApplicationContext found."); if (this.contextClass.isInstance(context)) { return (C) context; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/servlet/ApplicationContextRequestMatcher.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/servlet/ApplicationContextRequestMatcher.java index ac2ac2f688..deeff4869f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/servlet/ApplicationContextRequestMatcher.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/servlet/ApplicationContextRequestMatcher.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/web/embedded/jetty/ForwardHeadersCustomizer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/ForwardHeadersCustomizer.java index 7b40e50b28..9b0911ae5a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/ForwardHeadersCustomizer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/ForwardHeadersCustomizer.java @@ -24,6 +24,7 @@ import org.eclipse.jetty.server.Server; /** * {@link JettyServerCustomizer} to add {@link ForwardedRequestCustomizer}. + * * @author Phillip Webb */ class ForwardHeadersCustomizer implements JettyServerCustomizer { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyHandlerWrappers.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyHandlerWrappers.java index c3b4449a2c..d0cab9866f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyHandlerWrappers.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyHandlerWrappers.java @@ -79,4 +79,5 @@ final class JettyHandlerWrappers { } } + } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java index 997e0e8152..b519f31082 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java @@ -234,8 +234,7 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor SessionHandler handler = context.getSessionHandler(); Duration sessionTimeout = getSession().getTimeout(); handler.setMaxInactiveInterval( - (sessionTimeout == null || sessionTimeout.isNegative()) ? -1 - : (int) sessionTimeout.getSeconds()); + isNegative(sessionTimeout) ? -1 : (int) sessionTimeout.getSeconds()); if (getSession().isPersistent()) { DefaultSessionCache cache = new DefaultSessionCache(handler); FileSessionDataStore store = new FileSessionDataStore(); @@ -245,6 +244,10 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor } } + private boolean isNegative(Duration sessionTimeout) { + return sessionTimeout == null || sessionTimeout.isNegative(); + } + private void addLocaleMappings(WebAppContext context) { for (Map.Entry entry : getLocaleCharsetMappings().entrySet()) { Locale locale = entry.getKey(); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/SslServerCustomizer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/SslServerCustomizer.java index f05c53684e..929fa29f31 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/SslServerCustomizer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/SslServerCustomizer.java @@ -135,4 +135,5 @@ public class SslServerCustomizer implements NettyServerCustomizer { store.load(url.openStream(), password == null ? null : password.toCharArray()); return store; } + } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatConnectorCustomizer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatConnectorCustomizer.java index 4437c72ea8..c11061b83b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatConnectorCustomizer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatConnectorCustomizer.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/web/embedded/tomcat/TomcatServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java index 17ed0470cd..37ea7c5668 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java @@ -386,13 +386,17 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto private long getSessionTimeoutInMinutes() { Duration sessionTimeout = getSession().getTimeout(); - if (sessionTimeout == null || sessionTimeout.isNegative() - || sessionTimeout.isZero()) { + if (isZeroOrLess(sessionTimeout)) { return 0; } return Math.max(sessionTimeout.toMinutes(), 1); } + private boolean isZeroOrLess(Duration sessionTimeout) { + return sessionTimeout == null || sessionTimeout.isNegative() + || sessionTimeout.isZero(); + } + /** * Post process the Tomcat {@link Context} before it's used with the Tomcat Server. * Subclasses can override this method to apply additional processing to the diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java index 1608848147..8a992794ee 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java @@ -283,13 +283,17 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac manager.deploy(); SessionManager sessionManager = manager.getDeployment().getSessionManager(); Duration timeoutDuration = getSession().getTimeout(); - int sessionTimeout = (timeoutDuration == null || timeoutDuration.isZero() - || timeoutDuration.isNegative() ? -1 - : (int) timeoutDuration.getSeconds()); + int sessionTimeout = (isZeroOrLess(timeoutDuration) ? -1 + : (int) timeoutDuration.getSeconds()); sessionManager.setDefaultSessionTimeout(sessionTimeout); return manager; } + private boolean isZeroOrLess(Duration timeoutDuration) { + return timeoutDuration == null || timeoutDuration.isZero() + || timeoutDuration.isNegative(); + } + private void configureAccessLog(DeploymentInfo deploymentInfo) { deploymentInfo.addInitialHandlerChainWrapper(this::createAccessLogHandler); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ConfigurableServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ConfigurableServletWebServerFactory.java index 7c7e7ec311..1f4b12b99f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ConfigurableServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ConfigurableServletWebServerFactory.java @@ -62,31 +62,10 @@ public interface ConfigurableServletWebServerFactory /** * Sets the configuration that will be applied to the container's HTTP session * support. - * * @param session the session configuration */ void setSession(Session session); - // /** - // * The session timeout in seconds (default 30 minutes). If {@code null} then - // sessions - // * never expire. - // * @param sessionTimeout the session timeout - // */ - // void setSessionTimeout(Duration sessionTimeout); - // - // /** - // * Sets if session data should be persisted between restarts. - // * @param persistSession {@code true} if session data should be persisted - // */ - // void setPersistSession(boolean persistSession); - // - // /** - // * Set the directory used to store serialized session data. - // * @param sessionStoreDir the directory or {@code null} to use a default location. - // */ - // void setSessionStoreDir(File sessionStoreDir); - /** * Set if the DefaultServlet should be registered. Defaults to {@code true} so that * files from the {@link #setDocumentRoot(File) document root} will be served. @@ -141,7 +120,6 @@ public interface ConfigurableServletWebServerFactory /** * Sets the init parameters that are applied to the container's * {@link ServletContext}. - * * @param initParameters the init parameters */ void setInitParameters(Map initParameters); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/Session.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/Session.java index 8c4073d236..3868481395 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/Session.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/Session.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/security/servlet/ApplicationContextRequestMatcherTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/security/servlet/ApplicationContextRequestMatcherTests.java index eb656ead81..e1101c6ad4 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/security/servlet/ApplicationContextRequestMatcherTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/security/servlet/ApplicationContextRequestMatcherTests.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/web/embedded/jetty/JettyServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java index e96f2ae51f..f64003a5bc 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.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/web/reactive/server/AbstractReactiveWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java index a81c253f6b..8043c46bbc 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java @@ -156,7 +156,6 @@ public abstract class AbstractReactiveWebServerFactoryTests { ssl.setKeyStore("classpath:test.jks"); ssl.setKeyPassword("password"); ssl.setTrustStore("classpath:test.jks"); - testClientAuthSuccess(ssl, buildTrustAllSslWithClientKeyConnector()); } @@ -168,7 +167,6 @@ public abstract class AbstractReactiveWebServerFactoryTests { ssl.setKeyStore("classpath:test.jks"); ssl.setKeyPassword("password"); ssl.setTrustStore("classpath:test.jks"); - testClientAuthSuccess(ssl, buildTrustAllSslConnector()); } @@ -192,10 +190,8 @@ public abstract class AbstractReactiveWebServerFactoryTests { ReactorClientHttpConnector clientConnector) { AbstractReactiveWebServerFactory factory = getFactory(); factory.setSsl(sslConfiguration); - this.webServer = factory.getWebServer(new EchoHandler()); this.webServer.start(); - WebClient client = WebClient.builder() .baseUrl("https://localhost:" + this.webServer.getPort()) .clientConnector(clientConnector).build(); @@ -213,7 +209,6 @@ public abstract class AbstractReactiveWebServerFactoryTests { ssl.setKeyStore("classpath:test.jks"); ssl.setKeyPassword("password"); ssl.setTrustStore("classpath:test.jks"); - testClientAuthSuccess(ssl, buildTrustAllSslWithClientKeyConnector()); } @@ -228,7 +223,6 @@ public abstract class AbstractReactiveWebServerFactoryTests { ssl.setKeyStore("classpath:test.jks"); ssl.setKeyPassword("password"); ssl.setTrustStore("classpath:test.jks"); - testClientAuthFailure(ssl, buildTrustAllSslConnector()); } @@ -236,17 +230,14 @@ public abstract class AbstractReactiveWebServerFactoryTests { ReactorClientHttpConnector clientConnector) { AbstractReactiveWebServerFactory factory = getFactory(); factory.setSsl(sslConfiguration); - this.webServer = factory.getWebServer(new EchoHandler()); this.webServer.start(); - WebClient client = WebClient.builder() .baseUrl("https://localhost:" + this.webServer.getPort()) .clientConnector(clientConnector).build(); Mono result = client.post().uri("/test").contentType(MediaType.TEXT_PLAIN) .body(BodyInserters.fromObject("Hello World")).exchange() .flatMap((response) -> response.bodyToMono(String.class)); - StepVerifier.create(result).expectError(SSLException.class) .verify(Duration.ofSeconds(10)); } @@ -372,6 +363,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { } ctx.fireChannelRead(msg); } + } protected static class CharsHandler implements HttpHandler { @@ -395,6 +387,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { response.getHeaders().setContentType(this.mediaType); return response.writeWith(Mono.just(this.bytes)); } + } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java index 8dda195c11..7900734787 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java @@ -999,15 +999,6 @@ public abstract class AbstractServletWebServerFactoryTests { @Test public void sessionConfiguration() { AbstractServletWebServerFactory factory = getFactory(); - // map.put("server.servlet.session.timeout", "123"); - // map.put("server.servlet.session.tracking-modes", "cookie,url"); - // map.put("server.servlet.session.cookie.name", "testname"); - // map.put("server.servlet.session.cookie.domain", "testdomain"); - // map.put("server.servlet.session.cookie.path", "/testpath"); - // map.put("server.servlet.session.cookie.comment", "testcomment"); - // map.put("server.servlet.session.cookie.http-only", "true"); - // map.put("server.servlet.session.cookie.secure", "true"); - // map.put("server.servlet.session.cookie.max-age", "60"); factory.getSession().setTimeout(Duration.ofSeconds(123)); factory.getSession().setTrackingModes( EnumSet.of(SessionTrackingMode.COOKIE, SessionTrackingMode.URL)); @@ -1035,7 +1026,6 @@ public abstract class AbstractServletWebServerFactoryTests { assertThat(servletContext.getSessionCookieConfig().isHttpOnly()).isTrue(); assertThat(servletContext.getSessionCookieConfig().isSecure()).isTrue(); assertThat(servletContext.getSessionCookieConfig().getMaxAge()).isEqualTo(60); - } protected abstract void addConnector(int port, diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java index 945d6ebb81..7ffe5a844e 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.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-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java b/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java index 670124b8ee..e9f0ffd8a7 100644 --- a/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java +++ b/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java @@ -41,7 +41,8 @@ import org.springframework.test.web.reactive.server.WebTestClient; * @author Madhura Bhave */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { SampleSecureWebFluxCustomSecurityTests.SecurityConfiguration.class, +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { + SampleSecureWebFluxCustomSecurityTests.SecurityConfiguration.class, SampleSecureWebFluxApplication.class }) public class SampleSecureWebFluxCustomSecurityTests { @@ -61,7 +62,7 @@ public class SampleSecureWebFluxCustomSecurityTests { this.webClient.get().uri("/actuator/info").accept(MediaType.APPLICATION_JSON) .exchange().expectStatus().isOk(); } - + @Test public void actuatorsSecuredByRole() { this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON) @@ -82,22 +83,18 @@ public class SampleSecureWebFluxCustomSecurityTests { @Bean public MapReactiveUserDetailsService userDetailsService() { return new MapReactiveUserDetailsService( - User.withDefaultPasswordEncoder().username("user").password("password") - .authorities("ROLE_USER").build(), + User.withDefaultPasswordEncoder().username("user") + .password("password").authorities("ROLE_USER").build(), User.withDefaultPasswordEncoder().username("admin").password("admin") .authorities("ROLE_ACTUATOR", "ROLE_USER").build()); } @Bean SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { - http - .authorizeExchange() - .matchers(EndpointRequest.to("health", "info")).permitAll() - .matchers(EndpointRequest.toAnyEndpoint()).hasRole("ACTUATOR") - .pathMatchers("/login").permitAll() - .anyExchange().authenticated() - .and() - .httpBasic(); + http.authorizeExchange().matchers(EndpointRequest.to("health", "info")) + .permitAll().matchers(EndpointRequest.toAnyEndpoint()) + .hasRole("ACTUATOR").pathMatchers("/login").permitAll().anyExchange() + .authenticated().and().httpBasic(); return http.build(); } @@ -112,4 +109,3 @@ public class SampleSecureWebFluxCustomSecurityTests { } } - diff --git a/spring-boot-samples/spring-boot-sample-session/src/test/java/sample/session/SampleSessionApplicationTests.java b/spring-boot-samples/spring-boot-sample-session/src/test/java/sample/session/SampleSessionApplicationTests.java index 7af40b0e30..0a431da7be 100644 --- a/spring-boot-samples/spring-boot-sample-session/src/test/java/sample/session/SampleSessionApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-session/src/test/java/sample/session/SampleSessionApplicationTests.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-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.java b/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.java index 6789e3fcb1..94a7e433b1 100644 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.java +++ b/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.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.