diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ConditionalOnManagementPort.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ConditionalOnManagementPort.java index c50013fce0..2871986475 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ConditionalOnManagementPort.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ConditionalOnManagementPort.java @@ -26,6 +26,8 @@ import org.springframework.context.annotation.Conditional; /** * {@link Conditional} that matches based on the configuration of the management port. + * + * @since 2.0.0 */ @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.TYPE, ElementType.METHOD }) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EnableManagementContext.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EnableManagementContext.java index 807538075a..b487af37b7 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EnableManagementContext.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EnableManagementContext.java @@ -35,6 +35,10 @@ import org.springframework.context.annotation.Import; @Import(ManagementContextConfigurationImportSelector.class) @interface EnableManagementContext { + /** + * The management context type that should be enabled. + * @return the management context type + */ ManagementContextType value(); } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextAutoConfiguration.java index f08e9ae7cb..98a2eac0d2 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextAutoConfiguration.java @@ -37,6 +37,7 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; import org.springframework.core.env.PropertySource; import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.util.Assert; import org.springframework.web.context.ConfigurableWebApplicationContext; /** @@ -58,7 +59,7 @@ public class ManagementContextAutoConfiguration { @Bean public ManagementServletContext managementServletContext( - final ManagementServerProperties properties) { + ManagementServerProperties properties) { return () -> properties.getContextPath(); } @@ -86,12 +87,11 @@ public class ManagementContextAutoConfiguration { } private void verifySslConfiguration() { - if (this.environment.getProperty("management.ssl.enabled", Boolean.class, - false)) { - throw new IllegalStateException( - "Management-specific SSL cannot be configured as the management " - + "server is not listening on a separate port"); - } + Boolean enabled = this.environment.getProperty("management.ssl.enabled", + Boolean.class, false); + Assert.state(!enabled, + "Management-specific SSL cannot be configured as the management " + + "server is not listening on a separate port"); } private void verifyContextPathConfiguration() { @@ -112,6 +112,7 @@ public class ManagementContextAutoConfiguration { ConfigurableEnvironment environment) { environment.getPropertySources() .addLast(new PropertySource("Management Server") { + @Override public Object getProperty(String name) { if ("local.management.port".equals(name)) { @@ -119,6 +120,7 @@ public class ManagementContextAutoConfiguration { } return null; } + }); } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextConfigurationImportSelector.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextConfigurationImportSelector.java index 6ce1ae8524..1b90fa0991 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextConfigurationImportSelector.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextConfigurationImportSelector.java @@ -122,8 +122,8 @@ class ManagementContextConfigurationImportSelector Map annotationAttributes = annotationMetadata .getAnnotationAttributes( ManagementContextConfiguration.class.getName()); - return annotationAttributes == null ? ManagementContextType.ANY - : (ManagementContextType) annotationAttributes.get("value"); + return (annotationAttributes == null ? ManagementContextType.ANY + : (ManagementContextType) annotationAttributes.get("value")); } private int readOrder(AnnotationMetadata annotationMetadata) { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextFactory.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextFactory.java index fe054240d6..91154ca6e8 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextFactory.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextFactory.java @@ -27,7 +27,13 @@ import org.springframework.context.ConfigurableApplicationContext; */ interface ManagementContextFactory { + /** + * Create the management application context. + * @param parent the parent context + * @param configurationClasses the configuration classes + * @return a configured application context + */ ConfigurableApplicationContext createManagementContext(ApplicationContext parent, - Class... configClasses); + Class... configurationClasses); } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementPortType.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementPortType.java index 5fd8b57a63..7a90f8fd98 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementPortType.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementPortType.java @@ -18,6 +18,12 @@ package org.springframework.boot.actuate.autoconfigure; import org.springframework.core.env.Environment; +/** + * Port types that can be used to control how the management server is started. + * + * @author Andy Wilkinson + * @since 2.0.0 + */ public enum ManagementPortType { /** diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.java index a935c6f945..b00b90da6b 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.java @@ -78,8 +78,8 @@ import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping; * @author EddĂș MelĂ©ndez * @author Meang Akira Tanaka * @author Ben Hale - * @since 2.0.0 * @author Andy Wilkinson + * @since 2.0.0 */ @Configuration @AutoConfigureAfter({ FlywayAutoConfiguration.class, LiquibaseAutoConfiguration.class }) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/ManagementEndpointPathResolver.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/ManagementEndpointPathResolver.java index 4281204d2b..c14c6655b8 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/ManagementEndpointPathResolver.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/ManagementEndpointPathResolver.java @@ -20,8 +20,8 @@ import org.springframework.boot.actuate.autoconfigure.web.ManagementServerProper import org.springframework.boot.endpoint.EndpointPathResolver; /** - * {@link EndpointPathResolver} implementation for resolving - * actuator endpoint paths based on the endpoint id and management.context-path. + * {@link EndpointPathResolver} implementation for resolving actuator endpoint paths based + * on the endpoint id and management.context-path. * * @author Madhura Bhave * @since 2.0.0 @@ -38,5 +38,5 @@ public class ManagementEndpointPathResolver implements EndpointPathResolver { public String resolvePath(String endpointId) { return this.contextPath + "/" + endpointId; } -} +} diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/DefaultEndpointObjectNameFactory.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/DefaultEndpointObjectNameFactory.java index 3cfc0835b8..04f8eea305 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/DefaultEndpointObjectNameFactory.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/DefaultEndpointObjectNameFactory.java @@ -51,9 +51,8 @@ class DefaultEndpointObjectNameFactory implements EndpointObjectNameFactory { @Override public ObjectName generate(EndpointMBean mBean) throws MalformedObjectNameException { - String baseObjectName = this.properties.getDomain() + - ":type=Endpoint" + - ",name=" + StringUtils.capitalize(mBean.getEndpointId()); + String baseObjectName = this.properties.getDomain() + ":type=Endpoint" + ",name=" + + StringUtils.capitalize(mBean.getEndpointId()); StringBuilder builder = new StringBuilder(baseObjectName); if (this.mBeanServer != null && hasMBean(baseObjectName)) { builder.append(",context=").append(this.contextId); @@ -76,7 +75,8 @@ class DefaultEndpointObjectNameFactory implements EndpointObjectNameFactory { } StringBuilder builder = new StringBuilder(); - for (Map.Entry name : this.properties.getStaticNames().entrySet()) { + for (Map.Entry name : this.properties.getStaticNames() + .entrySet()) { builder.append(",").append(name.getKey()).append("=").append(name.getValue()); } return builder.toString(); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/EndpointInfrastructureAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/EndpointInfrastructureAutoConfiguration.java index 54aa880c1d..314e0cd8bf 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/EndpointInfrastructureAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/EndpointInfrastructureAutoConfiguration.java @@ -71,17 +71,20 @@ public class EndpointInfrastructureAutoConfiguration { @Bean public OperationParameterMapper operationParameterMapper() { DefaultConversionService conversionService = new DefaultConversionService(); - conversionService.addConverter(String.class, Date.class, (string) -> { - if (StringUtils.hasLength(string)) { - OffsetDateTime offsetDateTime = OffsetDateTime.parse(string, - DateTimeFormatter.ISO_OFFSET_DATE_TIME); - return new Date(offsetDateTime.toEpochSecond() * 1000); - } - return null; - }); + conversionService.addConverter(String.class, Date.class, this::convertToDate); return new ConversionServiceOperationParameterMapper(conversionService); } + private Date convertToDate(String value) { + if (StringUtils.hasLength(value)) { + OffsetDateTime offsetDateTime = OffsetDateTime.parse(value, + DateTimeFormatter.ISO_OFFSET_DATE_TIME); + return new Date(offsetDateTime.toEpochSecond() * 1000); + } + return null; + + } + @Bean public CachingConfigurationFactory cacheConfigurationFactory() { return new CachingConfigurationFactory(this.applicationContext.getEnvironment()); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/package-info.java index 41a0bc3f57..86b70679ca 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/package-info.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/package-info.java index 81e2f4611d..5adbb19815 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/package-info.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/support/EndpointEnablementProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/support/EndpointEnablementProvider.java index 7dd2db425c..ce16ca9927 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/support/EndpointEnablementProvider.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/support/EndpointEnablementProvider.java @@ -61,8 +61,9 @@ public class EndpointEnablementProvider { public EndpointEnablement getEndpointEnablement(String endpointId, boolean enabledByDefault, EndpointExposure exposure) { Assert.hasText(endpointId, "Endpoint id must have a value"); - Assert.isTrue(!endpointId.equals("default"), "Endpoint id 'default' is a reserved " - + "value and cannot be used by an endpoint"); + Assert.isTrue(!endpointId.equals("default"), + "Endpoint id 'default' is a reserved " + + "value and cannot be used by an endpoint"); EndpointEnablement result = findEnablement(endpointId, exposure); if (result != null) { return result; @@ -76,8 +77,7 @@ public class EndpointEnablementProvider { if (!enabledByDefault) { return getDefaultEndpointEnablement(endpointId, false, exposure); } - return getGlobalEndpointEnablement(endpointId, enabledByDefault, - exposure); + return getGlobalEndpointEnablement(endpointId, enabledByDefault, exposure); } private EndpointEnablement findEnablement(String endpointId, @@ -98,12 +98,10 @@ public class EndpointEnablementProvider { if (result != null) { return result; } - return getDefaultEndpointEnablement(endpointId, enabledByDefault, - exposure); + return getDefaultEndpointEnablement(endpointId, enabledByDefault, exposure); } - private EndpointEnablement findGlobalEndpointEnablement( - EndpointExposure exposure) { + private EndpointEnablement findGlobalEndpointEnablement(EndpointExposure exposure) { if (exposure != null) { EndpointEnablement result = findEnablement(getKey("default", exposure)); if (result != null) { @@ -136,8 +134,8 @@ public class EndpointEnablementProvider { private EndpointEnablement getDefaultEndpointEnablement(String endpointId, boolean enabledByDefault, EndpointExposure exposure) { - return new EndpointEnablement(enabledByDefault, createDefaultEnablementMessage( - endpointId, enabledByDefault, exposure)); + return new EndpointEnablement(enabledByDefault, + createDefaultEnablementMessage(endpointId, enabledByDefault, exposure)); } private String createDefaultEnablementMessage(String endpointId, @@ -145,8 +143,7 @@ public class EndpointEnablementProvider { StringBuilder message = new StringBuilder(); message.append(String.format("endpoint '%s' ", endpointId)); if (exposure != null) { - message.append( - String.format("(%s) ", exposure.name().toLowerCase())); + message.append(String.format("(%s) ", exposure.name().toLowerCase())); } message.append(String.format("is %s by default", (enabledByDefault ? "enabled" : "disabled"))); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/support/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/support/package-info.java index 0e7ec1a12f..4b486c1b16 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/support/package-info.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/support/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/package-info.java index 9873d97fab..5038da2660 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/package-info.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaManagementContextConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaManagementContextConfiguration.java index 1bbd03f10b..352d39757f 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaManagementContextConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaManagementContextConfiguration.java @@ -32,12 +32,10 @@ import org.springframework.web.servlet.mvc.ServletWrappingController; /** * {@link ManagementContextConfiguration} for embedding Jolokia, a JMX-HTTP bridge giving * an alternative to JSR-160 connectors. - * *

* This configuration will get automatically enabled as soon as the Jolokia * {@link AgentServlet} is on the classpath. To disable it set * {@code management.jolokia.enabled=false}. - * *

* Additional configuration parameters for Jolokia can be provided by specifying * {@code management.jolokia.config.*} properties. See the diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/security/ManagementWebSecurityAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/security/ManagementWebSecurityAutoConfiguration.java index f214879b15..d879cd92b4 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/security/ManagementWebSecurityAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/security/ManagementWebSecurityAutoConfiguration.java @@ -31,6 +31,7 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe * Security configuration for management endpoints. * * @author Madhura Bhave + * @since 2.0.0 */ @Configuration @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) @@ -39,9 +40,9 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe public class ManagementWebSecurityAutoConfiguration { @Bean - public EndpointPathResolver managementEndpointPathResolver(ManagementServerProperties properties) { + public EndpointPathResolver managementEndpointPathResolver( + ManagementServerProperties properties) { return new ManagementEndpointPathResolver(properties); } } - diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/AccessLevel.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/AccessLevel.java index 3aa73fa957..442e7bb0f2 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/AccessLevel.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/AccessLevel.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfiguration.java index bf1e66197d..964a64cd9f 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfiguration.java @@ -66,32 +66,33 @@ public class CloudFoundryActuatorAutoConfiguration { @Bean public CloudFoundryWebEndpointServletHandlerMapping cloudFoundryWebEndpointServletHandlerMapping( - EndpointProvider provider, - Environment environment, RestTemplateBuilder builder) { - CloudFoundryWebEndpointServletHandlerMapping handlerMapping = new CloudFoundryWebEndpointServletHandlerMapping( + EndpointProvider provider, Environment environment, + RestTemplateBuilder builder) { + return new CloudFoundryWebEndpointServletHandlerMapping( "/cloudfoundryapplication", provider.getEndpoints(), getCorsConfiguration(), getSecurityInterceptor(builder, environment)); - return handlerMapping; } private CloudFoundrySecurityInterceptor getSecurityInterceptor( RestTemplateBuilder restTemplateBuilder, Environment environment) { CloudFoundrySecurityService cloudfoundrySecurityService = getCloudFoundrySecurityService( restTemplateBuilder, environment); - TokenValidator tokenValidator = new TokenValidator(cloudfoundrySecurityService); - return new CloudFoundrySecurityInterceptor( - tokenValidator, cloudfoundrySecurityService, + TokenValidator tokenValidator = new TokenValidator( + cloudfoundrySecurityService); + return new CloudFoundrySecurityInterceptor(tokenValidator, + cloudfoundrySecurityService, environment.getProperty("vcap.application.application_id")); } private CloudFoundrySecurityService getCloudFoundrySecurityService( RestTemplateBuilder restTemplateBuilder, Environment environment) { - String cloudControllerUrl = environment.getProperty("vcap.application.cf_api"); + String cloudControllerUrl = environment + .getProperty("vcap.application.cf_api"); boolean skipSslValidation = environment.getProperty( "management.cloudfoundry.skip-ssl-validation", Boolean.class, false); - return cloudControllerUrl == null ? null - : new CloudFoundrySecurityService(restTemplateBuilder, cloudControllerUrl, - skipSslValidation); + return (cloudControllerUrl == null ? null + : new CloudFoundrySecurityService(restTemplateBuilder, + cloudControllerUrl, skipSslValidation)); } private CorsConfiguration getCorsConfiguration() { @@ -107,9 +108,9 @@ public class CloudFoundryActuatorAutoConfiguration { } /** - * {@link WebSecurityConfigurer} to tell Spring Security to - * ignore cloudfoundry specific paths. The Cloud foundry endpoints - * are protected by their own security interceptor. + * {@link WebSecurityConfigurer} to tell Spring Security to ignore cloudfoundry + * specific paths. The Cloud foundry endpoints are protected by their own security + * interceptor. */ @ConditionalOnClass(WebSecurity.class) @Order(SecurityProperties.IGNORED_ORDER) @@ -119,7 +120,8 @@ public class CloudFoundryActuatorAutoConfiguration { @Override public void init(WebSecurity builder) throws Exception { - builder.ignoring().requestMatchers(new AntPathRequestMatcher("/cloudfoundryapplication/**")); + builder.ignoring().requestMatchers( + new AntPathRequestMatcher("/cloudfoundryapplication/**")); } @Override diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundrySecurityInterceptor.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundrySecurityInterceptor.java index b918bd080c..23e474b696 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundrySecurityInterceptor.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundrySecurityInterceptor.java @@ -52,18 +52,19 @@ class CloudFoundrySecurityInterceptor { this.applicationId = applicationId; } - SecurityResponse preHandle(HttpServletRequest request, - String endpointId) { + SecurityResponse preHandle(HttpServletRequest request, String endpointId) { if (CorsUtils.isPreFlightRequest(request)) { return SecurityResponse.success(); } try { if (!StringUtils.hasText(this.applicationId)) { - throw new CloudFoundryAuthorizationException(CloudFoundryAuthorizationException.Reason.SERVICE_UNAVAILABLE, + throw new CloudFoundryAuthorizationException( + CloudFoundryAuthorizationException.Reason.SERVICE_UNAVAILABLE, "Application id is not available"); } if (this.cloudFoundrySecurityService == null) { - throw new CloudFoundryAuthorizationException(CloudFoundryAuthorizationException.Reason.SERVICE_UNAVAILABLE, + throw new CloudFoundryAuthorizationException( + CloudFoundryAuthorizationException.Reason.SERVICE_UNAVAILABLE, "Cloud controller URL is not available"); } if (HttpMethod.OPTIONS.matches(request.getMethod())) { @@ -75,21 +76,23 @@ class CloudFoundrySecurityInterceptor { logger.error(ex); if (ex instanceof CloudFoundryAuthorizationException) { CloudFoundryAuthorizationException cfException = (CloudFoundryAuthorizationException) ex; - return new SecurityResponse(cfException.getStatusCode(), "{\"security_error\":\"" + cfException.getMessage() + "\"}"); + return new SecurityResponse(cfException.getStatusCode(), + "{\"security_error\":\"" + cfException.getMessage() + "\"}"); } - return new SecurityResponse(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage()); + return new SecurityResponse(HttpStatus.INTERNAL_SERVER_ERROR, + ex.getMessage()); } return SecurityResponse.success(); } - private void check(HttpServletRequest request, String path) - throws Exception { + private void check(HttpServletRequest request, String path) throws Exception { Token token = getToken(request); this.tokenValidator.validate(token); AccessLevel accessLevel = this.cloudFoundrySecurityService .getAccessLevel(token.toString(), this.applicationId); if (!accessLevel.isAccessAllowed(path)) { - throw new CloudFoundryAuthorizationException(CloudFoundryAuthorizationException.Reason.ACCESS_DENIED, + throw new CloudFoundryAuthorizationException( + CloudFoundryAuthorizationException.Reason.ACCESS_DENIED, "Access denied"); } accessLevel.put(request); @@ -100,7 +103,8 @@ class CloudFoundrySecurityInterceptor { String bearerPrefix = "bearer "; if (authorization == null || !authorization.toLowerCase().startsWith(bearerPrefix)) { - throw new CloudFoundryAuthorizationException(CloudFoundryAuthorizationException.Reason.MISSING_AUTHORIZATION, + throw new CloudFoundryAuthorizationException( + CloudFoundryAuthorizationException.Reason.MISSING_AUTHORIZATION, "Authorization header is missing or invalid"); } return new Token(authorization.substring(bearerPrefix.length())); @@ -116,7 +120,7 @@ class CloudFoundrySecurityInterceptor { private final String message; SecurityResponse(HttpStatus status) { - this (status, null); + this(status, null); } SecurityResponse(HttpStatus status, String message) { @@ -135,7 +139,7 @@ class CloudFoundrySecurityInterceptor { static SecurityResponse success() { return new SecurityResponse(HttpStatus.OK); } + } } - diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryWebEndpointServletHandlerMapping.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryWebEndpointServletHandlerMapping.java index 5c7b0c79a3..447cb3a659 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryWebEndpointServletHandlerMapping.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryWebEndpointServletHandlerMapping.java @@ -50,18 +50,20 @@ import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping; /** - * A custom {@link RequestMappingInfoHandlerMapping} that makes web endpoints available - * on Cloudfoundry specific URLS over HTTP using Spring MVC. + * A custom {@link RequestMappingInfoHandlerMapping} that makes web endpoints available on + * Cloudfoundry specific URLS over HTTP using Spring MVC. * * @author Madhura Bhave */ -class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebEndpointServletHandlerMapping { +class CloudFoundryWebEndpointServletHandlerMapping + extends AbstractWebEndpointServletHandlerMapping { private final Method handle = ReflectionUtils.findMethod(OperationHandler.class, "handle", HttpServletRequest.class, Map.class); private final Method links = ReflectionUtils.findMethod( - CloudFoundryWebEndpointServletHandlerMapping.class, "links", HttpServletRequest.class, HttpServletResponse.class); + CloudFoundryWebEndpointServletHandlerMapping.class, "links", + HttpServletRequest.class, HttpServletResponse.class); private static final Log logger = LogFactory .getLog(CloudFoundryWebEndpointServletHandlerMapping.class); @@ -70,7 +72,10 @@ class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebEndpointSe private final EndpointLinksResolver endpointLinksResolver = new EndpointLinksResolver(); - CloudFoundryWebEndpointServletHandlerMapping(String endpointPath, Collection> webEndpoints, CorsConfiguration corsConfiguration, CloudFoundrySecurityInterceptor securityInterceptor) { + CloudFoundryWebEndpointServletHandlerMapping(String endpointPath, + Collection> webEndpoints, + CorsConfiguration corsConfiguration, + CloudFoundrySecurityInterceptor securityInterceptor) { super(endpointPath, webEndpoints, corsConfiguration); this.securityInterceptor = securityInterceptor; } @@ -81,27 +86,32 @@ class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebEndpointSe } @ResponseBody - private Map> links(HttpServletRequest request, HttpServletResponse response) { - CloudFoundrySecurityInterceptor.SecurityResponse securityResponse = this.securityInterceptor.preHandle(request, ""); + private Map> links(HttpServletRequest request, + HttpServletResponse response) { + CloudFoundrySecurityInterceptor.SecurityResponse securityResponse = this.securityInterceptor + .preHandle(request, ""); if (!securityResponse.getStatus().equals(HttpStatus.OK)) { sendFailureResponse(response, securityResponse); } AccessLevel accessLevel = AccessLevel.get(request); - Map links = this.endpointLinksResolver - .resolveLinks(getEndpoints(), request.getRequestURL().toString()); + Map links = this.endpointLinksResolver.resolveLinks(getEndpoints(), + request.getRequestURL().toString()); Map filteredLinks = new LinkedHashMap<>(); if (accessLevel == null) { return Collections.singletonMap("_links", filteredLinks); } filteredLinks = links.entrySet().stream() - .filter(e -> e.getKey().equals("self") || accessLevel.isAccessAllowed(e.getKey())) + .filter(e -> e.getKey().equals("self") + || accessLevel.isAccessAllowed(e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); return Collections.singletonMap("_links", filteredLinks); } - private void sendFailureResponse(HttpServletResponse response, CloudFoundrySecurityInterceptor.SecurityResponse securityResponse) { + private void sendFailureResponse(HttpServletResponse response, + CloudFoundrySecurityInterceptor.SecurityResponse securityResponse) { try { - response.sendError(securityResponse.getStatus().value(), securityResponse.getMessage()); + response.sendError(securityResponse.getStatus().value(), + securityResponse.getMessage()); } catch (Exception ex) { logger.debug("Failed to send error response", ex); @@ -111,7 +121,9 @@ class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebEndpointSe @Override protected void registerMappingForOperation(WebEndpointOperation operation) { registerMapping(createRequestMappingInfo(operation), - new OperationHandler(operation.getInvoker(), operation.getId(), this.securityInterceptor), this.handle); + new OperationHandler(operation.getInvoker(), operation.getId(), + this.securityInterceptor), + this.handle); } /** @@ -125,7 +137,8 @@ class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebEndpointSe private final CloudFoundrySecurityInterceptor securityInterceptor; - OperationHandler(OperationInvoker operationInvoker, String id, CloudFoundrySecurityInterceptor securityInterceptor) { + OperationHandler(OperationInvoker operationInvoker, String id, + CloudFoundrySecurityInterceptor securityInterceptor) { this.operationInvoker = operationInvoker; this.endpointId = id; this.securityInterceptor = securityInterceptor; @@ -135,7 +148,8 @@ class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebEndpointSe @ResponseBody public Object handle(HttpServletRequest request, @RequestBody(required = false) Map body) { - CloudFoundrySecurityInterceptor.SecurityResponse securityResponse = this.securityInterceptor.preHandle(request, this.endpointId); + CloudFoundrySecurityInterceptor.SecurityResponse securityResponse = this.securityInterceptor + .preHandle(request, this.endpointId); if (!securityResponse.getStatus().equals(HttpStatus.OK)) { return failureResponse(securityResponse); } @@ -155,8 +169,10 @@ class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebEndpointSe } } - private Object failureResponse(CloudFoundrySecurityInterceptor.SecurityResponse response) { - return handleResult(new WebEndpointResponse<>(response.getMessage(), response.getStatus().value())); + private Object failureResponse( + CloudFoundrySecurityInterceptor.SecurityResponse response) { + return handleResult(new WebEndpointResponse<>(response.getMessage(), + response.getStatus().value())); } private Object handleResult(Object result) { @@ -179,4 +195,3 @@ class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebEndpointSe } } - diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/SkipSslVerificationHttpRequestFactory.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/SkipSslVerificationHttpRequestFactory.java index dfc3c8d7cd..91b0d4783d 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/SkipSslVerificationHttpRequestFactory.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/SkipSslVerificationHttpRequestFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -91,4 +91,3 @@ class SkipSslVerificationHttpRequestFactory extends SimpleClientHttpRequestFacto } } - diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/Token.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/Token.java index 6aa8846cbb..7da97acbc4 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/Token.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/Token.java @@ -123,4 +123,3 @@ class Token { }; } - diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/TokenValidator.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/TokenValidator.java index 41c9f74a4f..b0dae1077a 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/TokenValidator.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/TokenValidator.java @@ -139,4 +139,3 @@ class TokenValidator { } } - diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/InfoEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/InfoEndpoint.java index 16d779a49a..85ba27e857 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/InfoEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/InfoEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/main/java/org/springframework/boot/actuate/endpoint/NamePatternFilter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/NamePatternFilter.java index 141cf9c2b1..3c118ed111 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/NamePatternFilter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/NamePatternFilter.java @@ -32,7 +32,7 @@ import java.util.regex.PatternSyntaxException; * @author Phillip Webb * @author Sergei Egorov * @author Andy Wilkinson - * @since 2.0.0 + * @author Dylian Bego */ abstract class NamePatternFilter { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ThreadDumpEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ThreadDumpEndpoint.java index 7e62399850..e6e303f281 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ThreadDumpEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ThreadDumpEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TraceEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TraceEndpoint.java index 11f2291e1b..8626c2c022 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TraceEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TraceEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/HeapDumpWebEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/HeapDumpWebEndpoint.java index 2a04c0a0a1..bec769816c 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/HeapDumpWebEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/HeapDumpWebEndpoint.java @@ -16,7 +16,9 @@ package org.springframework.boot.actuate.endpoint.web; +import java.io.Closeable; import java.io.File; +import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import java.lang.management.ManagementFactory; @@ -206,12 +208,7 @@ public class HeapDumpWebEndpoint { @Override public void close() throws IOException { - try { - readableChannel.close(); - } - finally { - deleteFile(); - } + closeThenDeleteFile(readableChannel); } @Override @@ -224,62 +221,25 @@ public class HeapDumpWebEndpoint { @Override public InputStream getInputStream() throws IOException { - InputStream delegate = super.getInputStream(); - return new InputStream() { - - @Override - public int read() throws IOException { - return delegate.read(); - } - - @Override - public int read(byte[] b) throws IOException { - return delegate.read(b); - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - return delegate.read(b, off, len); - } - - @Override - public long skip(long n) throws IOException { - return delegate.skip(n); - } - - @Override - public int available() throws IOException { - return delegate.available(); - } + return new FilterInputStream(super.getInputStream()) { @Override public void close() throws IOException { - try { - delegate.close(); - } - finally { - deleteFile(); - } - } - - @Override - public synchronized void mark(int readlimit) { - delegate.mark(readlimit); - } - - @Override - public synchronized void reset() throws IOException { - delegate.reset(); - } - - @Override - public boolean markSupported() { - return delegate.markSupported(); + closeThenDeleteFile(this.in); } }; } + private void closeThenDeleteFile(Closeable closeable) throws IOException { + try { + closeable.close(); + } + finally { + deleteFile(); + } + } + private void deleteFile() { try { Files.delete(getFile().toPath()); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorFactory.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorFactory.java index b57e895f03..45b42068df 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorFactory.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorFactory.java @@ -35,8 +35,7 @@ public class HealthIndicatorFactory { * @return a {@link HealthIndicator} that delegates to the specified * {@code healthIndicators}. */ - public HealthIndicator createHealthIndicator( - HealthAggregator healthAggregator, + public HealthIndicator createHealthIndicator(HealthAggregator healthAggregator, Map healthIndicators) { Assert.notNull(healthAggregator, "HealthAggregator must not be null"); Assert.notNull(healthIndicators, "HealthIndicators must not be null"); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/aggregate/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/aggregate/package-info.java index 5c9a071a14..85e328bc6e 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/aggregate/package-info.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/aggregate/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/package-info.java index 0baa935fd0..bfa7a446fe 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/package-info.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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-actuator/src/main/java/org/springframework/boot/actuate/web/server/LocalManagementPort.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/server/LocalManagementPort.java index c7a816358d..44ea827e78 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/server/LocalManagementPort.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/server/LocalManagementPort.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/audit/AuditAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/audit/AuditAutoConfigurationTests.java index 7ace4dc96b..0e5e474d7d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/audit/AuditAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/audit/AuditAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/ConditionalOnEnabledEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/ConditionalOnEnabledEndpointTests.java index 00f7fc004d..c93ce7562a 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/ConditionalOnEnabledEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/ConditionalOnEnabledEndpointTests.java @@ -118,10 +118,9 @@ public class ConditionalOnEnabledEndpointTests { @Test public void disabledEvenWithEnabledGeneralProperties() { - this.contextRunner.withUserConfiguration(FooConfig.class) - .withPropertyValues("endpoints.default.enabled=true", - "endpoints.default.web.enabled=true", - "endpoints.default.jmx.enabled=true", "endpoints.foo.enabled=false") + this.contextRunner.withUserConfiguration(FooConfig.class).withPropertyValues( + "endpoints.default.enabled=true", "endpoints.default.web.enabled=true", + "endpoints.default.jmx.enabled=true", "endpoints.foo.enabled=false") .run((context) -> assertThat(context).doesNotHaveBean("foo")); } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/DefaultEndpointObjectNameFactoryTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/DefaultEndpointObjectNameFactoryTests.java index 728c824408..d9664093e9 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/DefaultEndpointObjectNameFactoryTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/DefaultEndpointObjectNameFactoryTests.java @@ -41,7 +41,8 @@ public class DefaultEndpointObjectNameFactoryTests { private final MockEnvironment environment = new MockEnvironment(); - private final JmxEndpointExporterProperties properties = new JmxEndpointExporterProperties(this.environment); + private final JmxEndpointExporterProperties properties = new JmxEndpointExporterProperties( + this.environment); private final MBeanServer mBeanServer = mock(MBeanServer.class); @@ -50,23 +51,23 @@ public class DefaultEndpointObjectNameFactoryTests { @Test public void generateObjectName() { ObjectName objectName = generateObjectName(endpoint("Test")); - assertThat(objectName.toString()).isEqualTo( - "org.springframework.boot:type=Endpoint,name=Test"); + assertThat(objectName.toString()) + .isEqualTo("org.springframework.boot:type=Endpoint,name=Test"); } @Test public void generateObjectNameWithCapitalizedId() { ObjectName objectName = generateObjectName(endpoint("test")); - assertThat(objectName.toString()).isEqualTo( - "org.springframework.boot:type=Endpoint,name=Test"); + assertThat(objectName.toString()) + .isEqualTo("org.springframework.boot:type=Endpoint,name=Test"); } @Test public void generateObjectNameWithCustomDomain() { this.properties.setDomain("com.example.acme"); ObjectName objectName = generateObjectName(endpoint("test")); - assertThat(objectName.toString()).isEqualTo( - "com.example.acme:type=Endpoint,name=Test"); + assertThat(objectName.toString()) + .isEqualTo("com.example.acme:type=Endpoint,name=Test"); } @Test @@ -86,17 +87,18 @@ public class DefaultEndpointObjectNameFactoryTests { ObjectName objectName = generateObjectName(endpoint("test")); assertThat(objectName.getKeyProperty("counter")).isEqualTo("42"); assertThat(objectName.getKeyProperty("foo")).isEqualTo("bar"); - assertThat(objectName.toString()).startsWith( - "org.springframework.boot:type=Endpoint,name=Test,"); + assertThat(objectName.toString()) + .startsWith("org.springframework.boot:type=Endpoint,name=Test,"); } @Test public void generateObjectNameWithDuplicate() throws MalformedObjectNameException { this.contextId = "testContext"; - given(this.mBeanServer.queryNames(new ObjectName( - "org.springframework.boot:type=Endpoint,name=Test,*"), null)) - .willReturn(Collections.singleton( - new ObjectName("org.springframework.boot:type=Endpoint,name=Test"))); + given(this.mBeanServer.queryNames( + new ObjectName("org.springframework.boot:type=Endpoint,name=Test,*"), + null)).willReturn( + Collections.singleton(new ObjectName( + "org.springframework.boot:type=Endpoint,name=Test"))); ObjectName objectName = generateObjectName(endpoint("test")); assertThat(objectName.toString()).isEqualTo( "org.springframework.boot:type=Endpoint,name=Test,context=testContext"); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/WebMvcEndpointInfrastructureAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/WebMvcEndpointInfrastructureAutoConfigurationTests.java index 545cf5d1f4..673680a09e 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/WebMvcEndpointInfrastructureAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/WebMvcEndpointInfrastructureAutoConfigurationTests.java @@ -57,25 +57,18 @@ public class WebMvcEndpointInfrastructureAutoConfigurationTests { @Test public void webEndpointsAreDisabledByDefault() { this.contextRunner.run(context -> { - MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).build(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/autoconfig")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/beans")).isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/configprops")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/env")).isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/health")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/info")).isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/mappings")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/metrics")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.POST, "/application/shutdown")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/threaddump")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/trace")).isFalse(); + MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).build(); + assertThat(isExposed(mvc, HttpMethod.GET, "autoconfig")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "beans")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "configprops")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "env")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "health")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "info")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "mappings")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "metrics")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.POST, "shutdown")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "threaddump")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "trace")).isFalse(); }); } @@ -84,60 +77,45 @@ public class WebMvcEndpointInfrastructureAutoConfigurationTests { WebApplicationContextRunner contextRunner = this.contextRunner .withPropertyValues("endpoints.default.web.enabled=true"); contextRunner.run(context -> { - MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).build(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/autoconfig")) - .isTrue(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/beans")) - .isTrue(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/configprops")) - .isTrue(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/env")).isTrue(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/health")) - .isTrue(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/info")).isTrue(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/mappings")) - .isTrue(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/metrics")) - .isTrue(); - assertThat(isExposed(mockMvc, HttpMethod.POST, "/application/shutdown")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/threaddump")) - .isTrue(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/trace")) - .isTrue(); + MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).build(); + assertThat(isExposed(mvc, HttpMethod.GET, "autoconfig")).isTrue(); + assertThat(isExposed(mvc, HttpMethod.GET, "beans")).isTrue(); + assertThat(isExposed(mvc, HttpMethod.GET, "configprops")).isTrue(); + assertThat(isExposed(mvc, HttpMethod.GET, "env")).isTrue(); + assertThat(isExposed(mvc, HttpMethod.GET, "health")).isTrue(); + assertThat(isExposed(mvc, HttpMethod.GET, "info")).isTrue(); + assertThat(isExposed(mvc, HttpMethod.GET, "mappings")).isTrue(); + assertThat(isExposed(mvc, HttpMethod.GET, "metrics")).isTrue(); + assertThat(isExposed(mvc, HttpMethod.POST, "shutdown")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "threaddump")).isTrue(); + assertThat(isExposed(mvc, HttpMethod.GET, "trace")).isTrue(); }); } @Test public void singleWebEndpointCanBeEnabled() { WebApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues( - "endpoints.default.web.enabled=false", "endpoints.beans.web.enabled=true"); + "endpoints.default.web.enabled=false", + "endpoints.beans.web.enabled=true"); contextRunner.run((context) -> { - MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).build(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/autoconfig")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/beans")).isTrue(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/configprops")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/env")).isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/health")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/info")).isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/mappings")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/metrics")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.POST, "/application/shutdown")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/threaddump")) - .isFalse(); - assertThat(isExposed(mockMvc, HttpMethod.GET, "/application/trace")) - .isFalse(); + MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).build(); + assertThat(isExposed(mvc, HttpMethod.GET, "autoconfig")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "beans")).isTrue(); + assertThat(isExposed(mvc, HttpMethod.GET, "configprops")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "env")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "health")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "info")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "mappings")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "metrics")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.POST, "shutdown")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "threaddump")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "trace")).isFalse(); }); } private boolean isExposed(MockMvc mockMvc, HttpMethod method, String path) throws Exception { + path = "/application/" + path; MvcResult mvcResult = mockMvc.perform(request(method, path)).andReturn(); int status = mvcResult.getResponse().getStatus(); if (status == HttpStatus.SC_OK) { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/support/EndpointEnablementProviderTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/support/EndpointEnablementProviderTests.java index f07360eac7..7d4d41d319 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/support/EndpointEnablementProviderTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/support/EndpointEnablementProviderTests.java @@ -254,9 +254,8 @@ public class EndpointEnablementProviderTests { @Test public void specificEnabledOverrideHasNoEffectWithUnrelatedTechProperty() { - validate( - getEndpointEnablement("foo", true, EndpointExposure.JMX, - "endpoints.default.enabled=false", "endpoints.default.web.enabled=true"), + validate(getEndpointEnablement("foo", true, EndpointExposure.JMX, + "endpoints.default.enabled=false", "endpoints.default.web.enabled=true"), false, "found property endpoints.default.enabled"); } @@ -264,8 +263,8 @@ public class EndpointEnablementProviderTests { public void specificDisabledWithEndpointPropertyEvenWithEnabledGeneralProperties() { EndpointEnablement enablement = getEndpointEnablement("foo", true, EndpointExposure.WEB, "endpoints.default.enabled=true", - "endpoints.default.web.enabled=true", "endpoints.default.jmx.enabled=true", - "endpoints.foo.enabled=false"); + "endpoints.default.web.enabled=true", + "endpoints.default.jmx.enabled=true", "endpoints.foo.enabled=false"); validate(enablement, false, "found property endpoints.foo.enabled"); } @@ -273,8 +272,9 @@ public class EndpointEnablementProviderTests { public void specificDisabledWithTechPropertyEvenWithEnabledGeneralProperties() { EndpointEnablement enablement = getEndpointEnablement("foo", true, EndpointExposure.WEB, "endpoints.default.enabled=true", - "endpoints.default.web.enabled=true", "endpoints.default.jmx.enabled=true", - "endpoints.foo.enabled=true", "endpoints.foo.web.enabled=false"); + "endpoints.default.web.enabled=true", + "endpoints.default.jmx.enabled=true", "endpoints.foo.enabled=true", + "endpoints.foo.web.enabled=false"); validate(enablement, false, "found property endpoints.foo.web.enabled"); } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointManagementContextConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointManagementContextConfigurationTests.java index 32c25770e6..87c2360e84 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointManagementContextConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointManagementContextConfigurationTests.java @@ -73,9 +73,7 @@ public class WebEndpointManagementContextConfigurationTests { contextRunner.run((context) -> { HealthWebEndpointExtension extension = context .getBean(HealthWebEndpointExtension.class); - @SuppressWarnings("unchecked") - Map statusMappings = ((HealthStatusHttpMapper) ReflectionTestUtils - .getField(extension, "statusHttpMapper")).getStatusMapping(); + Map statusMappings = getStatusMapping(extension); assertThat(statusMappings).containsEntry("DOWN", 503); assertThat(statusMappings).containsEntry("OUT_OF_SERVICE", 503); assertThat(statusMappings).containsEntry("CUSTOM", 500); @@ -102,9 +100,7 @@ public class WebEndpointManagementContextConfigurationTests { contextRunner.run((context) -> { StatusWebEndpointExtension extension = context .getBean(StatusWebEndpointExtension.class); - @SuppressWarnings("unchecked") - Map statusMappings = ((HealthStatusHttpMapper) ReflectionTestUtils - .getField(extension, "statusHttpMapper")).getStatusMapping(); + Map statusMappings = getStatusMapping(extension); assertThat(statusMappings).containsEntry("DOWN", 503); assertThat(statusMappings).containsEntry("OUT_OF_SERVICE", 503); assertThat(statusMappings).containsEntry("CUSTOM", 500); @@ -161,8 +157,7 @@ public class WebEndpointManagementContextConfigurationTests { } private void beanIsAutoConfigured(Class beanType, Class... config) { - contextRunner() - .withPropertyValues("endpoints.default.web.enabled:true") + contextRunner().withPropertyValues("endpoints.default.web.enabled:true") .withUserConfiguration(config) .run((context) -> assertThat(context).hasSingleBean(beanType)); } @@ -178,6 +173,11 @@ public class WebEndpointManagementContextConfigurationTests { AutoConfigurations.of(WebEndpointManagementContextConfiguration.class)); } + private Map getStatusMapping(Object extension) { + return ((HealthStatusHttpMapper) ReflectionTestUtils.getField(extension, + "statusHttpMapper")).getStatusMapping(); + } + @Configuration static class HealthEndpointConfiguration { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaManagementContextConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaManagementContextConfigurationTests.java index 548e49ee4d..567ffb47a5 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaManagementContextConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaManagementContextConfigurationTests.java @@ -63,28 +63,30 @@ public class JolokiaManagementContextConfigurationTests { @Test public void customPath() { - this.contextRunner.withPropertyValues("management.jolokia.enabled=true", - "management.jolokia.path=/lokia").run( - isDefinedOnPath("/application/lokia/*")); + this.contextRunner + .withPropertyValues("management.jolokia.enabled=true", + "management.jolokia.path=/lokia") + .run(isDefinedOnPath("/application/lokia/*")); } @Test public void customManagementPath() { - this.contextRunner.withPropertyValues("management.jolokia.enabled=true", - "management.context-path=/admin").run( - isDefinedOnPath("/admin/jolokia/*")); + this.contextRunner + .withPropertyValues("management.jolokia.enabled=true", + "management.context-path=/admin") + .run(isDefinedOnPath("/admin/jolokia/*")); } @Test public void customInitParameters() { this.contextRunner.withPropertyValues("management.jolokia.enabled=true", "management.jolokia.config.debug=true").run((context) -> { - assertThat(context).hasSingleBean(ServletRegistrationBean.class); - ServletRegistrationBean registrationBean = context - .getBean(ServletRegistrationBean.class); - assertThat(registrationBean.getInitParameters()) - .containsOnly(entry("debug", "true")); - }); + assertThat(context).hasSingleBean(ServletRegistrationBean.class); + ServletRegistrationBean registrationBean = context + .getBean(ServletRegistrationBean.class); + assertThat(registrationBean.getInitParameters()) + .containsOnly(entry("debug", "true")); + }); } private ContextConsumer isDefinedOnPath( diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricFilterAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricFilterAutoConfigurationTests.java index cde84471dd..ecffe6854a 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricFilterAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricFilterAutoConfigurationTests.java @@ -385,8 +385,10 @@ public class MetricFilterAutoConfigurationTests { public void doesNotRecordRolledUpMetricsIfConfigured() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(Config.class, MetricFilterAutoConfiguration.class); - TestPropertyValues.of("management.metrics.filter.gauge-submissions=", - "management.metrics.filter.counter-submissions=").applyTo(context); + TestPropertyValues + .of("management.metrics.filter.gauge-submissions=", + "management.metrics.filter.counter-submissions=") + .applyTo(context); context.refresh(); Filter filter = context.getBean(Filter.class); MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/test/path"); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricRepositoryAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricRepositoryAutoConfigurationTests.java index 9687cb0943..54ba51d663 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricRepositoryAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricRepositoryAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsDropwizardAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsDropwizardAutoConfigurationTests.java index 9bd8c19742..6a9d39f344 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsDropwizardAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsDropwizardAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/trace/TraceRepositoryAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/trace/TraceRepositoryAutoConfigurationTests.java index bf437407a8..6473ce6cf6 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/trace/TraceRepositoryAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/trace/TraceRepositoryAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/AccessLevelTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/AccessLevelTests.java index 301ceaea36..40a13a47d8 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/AccessLevelTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/AccessLevelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/AuthorizationExceptionMatcher.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/AuthorizationExceptionMatcher.java index 9ee80e6a78..e72d9ba0d9 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/AuthorizationExceptionMatcher.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/AuthorizationExceptionMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -39,11 +39,10 @@ final class AuthorizationExceptionMatcher { public boolean matches(Object object) { return ((object instanceof CloudFoundryAuthorizationException) && ((CloudFoundryAuthorizationException) object) - .getReason() == reason); + .getReason() == reason); } }; } } - diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfigurationTests.java index 75d97fc62f..1ee0ee22cf 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfigurationTests.java @@ -59,8 +59,7 @@ public class CloudFoundryActuatorAutoConfigurationTests { this.context = new AnnotationConfigWebApplicationContext(); this.context.setServletContext(new MockServletContext()); this.context.register(SecurityAutoConfiguration.class, - WebMvcAutoConfiguration.class, - JacksonAutoConfiguration.class, + WebMvcAutoConfiguration.class, JacksonAutoConfiguration.class, DispatcherServletAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, @@ -80,7 +79,8 @@ public class CloudFoundryActuatorAutoConfigurationTests { @Test public void cloudFoundryPlatformActive() throws Exception { CloudFoundryWebEndpointServletHandlerMapping handlerMapping = getHandlerMapping(); - assertThat(handlerMapping.getEndpointPath()).isEqualTo("/cloudfoundryapplication"); + assertThat(handlerMapping.getEndpointPath()) + .isEqualTo("/cloudfoundryapplication"); CorsConfiguration corsConfiguration = (CorsConfiguration) ReflectionTestUtils .getField(handlerMapping, "corsConfiguration"); assertThat(corsConfiguration.getAllowedOrigins()).contains("*"); @@ -136,9 +136,9 @@ public class CloudFoundryActuatorAutoConfigurationTests { .of("VCAP_APPLICATION:---", "vcap.application.application_id:my-app-id") .applyTo(this.context); this.context.refresh(); - CloudFoundryWebEndpointServletHandlerMapping handlerMapping = this.context.getBean( - "cloudFoundryWebEndpointServletHandlerMapping", - CloudFoundryWebEndpointServletHandlerMapping.class); + CloudFoundryWebEndpointServletHandlerMapping handlerMapping = this.context + .getBean("cloudFoundryWebEndpointServletHandlerMapping", + CloudFoundryWebEndpointServletHandlerMapping.class); Object securityInterceptor = ReflectionTestUtils.getField(handlerMapping, "securityInterceptor"); Object interceptorSecurityService = ReflectionTestUtils @@ -152,7 +152,8 @@ public class CloudFoundryActuatorAutoConfigurationTests { .of("VCAP_APPLICATION:---", "vcap.application.application_id:my-app-id") .applyTo(this.context); this.context.refresh(); - FilterChainProxy securityFilterChain = (FilterChainProxy) this.context.getBean("springSecurityFilterChain"); + FilterChainProxy securityFilterChain = (FilterChainProxy) this.context + .getBean("springSecurityFilterChain"); SecurityFilterChain chain = securityFilterChain.getFilterChains().get(0); MockHttpServletRequest request = new MockHttpServletRequest(); request.setServletPath("/cloudfoundryapplication/my-path"); @@ -165,8 +166,9 @@ public class CloudFoundryActuatorAutoConfigurationTests { @Test public void cloudFoundryPlatformInactive() throws Exception { this.context.refresh(); - assertThat(this.context.containsBean("cloudFoundryWebEndpointServletHandlerMapping")) - .isFalse(); + assertThat( + this.context.containsBean("cloudFoundryWebEndpointServletHandlerMapping")) + .isFalse(); } @Test diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryAuthorizationExceptionTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryAuthorizationExceptionTests.java index 2a13144682..239f82ca9f 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryAuthorizationExceptionTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryAuthorizationExceptionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryMvcWebEndpointIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryMvcWebEndpointIntegrationTests.java index 3078c73a6b..a78bbe67e5 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryMvcWebEndpointIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryMvcWebEndpointIntegrationTests.java @@ -23,8 +23,6 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; import org.junit.Test; -import org.mockito.BDDMockito; -import org.mockito.Mockito; import org.springframework.boot.endpoint.CachingConfiguration; import org.springframework.boot.endpoint.ConversionServiceOperationParameterMapper; @@ -52,39 +50,40 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willThrow; import static org.mockito.Mockito.mock; /** - * Integration tests for web endpoints exposed using Spring MVC - * on CloudFoundry. + * Integration tests for web endpoints exposed using Spring MVC on CloudFoundry. * * @author Madhura Bhave */ public class CloudFoundryMvcWebEndpointIntegrationTests { - private static TokenValidator tokenValidator = Mockito.mock(TokenValidator.class); + private static TokenValidator tokenValidator = mock(TokenValidator.class); - private static CloudFoundrySecurityService securityService = Mockito.mock(CloudFoundrySecurityService.class); + private static CloudFoundrySecurityService securityService = mock( + CloudFoundrySecurityService.class); @Test public void operationWithSecurityInterceptorForbidden() throws Exception { - BDDMockito.doNothing().when(tokenValidator).validate(any()); - given(securityService.getAccessLevel(any(), eq("app-id"))).willReturn(AccessLevel.RESTRICTED); + given(securityService.getAccessLevel(any(), eq("app-id"))) + .willReturn(AccessLevel.RESTRICTED); load(TestEndpointConfiguration.class, (client) -> { client.get().uri("/cfApplication/test").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "bearer " + mockAccessToken()) - .exchange().expectStatus().isEqualTo(HttpStatus.FORBIDDEN); + .header("Authorization", "bearer " + mockAccessToken()).exchange() + .expectStatus().isEqualTo(HttpStatus.FORBIDDEN); }); } @Test public void operationWithSecurityInterceptorSuccess() throws Exception { - BDDMockito.doNothing().when(tokenValidator).validate(any()); - given(securityService.getAccessLevel(any(), eq("app-id"))).willReturn(AccessLevel.FULL); + given(securityService.getAccessLevel(any(), eq("app-id"))) + .willReturn(AccessLevel.FULL); load(TestEndpointConfiguration.class, (client) -> { client.get().uri("/cfApplication/test").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "bearer " + mockAccessToken()) - .exchange().expectStatus().isEqualTo(HttpStatus.OK); + .header("Authorization", "bearer " + mockAccessToken()).exchange() + .expectStatus().isEqualTo(HttpStatus.OK); }); } @@ -103,14 +102,14 @@ public class CloudFoundryMvcWebEndpointIntegrationTests { @Test public void linksToOtherEndpointsWithFullAccess() { - BDDMockito.doNothing().when(tokenValidator).validate(any()); - given(securityService.getAccessLevel(any(), eq("app-id"))).willReturn(AccessLevel.FULL); + given(securityService.getAccessLevel(any(), eq("app-id"))) + .willReturn(AccessLevel.FULL); load(TestEndpointConfiguration.class, - (client) -> client.get().uri("/cfApplication").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "bearer " + mockAccessToken()) - .exchange().expectStatus().isOk().expectBody() - .jsonPath("_links.length()").isEqualTo(5) - .jsonPath("_links.self.href").isNotEmpty() + (client) -> client.get().uri("/cfApplication") + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", "bearer " + mockAccessToken()).exchange() + .expectStatus().isOk().expectBody().jsonPath("_links.length()") + .isEqualTo(5).jsonPath("_links.self.href").isNotEmpty() .jsonPath("_links.self.templated").isEqualTo(false) .jsonPath("_links.info.href").isNotEmpty() .jsonPath("_links.info.templated").isEqualTo(false) @@ -124,33 +123,35 @@ public class CloudFoundryMvcWebEndpointIntegrationTests { @Test public void linksToOtherEndpointsForbidden() { - CloudFoundryAuthorizationException exception = new CloudFoundryAuthorizationException(CloudFoundryAuthorizationException.Reason.INVALID_TOKEN, "invalid-token"); - BDDMockito.doThrow(exception).when(tokenValidator).validate(any()); + CloudFoundryAuthorizationException exception = new CloudFoundryAuthorizationException( + CloudFoundryAuthorizationException.Reason.INVALID_TOKEN, "invalid-token"); + willThrow(exception).given(tokenValidator).validate(any()); load(TestEndpointConfiguration.class, - (client) -> client.get().uri("/cfApplication").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "bearer " + mockAccessToken()) - .exchange().expectStatus().isUnauthorized()); + (client) -> client.get().uri("/cfApplication") + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", "bearer " + mockAccessToken()).exchange() + .expectStatus().isUnauthorized()); } @Test public void linksToOtherEndpointsWithRestrictedAccess() { - BDDMockito.doNothing().when(tokenValidator).validate(any()); - given(securityService.getAccessLevel(any(), eq("app-id"))).willReturn(AccessLevel.RESTRICTED); + given(securityService.getAccessLevel(any(), eq("app-id"))) + .willReturn(AccessLevel.RESTRICTED); load(TestEndpointConfiguration.class, - (client) -> client.get().uri("/cfApplication").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "bearer " + mockAccessToken()) - .exchange().expectStatus().isOk().expectBody() - .jsonPath("_links.length()").isEqualTo(2) - .jsonPath("_links.self.href").isNotEmpty() + (client) -> client.get().uri("/cfApplication") + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", "bearer " + mockAccessToken()).exchange() + .expectStatus().isOk().expectBody().jsonPath("_links.length()") + .isEqualTo(2).jsonPath("_links.self.href").isNotEmpty() .jsonPath("_links.self.templated").isEqualTo(false) .jsonPath("_links.info.href").isNotEmpty() .jsonPath("_links.info.templated").isEqualTo(false) - .jsonPath("_links.env").doesNotExist() - .jsonPath("_links.test").doesNotExist() - .jsonPath("_links.test-part").doesNotExist()); + .jsonPath("_links.env").doesNotExist().jsonPath("_links.test") + .doesNotExist().jsonPath("_links.test-part").doesNotExist()); } - private AnnotationConfigServletWebServerApplicationContext createApplicationContext(Class... config) { + private AnnotationConfigServletWebServerApplicationContext createApplicationContext( + Class... config) { return new AnnotationConfigServletWebServerApplicationContext(config); } @@ -159,14 +160,13 @@ public class CloudFoundryMvcWebEndpointIntegrationTests { } private void load(Class configuration, Consumer clientConsumer) { - BiConsumer consumer = (context, client) -> clientConsumer.accept(client); - AnnotationConfigServletWebServerApplicationContext context = createApplicationContext(configuration, CloudFoundryMvcConfiguration.class); + BiConsumer consumer = (context, + client) -> clientConsumer.accept(client); + AnnotationConfigServletWebServerApplicationContext context = createApplicationContext( + configuration, CloudFoundryMvcConfiguration.class); try { - consumer.accept(context, - WebTestClient.bindToServer() - .baseUrl( - "http://localhost:" + getPort(context)) - .build()); + consumer.accept(context, WebTestClient.bindToServer() + .baseUrl("http://localhost:" + getPort(context)).build()); } finally { context.close(); @@ -185,17 +185,20 @@ public class CloudFoundryMvcWebEndpointIntegrationTests { @Bean public CloudFoundrySecurityInterceptor interceptor() { - return new CloudFoundrySecurityInterceptor(tokenValidator, securityService, "app-id"); + return new CloudFoundrySecurityInterceptor(tokenValidator, securityService, + "app-id"); } @Bean public CloudFoundryWebEndpointServletHandlerMapping cloudFoundryWebEndpointServletHandlerMapping( - WebAnnotationEndpointDiscoverer webEndpointDiscoverer, CloudFoundrySecurityInterceptor interceptor) { + WebAnnotationEndpointDiscoverer webEndpointDiscoverer, + CloudFoundrySecurityInterceptor interceptor) { CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.setAllowedOrigins(Arrays.asList("http://example.com")); corsConfiguration.setAllowedMethods(Arrays.asList("GET", "POST")); return new CloudFoundryWebEndpointServletHandlerMapping("/cfApplication", - webEndpointDiscoverer.discoverEndpoints(), corsConfiguration, interceptor); + webEndpointDiscoverer.discoverEndpoints(), corsConfiguration, + interceptor); } @Bean @@ -302,4 +305,3 @@ public class CloudFoundryMvcWebEndpointIntegrationTests { } } - diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundrySecurityInterceptorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundrySecurityInterceptorTests.java index 0502113d28..47766ab31f 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundrySecurityInterceptorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundrySecurityInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -19,7 +19,6 @@ package org.springframework.boot.actuate.cloudfoundry; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.BDDMockito; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -30,6 +29,7 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.util.Base64Utils; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.verify; /** @@ -62,13 +62,15 @@ public class CloudFoundrySecurityInterceptorTests { this.request.setMethod("OPTIONS"); this.request.addHeader(HttpHeaders.ORIGIN, "http://example.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); - CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor.preHandle(this.request, "/a"); + CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor + .preHandle(this.request, "/a"); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK); } @Test public void preHandleWhenTokenIsMissingShouldReturnFalse() throws Exception { - CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor.preHandle(this.request, "/a"); + CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor + .preHandle(this.request, "/a"); assertThat(response.getStatus()) .isEqualTo(Reason.MISSING_AUTHORIZATION.getStatus()); } @@ -76,7 +78,8 @@ public class CloudFoundrySecurityInterceptorTests { @Test public void preHandleWhenTokenIsNotBearerShouldReturnFalse() throws Exception { this.request.addHeader("Authorization", mockAccessToken()); - CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor.preHandle(this.request, "/a"); + CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor + .preHandle(this.request, "/a"); assertThat(response.getStatus()) .isEqualTo(Reason.MISSING_AUTHORIZATION.getStatus()); } @@ -86,7 +89,8 @@ public class CloudFoundrySecurityInterceptorTests { this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, this.securityService, null); this.request.addHeader("Authorization", "bearer " + mockAccessToken()); - CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor.preHandle(this.request, "/a"); + CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor + .preHandle(this.request, "/a"); assertThat(response.getStatus()) .isEqualTo(Reason.SERVICE_UNAVAILABLE.getStatus()); } @@ -97,7 +101,8 @@ public class CloudFoundrySecurityInterceptorTests { this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, null, "my-app-id"); this.request.addHeader("Authorization", "bearer " + mockAccessToken()); - CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor.preHandle(this.request, "/a"); + CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor + .preHandle(this.request, "/a"); assertThat(response.getStatus()) .isEqualTo(Reason.SERVICE_UNAVAILABLE.getStatus()); } @@ -106,20 +111,21 @@ public class CloudFoundrySecurityInterceptorTests { public void preHandleWhenAccessIsNotAllowedShouldReturnFalse() throws Exception { String accessToken = mockAccessToken(); this.request.addHeader("Authorization", "bearer " + accessToken); - BDDMockito.given(this.securityService.getAccessLevel(accessToken, "my-app-id")) + given(this.securityService.getAccessLevel(accessToken, "my-app-id")) .willReturn(AccessLevel.RESTRICTED); - CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor.preHandle(this.request, "/a"); - assertThat(response.getStatus()) - .isEqualTo(Reason.ACCESS_DENIED.getStatus()); + CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor + .preHandle(this.request, "/a"); + assertThat(response.getStatus()).isEqualTo(Reason.ACCESS_DENIED.getStatus()); } @Test public void preHandleSuccessfulWithFullAccess() throws Exception { String accessToken = mockAccessToken(); this.request.addHeader("Authorization", "Bearer " + accessToken); - BDDMockito.given(this.securityService.getAccessLevel(accessToken, "my-app-id")) + given(this.securityService.getAccessLevel(accessToken, "my-app-id")) .willReturn(AccessLevel.FULL); - CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor.preHandle(this.request, "/a"); + CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor + .preHandle(this.request, "/a"); ArgumentCaptor tokenArgumentCaptor = ArgumentCaptor.forClass(Token.class); verify(this.tokenValidator).validate(tokenArgumentCaptor.capture()); Token token = tokenArgumentCaptor.getValue(); @@ -133,9 +139,10 @@ public class CloudFoundrySecurityInterceptorTests { public void preHandleSuccessfulWithRestrictedAccess() throws Exception { String accessToken = mockAccessToken(); this.request.addHeader("Authorization", "Bearer " + accessToken); - BDDMockito.given(this.securityService.getAccessLevel(accessToken, "my-app-id")) + given(this.securityService.getAccessLevel(accessToken, "my-app-id")) .willReturn(AccessLevel.RESTRICTED); - CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor.preHandle(this.request, "info"); + CloudFoundrySecurityInterceptor.SecurityResponse response = this.interceptor + .preHandle(this.request, "info"); ArgumentCaptor tokenArgumentCaptor = ArgumentCaptor.forClass(Token.class); verify(this.tokenValidator).validate(tokenArgumentCaptor.capture()); Token token = tokenArgumentCaptor.getValue(); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/TokenTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/TokenTests.java index 50551a19d2..37ac32ecd6 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/TokenTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/TokenTests.java @@ -137,4 +137,3 @@ public class TokenTests { } } - diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/TokenValidatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/TokenValidatorTests.java index 66bd395eb1..a3adfcc658 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/TokenValidatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/TokenValidatorTests.java @@ -266,4 +266,3 @@ public class TokenValidatorTests { } } - diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java index 0eb59103cf..eed17404af 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java @@ -46,8 +46,8 @@ public class HealthEndpointTests { .withDetail("first", "1").build()); healthIndicators.put("upAgain", () -> new Health.Builder().status(Status.UP) .withDetail("second", "2").build()); - HealthEndpoint endpoint = new HealthEndpoint(createHealthIndicator( - healthIndicators)); + HealthEndpoint endpoint = new HealthEndpoint( + createHealthIndicator(healthIndicators)); Health health = endpoint.health(); assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getDetails()).containsOnlyKeys("up", "upAgain"); @@ -59,8 +59,8 @@ public class HealthEndpointTests { private HealthIndicator createHealthIndicator( Map healthIndicators) { - return new HealthIndicatorFactory().createHealthIndicator( - new OrderedHealthAggregator(), healthIndicators); + return new HealthIndicatorFactory() + .createHealthIndicator(new OrderedHealthAggregator(), healthIndicators); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/StatusEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/StatusEndpointTests.java index 2652397451..625bcdde5f 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/StatusEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/StatusEndpointTests.java @@ -43,8 +43,8 @@ public class StatusEndpointTests { .withDetail("first", "1").build()); healthIndicators.put("upAgain", () -> new Health.Builder().status(Status.UP) .withDetail("second", "2").build()); - StatusEndpoint endpoint = new StatusEndpoint(createHealthIndicator( - healthIndicators)); + StatusEndpoint endpoint = new StatusEndpoint( + createHealthIndicator(healthIndicators)); Health health = endpoint.health(); assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getDetails()).isEmpty(); @@ -52,8 +52,8 @@ public class StatusEndpointTests { private HealthIndicator createHealthIndicator( Map healthIndicators) { - return new HealthIndicatorFactory().createHealthIndicator( - new OrderedHealthAggregator(), healthIndicators); + return new HealthIndicatorFactory() + .createHealthIndicator(new OrderedHealthAggregator(), healthIndicators); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointCorsIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointCorsIntegrationTests.java index b680b19ea5..29f3623e1c 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointCorsIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointCorsIntegrationTests.java @@ -65,8 +65,7 @@ public class MvcEndpointCorsIntegrationTests { EndpointInfrastructureAutoConfiguration.class, EndpointAutoConfiguration.class, ManagementContextAutoConfiguration.class, ServletEndpointAutoConfiguration.class); - TestPropertyValues.of("endpoints.default.web.enabled:true") - .applyTo(this.context); + TestPropertyValues.of("endpoints.default.web.enabled:true").applyTo(this.context); } @Test @@ -144,8 +143,10 @@ public class MvcEndpointCorsIntegrationTests { @Test public void allowedMethodsCanBeConfigured() throws Exception { - TestPropertyValues.of("management.endpoints.cors.allowed-origins:foo.example.com", - "management.endpoints.cors.allowed-methods:GET,HEAD").applyTo(this.context); + TestPropertyValues + .of("management.endpoints.cors.allowed-origins:foo.example.com", + "management.endpoints.cors.allowed-methods:GET,HEAD") + .applyTo(this.context); createMockMvc() .perform(options("/application/beans") .header(HttpHeaders.ORIGIN, "foo.example.com") @@ -156,16 +157,20 @@ public class MvcEndpointCorsIntegrationTests { @Test public void credentialsCanBeAllowed() throws Exception { - TestPropertyValues.of("management.endpoints.cors.allowed-origins:foo.example.com", - "management.endpoints.cors.allow-credentials:true").applyTo(this.context); + TestPropertyValues + .of("management.endpoints.cors.allowed-origins:foo.example.com", + "management.endpoints.cors.allow-credentials:true") + .applyTo(this.context); performAcceptedCorsRequest().andExpect( header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true")); } @Test public void credentialsCanBeDisabled() throws Exception { - TestPropertyValues.of("management.endpoints.cors.allowed-origins:foo.example.com", - "management.endpoints.cors.allow-credentials:false").applyTo(this.context); + TestPropertyValues + .of("management.endpoints.cors.allowed-origins:foo.example.com", + "management.endpoints.cors.allow-credentials:false") + .applyTo(this.context); performAcceptedCorsRequest().andExpect( header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS)); } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointIntegrationTests.java index 3a2d87bd9a..a1224375bb 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointIntegrationTests.java @@ -69,8 +69,8 @@ public class MvcEndpointIntegrationTests { this.context = new AnnotationConfigWebApplicationContext(); this.context.register(SecureConfiguration.class); MockMvc mockMvc = createSecureMockMvc(); - mockMvc.perform(get("/application/beans") - .accept(MediaType.APPLICATION_JSON)).andExpect(status().isUnauthorized()); + mockMvc.perform(get("/application/beans").accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isUnauthorized()); } @Test @@ -80,8 +80,8 @@ public class MvcEndpointIntegrationTests { TestPropertyValues.of("management.context-path:/management") .applyTo(this.context); MockMvc mockMvc = createSecureMockMvc(); - mockMvc.perform(get("/management/beans") - .accept(MediaType.APPLICATION_JSON)).andExpect(status().isUnauthorized()); + mockMvc.perform(get("/management/beans").accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isUnauthorized()); } @Test @@ -92,8 +92,7 @@ public class MvcEndpointIntegrationTests { this.context = new AnnotationConfigWebApplicationContext(); this.context.register(SecureConfiguration.class); TestPropertyValues.of("management.context-path:/management", - "endpoints.default.web.enabled=true") - .applyTo(this.context); + "endpoints.default.web.enabled=true").applyTo(this.context); MockMvc mockMvc = createSecureMockMvc(); mockMvc.perform(get("/management/beans")).andExpect(status().isOk()); } @@ -137,7 +136,7 @@ public class MvcEndpointIntegrationTests { } @Import(DefaultConfiguration.class) - @ImportAutoConfiguration({ SecurityAutoConfiguration.class}) + @ImportAutoConfiguration({ SecurityAutoConfiguration.class }) static class SecureConfiguration { } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/StatusEndpointWebIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/StatusEndpointWebIntegrationTests.java index 05ac7e0a10..9ae5145354 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/StatusEndpointWebIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/StatusEndpointWebIntegrationTests.java @@ -57,8 +57,8 @@ public class StatusEndpointWebIntegrationTests { context.getBean("alphaHealthIndicator", TestHealthIndicator.class) .setHealth(Health.down().build()); client.get().uri("/application/status").exchange().expectStatus() - .isEqualTo(HttpStatus.SERVICE_UNAVAILABLE) - .expectBody().json("{\"status\":\"DOWN\"}"); + .isEqualTo(HttpStatus.SERVICE_UNAVAILABLE).expectBody() + .json("{\"status\":\"DOWN\"}"); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/WebEndpointsRunner.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/WebEndpointsRunner.java index fe4ed575bb..a09e428dc2 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/WebEndpointsRunner.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/WebEndpointsRunner.java @@ -78,9 +78,8 @@ import org.springframework.web.util.DefaultUriBuilderFactory.EncodingMode; * The {@link PropertySource PropertySources} that belong to the application context's * {@link org.springframework.core.env.Environment} are reset at the end of every test. * This means that {@link TestPropertyValues} can be used in a test without affecting the - * {@code Environment} of other tests in the same class. - * The runner always sets the flag `endpoints.default.web.enabled` to true so that web - * endpoints are enabled. + * {@code Environment} of other tests in the same class. The runner always sets the flag + * `endpoints.default.web.enabled` to true so that web endpoints are enabled. * * @author Andy Wilkinson */ @@ -266,7 +265,8 @@ public class WebEndpointsRunner extends Suite { private ReactiveWebEndpointsRunner(Class klass) throws InitializationError { super(klass, "Reactive", (classes) -> { ReactiveWebServerApplicationContext context = new ReactiveWebServerApplicationContext(); - TestPropertyValues.of("endpoints.default.web.enabled:true").applyTo(context); + TestPropertyValues.of("endpoints.default.web.enabled:true") + .applyTo(context); classes.add(ReactiveInfrastructureConfiguration.class); context.register(classes.toArray(new Class[classes.size()])); context.refresh(); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java index eb7adeee46..619c5a8a22 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/test/java/org/springframework/boot/actuate/health/HealthIndicatorFactoryTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthIndicatorFactoryTests.java index 2101f09cea..d6a7170db5 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthIndicatorFactoryTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthIndicatorFactoryTests.java @@ -62,8 +62,8 @@ public class HealthIndicatorFactoryTests { private HealthIndicator createHealthIndicator( Map healthIndicators) { - return new HealthIndicatorFactory().createHealthIndicator( - new OrderedHealthAggregator(), healthIndicators); + return new HealthIndicatorFactory() + .createHealthIndicator(new OrderedHealthAggregator(), healthIndicators); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java index 5a25acc3ef..40d56eaab7 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java @@ -51,12 +51,14 @@ public class RedisHealthIndicatorTests { @Test public void indicatorExists() { - new ApplicationContextRunner().withConfiguration(AutoConfigurations.of( - RedisAutoConfiguration.class, EndpointAutoConfiguration.class, - HealthIndicatorAutoConfiguration.class)).run((context) -> { - assertThat(context).hasSingleBean(RedisConnectionFactory.class); - assertThat(context).hasSingleBean(RedisHealthIndicator.class); - }); + new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class, + EndpointAutoConfiguration.class, + HealthIndicatorAutoConfiguration.class)) + .run((context) -> { + assertThat(context).hasSingleBean(RedisConnectionFactory.class); + assertThat(context).hasSingleBean(RedisHealthIndicator.class); + }); } @Test @@ -74,8 +76,8 @@ public class RedisHealthIndicatorTests { @Test public void redisIsDown() throws Exception { RedisConnection redisConnection = mock(RedisConnection.class); - given(redisConnection.info()).willThrow( - new RedisConnectionFailureException("Connection failed")); + given(redisConnection.info()) + .willThrow(new RedisConnectionFailureException("Connection failed")); RedisHealthIndicator healthIndicator = createHealthIndicator(redisConnection); Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.DOWN); @@ -83,9 +85,9 @@ public class RedisHealthIndicatorTests { .contains("Connection failed"); } - private RedisHealthIndicator createHealthIndicator( - RedisConnection redisConnection) { - RedisConnectionFactory redisConnectionFactory = mock(RedisConnectionFactory.class); + private RedisHealthIndicator createHealthIndicator(RedisConnection redisConnection) { + RedisConnectionFactory redisConnectionFactory = mock( + RedisConnectionFactory.class); given(redisConnectionFactory.getConnection()).willReturn(redisConnection); return new RedisHealthIndicator(redisConnectionFactory); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java index c83a1feb7f..d1ebd03a23 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java index 9496432a8f..bb89354991 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.java index c11e1c2e0a..00c8e65e00 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.java @@ -50,12 +50,12 @@ import org.springframework.util.ReflectionUtils; /** * Configuration for a Spring Security in-memory {@link AuthenticationManager}. Can be - * disabled by providing a bean of type {@link AuthenticationManager}, {@link AuthenticationProvider} - * or {@link UserDetailsService}. The value provided by this configuration will become the "global" - * authentication manager (from Spring Security), or the parent of the global instance. - * Thus it acts as a fallback when no others are provided, is used by method security if - * enabled, and as a parent authentication manager for "local" authentication managers in - * individual filter chains. + * disabled by providing a bean of type {@link AuthenticationManager}, + * {@link AuthenticationProvider} or {@link UserDetailsService}. The value provided by + * this configuration will become the "global" authentication manager (from Spring + * Security), or the parent of the global instance. Thus it acts as a fallback when no + * others are provided, is used by method security if enabled, and as a parent + * authentication manager for "local" authentication managers in individual filter chains. * * @author Dave Syer * @author Rob Winch @@ -63,8 +63,8 @@ import org.springframework.util.ReflectionUtils; */ @Configuration @ConditionalOnBean(ObjectPostProcessor.class) -@ConditionalOnMissingBean({ AuthenticationManager.class, - AuthenticationProvider.class, UserDetailsService.class}) +@ConditionalOnMissingBean({ AuthenticationManager.class, AuthenticationProvider.class, + UserDetailsService.class }) @Order(0) public class AuthenticationManagerConfiguration { @@ -102,8 +102,8 @@ public class AuthenticationManagerConfiguration { * {@link GlobalAuthenticationConfigurerAdapter#init(AuthenticationManagerBuilder)} * exists that adds a {@link SecurityConfigurer} to the * {@link AuthenticationManagerBuilder}. - *

  • {@link AuthenticationManagerConfiguration} - * adds {@link SpringBootAuthenticationConfigurerAdapter} so it is after the + *
  • {@link AuthenticationManagerConfiguration} adds + * {@link SpringBootAuthenticationConfigurerAdapter} so it is after the * {@link SecurityConfigurer} in the first step.
  • *
  • We then can default an {@link AuthenticationProvider} if necessary. Note we can * only invoke the @@ -169,10 +169,9 @@ public class AuthenticationManagerConfiguration { return; } String password = UUID.randomUUID().toString(); - logger.info(String.format("%n%nUsing default security password: %s%n", - password)); - withUser("user").password(password) - .roles(); + logger.info( + String.format("%n%nUsing default security password: %s%n", password)); + withUser("user").password(password).roles(); setField(auth, "defaultUserDetailsService", getUserDetailsService()); super.configure(auth); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java index 1b8e3d1d0c..5a2e8c3577 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java @@ -63,9 +63,11 @@ public class SecurityAutoConfiguration { } @Bean - public SpringBootSecurity springBootSecurity(EndpointPathResolver endpointPathResolver, + public SpringBootSecurity springBootSecurity( + EndpointPathResolver endpointPathResolver, ObjectProvider errorController) { - return new SpringBootSecurity(endpointPathResolver, errorController.getIfAvailable()); + return new SpringBootSecurity(endpointPathResolver, + errorController.getIfAvailable()); } @Bean diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfiguration.java index bfa6e6ccb9..4e1b8991d4 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfiguration.java @@ -73,8 +73,7 @@ public class SecurityFilterAutoConfiguration { return null; } return securityProperties.getFilterDispatcherTypes().stream() - .map((type) -> DispatcherType.valueOf(type.name())) - .collect(Collectors + .map((type) -> DispatcherType.valueOf(type.name())).collect(Collectors .collectingAndThen(Collectors.toSet(), EnumSet::copyOf)); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java index 5683843c39..0d6667310a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java @@ -66,8 +66,8 @@ public class SecurityProperties implements SecurityPrerequisite { /** * Security filter chain dispatcher types. */ - private Set filterDispatcherTypes = new HashSet<>(Arrays.asList( - DispatcherType.ASYNC, DispatcherType.ERROR, DispatcherType.REQUEST)); + private Set filterDispatcherTypes = new HashSet<>(Arrays + .asList(DispatcherType.ASYNC, DispatcherType.ERROR, DispatcherType.REQUEST)); public Basic getBasic() { return this.basic; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SpringBootSecurity.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SpringBootSecurity.java index d3d480a4e5..7102545e7a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SpringBootSecurity.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SpringBootSecurity.java @@ -31,7 +31,6 @@ import org.springframework.security.web.util.matcher.RequestMatcher; import org.springframework.util.Assert; import org.springframework.util.StringUtils; - /** * Provides request matchers that can be used to configure security for static resources * and the error controller path in a custom {@link WebSecurityConfigurerAdapter}. @@ -68,8 +67,8 @@ public final class SpringBootSecurity { Assert.notEmpty(ids, "At least one endpoint id must be specified."); List pathList = Arrays.asList(ids); if (pathList.contains(ALL_ENDPOINTS)) { - return new AntPathRequestMatcher(this.endpointPathResolver.resolvePath( - ALL_ENDPOINTS), null); + return new AntPathRequestMatcher( + this.endpointPathResolver.resolvePath(ALL_ENDPOINTS), null); } return getEndpointsRequestMatcher(pathList); } @@ -140,4 +139,3 @@ public final class SpringBootSecurity { } } - diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfiguration.java index ec11a21acb..92b6686f4a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfiguration.java @@ -29,10 +29,10 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur /** * The default configuration for web security. It relies on Spring Security's - * content-negotiation strategy to determine what sort of authentication to use. - * If the user specifies their own {@link WebSecurityConfigurerAdapter}, this will - * back-off completely and the users should specify all the bits that they want to - * configure as part of the custom security configuration. + * content-negotiation strategy to determine what sort of authentication to use. If the + * user specifies their own {@link WebSecurityConfigurerAdapter}, this will back-off + * completely and the users should specify all the bits that they want to configure as + * part of the custom security configuration. * * @author Madhura Bhave * @since 2.0.0 @@ -52,6 +52,7 @@ public class SpringBootWebSecurityConfiguration { super.configure(http); http.csrf().disable(); } + } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/WebSecurityEnablerConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/WebSecurityEnablerConfiguration.java index 9d55f707b2..eeda91c3f0 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/WebSecurityEnablerConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/WebSecurityEnablerConfiguration.java @@ -39,5 +39,5 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) @EnableWebSecurity public class WebSecurityEnablerConfiguration { -} +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/EnableOAuth2Sso.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/EnableOAuth2Sso.java index 80b63b29f2..6c291e7385 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/EnableOAuth2Sso.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/EnableOAuth2Sso.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java index 3b6c70901d..ca8fcffa01 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java @@ -86,7 +86,7 @@ public class OAuth2RestOperationsConfiguration { @Configuration @ConditionalOnBean(OAuth2ClientConfiguration.class) - @Conditional({OAuth2ClientIdCondition.class, NoClientCredentialsCondition.class}) + @Conditional({ OAuth2ClientIdCondition.class, NoClientCredentialsCondition.class }) @Import(OAuth2ProtectedResourceDetailsConfiguration.class) protected static class SessionScopedConfiguration { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoDefaultConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoDefaultConfiguration.java index 194bbc00a9..a4658946c4 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoDefaultConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoDefaultConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.java index 1be07609eb..23c188dfaa 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.java @@ -55,8 +55,7 @@ class SessionRepositoryFilterConfiguration { return null; } return servletProperties.getFilterDispatcherTypes().stream() - .map((type) -> DispatcherType.valueOf(type.name())) - .collect(Collectors + .map((type) -> DispatcherType.valueOf(type.name())).collect(Collectors .collectingAndThen(Collectors.toSet(), EnumSet::copyOf)); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java index b1d26dd21c..ae0d34477f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java index d96e7f6ea6..ce7366388d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java @@ -95,8 +95,8 @@ public class FlywayAutoConfigurationTests { @Test public void createDataSource() throws Exception { - TestPropertyValues.of("spring.flyway.url:jdbc:hsqldb:mem:flywaytest", "spring.flyway.user:sa") - .applyTo(this.context); + TestPropertyValues.of("spring.flyway.url:jdbc:hsqldb:mem:flywaytest", + "spring.flyway.user:sa").applyTo(this.context); registerAndRefresh(EmbeddedDataSourceConfiguration.class, FlywayAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); @@ -162,7 +162,8 @@ public class FlywayAutoConfigurationTests { @Test public void changeLogDoesNotExist() throws Exception { - TestPropertyValues.of("spring.flyway.locations:file:no-such-dir").applyTo(this.context); + TestPropertyValues.of("spring.flyway.locations:file:no-such-dir") + .applyTo(this.context); this.thrown.expect(BeanCreationException.class); registerAndRefresh(EmbeddedDataSourceConfiguration.class, FlywayAutoConfiguration.class, diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java index 1c45887217..53c75561ed 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java @@ -318,7 +318,8 @@ public class DataSourceAutoConfigurationTests { @Override protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - for (EmbeddedDatabaseConnection candidate : EmbeddedDatabaseConnection.values()) { + for (EmbeddedDatabaseConnection candidate : EmbeddedDatabaseConnection + .values()) { if (name.equals(candidate.getDriverClassName())) { throw new ClassNotFoundException(); } @@ -328,5 +329,4 @@ public class DataSourceAutoConfigurationTests { } - } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java index d4b4ddf192..92a64ccb61 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfigurationTests.java index 13e2cbc130..4f00ec9cb7 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java index 72b6462078..d885290546 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java @@ -160,7 +160,8 @@ public class LiquibaseAutoConfigurationTests { @Test public void testOverrideDefaultSchema() throws Exception { - TestPropertyValues.of("spring.liquibase.default-schema:public").applyTo(this.context); + TestPropertyValues.of("spring.liquibase.default-schema:public") + .applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, LiquibaseAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); @@ -182,9 +183,8 @@ public class LiquibaseAutoConfigurationTests { @Test public void testOverrideDataSource() throws Exception { - TestPropertyValues - .of("spring.liquibase.url:jdbc:hsqldb:mem:liquibase", "spring.liquibase.user:sa") - .applyTo(this.context); + TestPropertyValues.of("spring.liquibase.url:jdbc:hsqldb:mem:liquibase", + "spring.liquibase.user:sa").applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, LiquibaseAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); @@ -198,7 +198,8 @@ public class LiquibaseAutoConfigurationTests { @Test(expected = BeanCreationException.class) public void testChangeLogDoesNotExist() throws Exception { - TestPropertyValues.of("spring.liquibase.change-log:classpath:/no-such-changelog.yaml") + TestPropertyValues + .of("spring.liquibase.change-log:classpath:/no-such-changelog.yaml") .applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, LiquibaseAutoConfiguration.class, @@ -220,7 +221,8 @@ public class LiquibaseAutoConfigurationTests { @Test public void testOverrideLabels() throws Exception { - TestPropertyValues.of("spring.liquibase.labels:test, production").applyTo(this.context); + TestPropertyValues.of("spring.liquibase.labels:test, production") + .applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, LiquibaseAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); @@ -232,7 +234,8 @@ public class LiquibaseAutoConfigurationTests { @Test @SuppressWarnings("unchecked") public void testOverrideParameters() throws Exception { - TestPropertyValues.of("spring.liquibase.parameters.foo:bar").applyTo(this.context); + TestPropertyValues.of("spring.liquibase.parameters.foo:bar") + .applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, LiquibaseAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java index 85d8976afb..15ea7fdb50 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java @@ -298,8 +298,8 @@ public class SecurityAutoConfigurationTests { this.context.setServletContext(new MockServletContext()); this.context.register(SecurityAutoConfiguration.class); this.context.refresh(); - String password = this.outputCapture.toString().split("Using default security password: ")[1] - .split("\n")[0].trim(); + String password = this.outputCapture.toString() + .split("Using default security password: ")[1].split("\n")[0].trim(); AuthenticationManager manager = this.context.getBean(AuthenticationManager.class); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( "user", password); @@ -307,16 +307,17 @@ public class SecurityAutoConfigurationTests { } @Test - public void testCustomAuthenticationDoesNotCreateDefaultUser() - throws Exception { + public void testCustomAuthenticationDoesNotCreateDefaultUser() throws Exception { this.context = new AnnotationConfigWebApplicationContext(); this.context.setServletContext(new MockServletContext()); this.context.register(AuthenticationManagerCustomizer.class, SecurityAutoConfiguration.class); this.context.refresh(); AuthenticationManager manager = this.context.getBean(AuthenticationManager.class); - assertThat(this.outputCapture.toString()).doesNotContain("Using default security password: "); - UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("foo", "bar"); + assertThat(this.outputCapture.toString()) + .doesNotContain("Using default security password: "); + UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( + "foo", "bar"); assertThat(manager.authenticate(token)).isNotNull(); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationEarlyInitializationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationEarlyInitializationTests.java index 546fb6a07b..096bc08a0c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationEarlyInitializationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationEarlyInitializationTests.java @@ -61,13 +61,12 @@ public class SecurityFilterAutoConfigurationEarlyInitializationTests { @Test public void testSecurityFilterDoesNotCauseEarlyInitialization() throws Exception { try (AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext()) { - TestPropertyValues.of("server.port:0") - .applyTo(context); + TestPropertyValues.of("server.port:0").applyTo(context); context.register(Config.class); context.refresh(); int port = context.getWebServer().getPort(); - String password = this.outputCapture.toString().split("Using default security password: ")[1] - .split("\n")[0].trim(); + String password = this.outputCapture.toString() + .split("Using default security password: ")[1].split("\n")[0].trim(); new TestRestTemplate("user", password) .getForEntity("http://localhost:" + port, Object.class); // If early initialization occurred a ConverterNotFoundException is thrown @@ -80,8 +79,8 @@ public class SecurityFilterAutoConfigurationEarlyInitializationTests { ConverterBean.class }) @ImportAutoConfiguration({ WebMvcAutoConfiguration.class, JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, - DispatcherServletAutoConfiguration.class, - SecurityAutoConfiguration.class, SecurityFilterAutoConfiguration.class, + DispatcherServletAutoConfiguration.class, SecurityAutoConfiguration.class, + SecurityFilterAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) static class Config { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootSecurityTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootSecurityTests.java index 4e3c6a3c3c..5ad16fb744 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootSecurityTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootSecurityTests.java @@ -46,15 +46,16 @@ public class SpringBootSecurityTests { private MockHttpServletRequest request = new MockHttpServletRequest(); - private static String[] STATIC_RESOURCES = new String[]{"/css/**", "/js/**", - "/images/**", "/webjars/**", "/**/favicon.ico"}; + private static String[] STATIC_RESOURCES = new String[] { "/css/**", "/js/**", + "/images/**", "/webjars/**", "/**/favicon.ico" }; @Rule public ExpectedException thrown = ExpectedException.none(); @Before public void setUp() throws Exception { - this.bootSecurity = new SpringBootSecurity(this.endpointPathResolver, this.errorController); + this.bootSecurity = new SpringBootSecurity(this.endpointPathResolver, + this.errorController); } @Test @@ -65,7 +66,8 @@ public class SpringBootSecurityTests { } @Test - public void endpointIdsShouldReturnRequestMatcherWithEndpointPaths() throws Exception { + public void endpointIdsShouldReturnRequestMatcherWithEndpointPaths() + throws Exception { RequestMatcher requestMatcher = this.bootSecurity.endpointIds("id-1", "id-2"); assertThat(requestMatcher).isInstanceOf(OrRequestMatcher.class); this.request.setServletPath("/test/id-1"); @@ -77,8 +79,10 @@ public class SpringBootSecurityTests { } @Test - public void endpointIdsShouldReturnRequestMatcherWithAllEndpointPaths() throws Exception { - RequestMatcher requestMatcher = this.bootSecurity.endpointIds(SpringBootSecurity.ALL_ENDPOINTS); + public void endpointIdsShouldReturnRequestMatcherWithAllEndpointPaths() + throws Exception { + RequestMatcher requestMatcher = this.bootSecurity + .endpointIds(SpringBootSecurity.ALL_ENDPOINTS); this.request.setServletPath("/test/id-1"); assertThat(requestMatcher.matches(this.request)).isTrue(); this.request.setServletPath("/test/id-2"); @@ -112,7 +116,8 @@ public class SpringBootSecurityTests { } @Test - public void staticResourcesShouldReturnRequestMatcherWithStaticResources() throws Exception { + public void staticResourcesShouldReturnRequestMatcherWithStaticResources() + throws Exception { RequestMatcher requestMatcher = this.bootSecurity.staticResources(); assertThat(requestMatcher).isInstanceOf(OrRequestMatcher.class); for (String resource : STATIC_RESOURCES) { @@ -122,7 +127,8 @@ public class SpringBootSecurityTests { } @Test - public void errorShouldReturnRequestMatcherWithErrorControllerPath() throws Exception { + public void errorShouldReturnRequestMatcherWithErrorControllerPath() + throws Exception { RequestMatcher requestMatcher = this.bootSecurity.error(); assertThat(requestMatcher).isInstanceOf(AntPathRequestMatcher.class); this.request.setServletPath("/test/error"); @@ -152,6 +158,7 @@ public class SpringBootSecurityTests { public String getErrorPath() { return "/test/error"; } + } @Endpoint(id = "id-1") @@ -167,4 +174,5 @@ public class SpringBootSecurityTests { static class FakeEndpoint { } + } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfigurationTests.java index 0b4417f61c..ef3a2a4968 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfigurationTests.java @@ -22,6 +22,7 @@ import org.junit.rules.ExpectedException; import org.mockito.Mockito; import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.web.servlet.MockServletWebServerFactory; import org.springframework.boot.builder.SpringApplicationBuilder; @@ -77,8 +78,7 @@ public class OAuth2RestOperationsConfigurationTests { TestPropertyValues.of("security.oauth2.client.client-id=acme") .applyTo(this.environment); initializeContext(ConfigForRequestScopedConfiguration.class, false); - assertThat(this.context.containsBean("oauth2ClientContext")) - .isTrue(); + assertThat(this.context.containsBean("oauth2ClientContext")).isTrue(); } @Test @@ -93,8 +93,7 @@ public class OAuth2RestOperationsConfigurationTests { TestPropertyValues.of("security.oauth2.client.client-id=acme") .applyTo(this.environment); initializeContext(ConfigForSessionScopedConfiguration.class, false); - assertThat(this.context.containsBean("oauth2ClientContext")) - .isTrue(); + assertThat(this.context.containsBean("oauth2ClientContext")).isTrue(); } @Test @@ -104,10 +103,11 @@ public class OAuth2RestOperationsConfigurationTests { this.context.getBean(DefaultOAuth2ClientContext.class); } - private void initializeContext(Class configuration, boolean isClientCredentials) { + private void initializeContext(Class configuration, boolean clientCredentials) { this.context = new SpringApplicationBuilder(configuration) - .environment(this.environment) - .web(!isClientCredentials).run(); + .environment(this.environment).web(clientCredentials + ? WebApplicationType.NONE : WebApplicationType.SERVLET) + .run(); } @Configuration @@ -123,7 +123,8 @@ public class OAuth2RestOperationsConfigurationTests { @Configuration @Import({ OAuth2ClientConfiguration.class, OAuth2RestOperationsConfiguration.class }) - protected static class ConfigForSessionScopedConfiguration extends WebApplicationConfiguration { + protected static class ConfigForSessionScopedConfiguration + extends WebApplicationConfiguration { @Bean public SecurityProperties securityProperties() { @@ -133,7 +134,8 @@ public class OAuth2RestOperationsConfigurationTests { } @Configuration - protected static class ConfigForRequestScopedConfiguration extends WebApplicationConfiguration { + protected static class ConfigForRequestScopedConfiguration + extends WebApplicationConfiguration { } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/CustomOAuth2SsoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/CustomOAuth2SsoConfigurationTests.java index c87c5dcb48..d1cf5464f1 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/CustomOAuth2SsoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/CustomOAuth2SsoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/CustomOAuth2SsoWithAuthenticationEntryPointConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/CustomOAuth2SsoWithAuthenticationEntryPointConfigurationTests.java index 874ff62e9a..cc2080fd29 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/CustomOAuth2SsoWithAuthenticationEntryPointConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/CustomOAuth2SsoWithAuthenticationEntryPointConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/LaunchedApplication.java b/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/LaunchedApplication.java index 03614442a0..fc754cef9a 100644 --- a/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/LaunchedApplication.java +++ b/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/LaunchedApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-integration-tests/spring-boot-security-tests/spring-boot-security-test-web-helloworld/src/main/java/sample/HelloWebSecurityApplication.java b/spring-boot-integration-tests/spring-boot-security-tests/spring-boot-security-test-web-helloworld/src/main/java/sample/HelloWebSecurityApplication.java index db9b633dfe..06b3a4bdcd 100644 --- a/spring-boot-integration-tests/spring-boot-security-tests/spring-boot-security-test-web-helloworld/src/main/java/sample/HelloWebSecurityApplication.java +++ b/spring-boot-integration-tests/spring-boot-security-tests/spring-boot-security-test-web-helloworld/src/main/java/sample/HelloWebSecurityApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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. @@ -29,7 +29,8 @@ public class HelloWebSecurityApplication { @Bean public UserDetailsService userDetailsService() throws Exception { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser(User.withUsername("user").password("password").roles("USER").build()); + manager.createUser( + User.withUsername("user").password("password").roles("USER").build()); return manager; } diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/pom.xml b/spring-boot-samples/spring-boot-sample-actuator-custom-security/pom.xml index 4c04cc7622..43c8a3cfe2 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/pom.xml +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 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 9ce1e55b5e..cf734a2818 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 @@ -4,7 +4,6 @@ import org.springframework.boot.autoconfigure.security.SpringBootSecurity; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @Configuration @@ -18,13 +17,14 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication() - .withUser("user").password("password").authorities("ROLE_USER").and() - .withUser("admin").password("admin").authorities("ROLE_ACTUATOR", "ROLE_USER"); + auth.inMemoryAuthentication().withUser("user").password("password") + .authorities("ROLE_USER").and().withUser("admin").password("admin") + .authorities("ROLE_ACTUATOR", "ROLE_USER"); } @Override protected void configure(HttpSecurity http) throws Exception { + // @formatter:off http.authorizeRequests() .requestMatchers(this.bootSecurity.endpointIds("status", "info")).permitAll() .requestMatchers(this.bootSecurity.endpointIds(SpringBootSecurity.ALL_ENDPOINTS)).hasRole("ACTUATOR") @@ -35,6 +35,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .cors() .and() .httpBasic(); + // @formatter:on } } diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java index a9737905a9..44541f82af 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java @@ -12,14 +12,10 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.LocalHostUriTemplateHandler; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpStatus; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; @@ -41,7 +37,7 @@ public class CorsSampleActuatorApplicationTests { private TestRestTemplate testRestTemplate; @Autowired - ApplicationContext applicationContext; + private ApplicationContext applicationContext; @Before public void setUp() throws Exception { diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/InsecureManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/InsecureManagementPortAndPathSampleActuatorApplicationTests.java index 06dc039fce..640c44af09 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/InsecureManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/InsecureManagementPortAndPathSampleActuatorApplicationTests.java @@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { - "management.port=0", "management.context-path=/admin"}) + "management.port=0", "management.context-path=/admin" }) @DirtiesContext public class InsecureManagementPortAndPathSampleActuatorApplicationTests { @@ -51,7 +51,6 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests { @Test public void testHome() throws Exception { - @SuppressWarnings("rawtypes") ResponseEntity entity = new TestRestTemplate("user", "password") .getForEntity("http://localhost:" + this.port, String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @@ -77,9 +76,10 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests { @Test public void testMissing() throws Exception { - ResponseEntity entity = new TestRestTemplate("admin", "admin").getForEntity( - "http://localhost:" + this.managementPort + "/admin/missing", - String.class); + ResponseEntity entity = new TestRestTemplate("admin", "admin") + .getForEntity( + "http://localhost:" + this.managementPort + "/admin/missing", + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); assertThat(entity.getBody()).contains("\"status\":404"); } diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java index 2e86ff7b63..fdca55998a 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java @@ -44,22 +44,22 @@ public class SampleActuatorCustomSecurityApplicationTests { assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); @SuppressWarnings("unchecked") Map body = entity.getBody(); - assertThat((String)body.get("message")).contains("Expected exception in controller"); + assertThat((String) body.get("message")) + .contains("Expected exception in controller"); } @Test public void testInsecureStaticResources() throws Exception { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); + ResponseEntity entity = this.restTemplate + .getForEntity("/css/bootstrap.min.css", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("body"); } @Test public void insecureActuator() throws Exception { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.getForEntity("/application/status", - String.class); + ResponseEntity entity = this.restTemplate + .getForEntity("/application/status", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); } diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleActuatorLog4J2Application.java b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleActuatorLog4J2Application.java index 5455223c41..b3135d68d4 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleActuatorLog4J2Application.java +++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleActuatorLog4J2Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2017 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. @@ -29,7 +29,8 @@ public class SampleActuatorLog4J2Application { @Bean public UserDetailsService userDetailsService() throws Exception { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser(User.withUsername("user").password("password").roles("USER").build()); + manager.createUser( + User.withUsername("user").password("password").roles("USER").build()); return manager; } diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java index a63bdcd006..87e7d92feb 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java @@ -65,17 +65,16 @@ public class SampleActuatorLog4J2ApplicationTests { @Test public void validateLoggersEndpoint() throws Exception { - this.mvc.perform(get("/application/loggers/org.apache.coyote.http11.Http11NioProtocol") - .header("Authorization", "Basic " + getBasicAuth())) + this.mvc.perform( + get("/application/loggers/org.apache.coyote.http11.Http11NioProtocol") + .header("Authorization", "Basic " + getBasicAuth())) .andExpect(status().isOk()) .andExpect(content().string(equalTo("{\"configuredLevel\":\"WARN\"," + "\"effectiveLevel\":\"WARN\"}"))); } private String getBasicAuth() { - return new String(Base64.getEncoder() - .encode(("user:password").getBytes())); + return new String(Base64.getEncoder().encode(("user:password").getBytes())); } } - diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/java/sample/actuator/ui/SampleActuatorUiApplication.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/java/sample/actuator/ui/SampleActuatorUiApplication.java index f36399f132..30774fdc0d 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/java/sample/actuator/ui/SampleActuatorUiApplication.java +++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/java/sample/actuator/ui/SampleActuatorUiApplication.java @@ -36,7 +36,8 @@ public class SampleActuatorUiApplication { @Bean public UserDetailsService userDetailsService() throws Exception { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser(User.withUsername("user").password("password").roles("USER").build()); + manager.createUser( + User.withUsername("user").password("password").roles("USER").build()); return manager; } diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java index 9f373d9435..73d127b97e 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java @@ -54,9 +54,9 @@ public class SampleActuatorUiApplicationTests { public void testHome() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()) - .exchange("/", HttpMethod.GET, - new HttpEntity(headers), String.class); + ResponseEntity entity = this.restTemplate + .withBasicAuth("user", getPassword()).exchange("/", HttpMethod.GET, + new HttpEntity(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("Hello"); } @@ -72,8 +72,8 @@ public class SampleActuatorUiApplicationTests { @Test public void testMetrics() throws Exception { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.getForEntity("/application/metrics", - Map.class); + ResponseEntity<Map> entity = this.restTemplate + .getForEntity("/application/metrics", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @@ -81,9 +81,9 @@ public class SampleActuatorUiApplicationTests { public void testError() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) - .exchange("/error", - HttpMethod.GET, new HttpEntity<Void>(headers), String.class); + ResponseEntity<String> entity = this.restTemplate + .withBasicAuth("user", getPassword()).exchange("/error", HttpMethod.GET, + new HttpEntity<Void>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(entity.getBody()).contains("<html>").contains("<body>") .contains("Please contact the operator with the above information"); diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleActuatorApplication.java b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleActuatorApplication.java index 44930055de..61c068da70 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleActuatorApplication.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleActuatorApplication.java @@ -22,7 +22,6 @@ import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.provisioning.InMemoryUserDetailsManager; @@ -38,17 +37,20 @@ public class SampleActuatorApplication { @Bean public UserDetailsService userDetailsService() throws Exception { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser(User.withUsername("user").password("password").roles("USER").build()); + manager.createUser( + User.withUsername("user").password("password").roles("USER").build()); return manager; } @Bean public HealthIndicator helloHealthIndicator() { return new HealthIndicator() { + @Override public Health health() { return Health.up().withDetail("hello", "world").build(); } + }; } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java index 61d358a517..5c5c3d7f50 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java index 169f4db003..8ef544d05e 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java index 67440a15bf..37260bc76a 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java @@ -104,8 +104,9 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { @Test public void testManagementErrorPage() throws Exception { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()).getForEntity( - "http://localhost:" + this.managementPort + "/error", Map.class); + ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) + .getForEntity("http://localhost:" + this.managementPort + "/error", + Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java index 0aca403e3d..082d7356ab 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java @@ -18,14 +18,12 @@ package sample.actuator; import java.util.Map; -import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.actuate.web.server.LocalManagementPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.rule.OutputCapture; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpStatus; @@ -86,8 +84,9 @@ public class ManagementPortSampleActuatorApplicationTests { @Test public void testErrorPage() throws Exception { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()).getForEntity( - "http://localhost:" + this.managementPort + "/error", Map.class); + ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) + .getForEntity("http://localhost:" + this.managementPort + "/error", + Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java index f3b5178d4a..49cb18b92c 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java index aed5cd189f..5b71cb3d29 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java @@ -200,8 +200,8 @@ public class SampleActuatorApplicationTests { @Test public void testErrorPageDirectAccess() throws Exception { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/error", Map.class); + ResponseEntity<Map> entity = this.restTemplate + .withBasicAuth("user", getPassword()).getForEntity("/error", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); diff --git a/spring-boot-samples/spring-boot-sample-secure-oauth2-actuator/src/main/java/sample/secure/oauth2/actuator/ActuatorSecurityConfiguration.java b/spring-boot-samples/spring-boot-sample-secure-oauth2-actuator/src/main/java/sample/secure/oauth2/actuator/ActuatorSecurityConfiguration.java index 5405df6556..aa33d0829d 100644 --- a/spring-boot-samples/spring-boot-sample-secure-oauth2-actuator/src/main/java/sample/secure/oauth2/actuator/ActuatorSecurityConfiguration.java +++ b/spring-boot-samples/spring-boot-sample-secure-oauth2-actuator/src/main/java/sample/secure/oauth2/actuator/ActuatorSecurityConfiguration.java @@ -12,7 +12,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur * @author Madhura Bhave */ @Configuration -@Order(2) //before the resource server configuration +@Order(2) // before the resource server configuration public class ActuatorSecurityConfiguration extends WebSecurityConfigurerAdapter { private final SpringBootSecurity springBootSecurity; @@ -23,9 +23,9 @@ public class ActuatorSecurityConfiguration extends WebSecurityConfigurerAdapter @Override protected void configure(HttpSecurity http) throws Exception { - http.requestMatcher(this.springBootSecurity.endpointIds(SpringBootSecurity.ALL_ENDPOINTS)) - .authorizeRequests().antMatchers("/**").authenticated() - .and() - .httpBasic(); + http.requestMatcher( + this.springBootSecurity.endpointIds(SpringBootSecurity.ALL_ENDPOINTS)) + .authorizeRequests().antMatchers("/**").authenticated().and().httpBasic(); } + } diff --git a/spring-boot-samples/spring-boot-sample-secure-oauth2-actuator/src/main/java/sample/secure/oauth2/actuator/SampleSecureOAuth2ActuatorApplication.java b/spring-boot-samples/spring-boot-sample-secure-oauth2-actuator/src/main/java/sample/secure/oauth2/actuator/SampleSecureOAuth2ActuatorApplication.java index 1bef7723a4..0f9d8199ed 100644 --- a/spring-boot-samples/spring-boot-sample-secure-oauth2-actuator/src/main/java/sample/secure/oauth2/actuator/SampleSecureOAuth2ActuatorApplication.java +++ b/spring-boot-samples/spring-boot-sample-secure-oauth2-actuator/src/main/java/sample/secure/oauth2/actuator/SampleSecureOAuth2ActuatorApplication.java @@ -41,7 +41,8 @@ public class SampleSecureOAuth2ActuatorApplication { @Bean public UserDetailsService userDetailsService() throws Exception { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser(User.withUsername("user").password("password").roles("USER").build()); + manager.createUser( + User.withUsername("user").password("password").roles("USER").build()); return manager; } diff --git a/spring-boot-samples/spring-boot-sample-secure-oauth2/src/main/java/sample/secure/oauth2/AuthenticationConfiguration.java b/spring-boot-samples/spring-boot-sample-secure-oauth2/src/main/java/sample/secure/oauth2/AuthenticationConfiguration.java index 81ca2cff77..a2bca3dc86 100644 --- a/spring-boot-samples/spring-boot-sample-secure-oauth2/src/main/java/sample/secure/oauth2/AuthenticationConfiguration.java +++ b/spring-boot-samples/spring-boot-sample-secure-oauth2/src/main/java/sample/secure/oauth2/AuthenticationConfiguration.java @@ -12,6 +12,7 @@ public class AuthenticationConfiguration extends GlobalAuthenticationConfigurerA @Override public void init(AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication().withUser("greg").password("turnquist").roles("read"); + auth.inMemoryAuthentication().withUser("greg").password("turnquist") + .roles("read"); } } diff --git a/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java b/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java index a901c22c0a..8c3c05b4ae 100644 --- a/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java +++ b/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2017 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. @@ -41,7 +41,8 @@ public class SampleSecureApplication implements CommandLineRunner { @Bean public UserDetailsService userDetailsService() throws Exception { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser(User.withUsername("user").password("password").roles("USER").build()); + manager.createUser( + User.withUsername("user").password("password").roles("USER").build()); return manager; } diff --git a/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java b/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java index c8d2b481b0..98adaba99c 100644 --- a/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = {SampleSecureApplication.class}) +@SpringBootTest(classes = { SampleSecureApplication.class }) public class SampleSecureApplicationTests { @Autowired diff --git a/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java b/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java index 8dbbcfb59c..3a35fa5bc4 100644 --- a/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java +++ b/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java @@ -41,7 +41,8 @@ public class SampleServletApplication extends SpringBootServletInitializer { @Bean public UserDetailsService userDetailsService() throws Exception { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser(User.withUsername("user").password("password").roles("USER").build()); + manager.createUser( + User.withUsername("user").password("password").roles("USER").build()); return manager; } diff --git a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java b/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java index 6861e118de..2aafda206b 100644 --- a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -53,7 +53,8 @@ public class SampleServletApplicationTests { public void testHomeIsSecure() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); - ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, + new HttpEntity<Void>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } 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 5a459bdc1f..a6896718bc 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 @@ -105,11 +105,9 @@ public class SampleMethodSecurityApplication implements WebMvcConfigurer { @Override protected void configure(HttpSecurity http) throws Exception { - http - .requestMatcher(this.springBootSecurity.endpointIds(SpringBootSecurity.ALL_ENDPOINTS)) - .authorizeRequests().anyRequest().authenticated() - .and() - .httpBasic(); + http.requestMatcher( + this.springBootSecurity.endpointIds(SpringBootSecurity.ALL_ENDPOINTS)) + .authorizeRequests().anyRequest().authenticated().and().httpBasic(); } } diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java index fee2546c87..bdc0544b3a 100644 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java @@ -107,8 +107,8 @@ public class SampleMethodSecurityApplicationTests { public void testManagementProtected() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); - ResponseEntity<String> entity = this.restTemplate - .exchange("/application/beans", HttpMethod.GET, new HttpEntity<Void>(headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/application/beans", + HttpMethod.GET, new HttpEntity<Void>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/main/java/sample/web/secure/SampleWebSecureApplication.java b/spring-boot-samples/spring-boot-sample-web-secure/src/main/java/sample/web/secure/SampleWebSecureApplication.java index 46547a0431..ba85cc071e 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure/src/main/java/sample/web/secure/SampleWebSecureApplication.java +++ b/spring-boot-samples/spring-boot-sample-web-secure/src/main/java/sample/web/secure/SampleWebSecureApplication.java @@ -70,8 +70,8 @@ public class SampleWebSecureApplication implements WebMvcConfigurer { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() - .requestMatchers(this.springBootSecurity.staticResources()).permitAll() - .anyRequest().fullyAuthenticated().and().formLogin() + .requestMatchers(this.springBootSecurity.staticResources()) + .permitAll().anyRequest().fullyAuthenticated().and().formLogin() .loginPage("/login").failureUrl("/login?error").permitAll().and() .logout().permitAll(); } diff --git a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/AutoConfigureTestDatabase.java b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/AutoConfigureTestDatabase.java index 41c677dcb0..d76440f7e3 100644 --- a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/AutoConfigureTestDatabase.java +++ b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/AutoConfigureTestDatabase.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java index 6aa8fcd1c0..a4e8224c58 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java index 3d9b03229e..94ee9ca067 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java index 6d0c09fc6f..77b4c6d95e 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests.java index bd459250c1..550e5edc74 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/MockMvcSecurityAutoConfigurationIntegrationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/MockMvcSecurityAutoConfigurationIntegrationTests.java index 8d596764ce..95b4700567 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/MockMvcSecurityAutoConfigurationIntegrationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/MockMvcSecurityAutoConfigurationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -44,7 +44,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. public class MockMvcSecurityAutoConfigurationIntegrationTests { @Autowired - MockMvc mockMvc; + private MockMvc mockMvc; @Test @WithMockUser(username = "test", password = "test", roles = "USER") @@ -54,8 +54,8 @@ public class MockMvcSecurityAutoConfigurationIntegrationTests { @Test public void unauthorizedResponseWithNoUser() throws Exception { - this.mockMvc.perform(get("/") - .accept(MediaType.APPLICATION_JSON)).andExpect(status().isUnauthorized()); + this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isUnauthorized()); } @Test diff --git a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/SecurityTestApplication.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/SecurityTestApplication.java index 26150503b6..86ba68eacc 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/SecurityTestApplication.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/SecurityTestApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -37,7 +37,8 @@ public class SecurityTestApplication { @Bean public UserDetailsService userDetailsService() throws Exception { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser(User.withUsername("user").password("secret").roles("USER").build()); + manager.createUser( + User.withUsername("user").password("secret").roles("USER").build()); return manager; } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/util/EnvironmentTestUtils.java b/spring-boot-test/src/main/java/org/springframework/boot/test/util/EnvironmentTestUtils.java index e85d393ad9..f42d83dc75 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/util/EnvironmentTestUtils.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/util/EnvironmentTestUtils.java @@ -73,8 +73,8 @@ public abstract class EnvironmentTestUtils { Map<String, Object> map = getOrAdd(sources, name); for (String pair : pairs) { int index = getSeparatorIndex(pair); - String key = index > 0 ? pair.substring(0, index) : pair; - String value = index > 0 ? pair.substring(index + 1) : ""; + String key = (index > 0 ? pair.substring(0, index) : pair); + String value = (index > 0 ? pair.substring(index + 1) : ""); map.put(key.trim(), value.trim()); } } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java b/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java index b92fae77bf..6a9372c658 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java @@ -252,8 +252,8 @@ public final class TestPropertyValues { public static Pair parse(String pair) { int index = getSeparatorIndex(pair); - String key = index > 0 ? pair.substring(0, index) : pair; - String value = index > 0 ? pair.substring(index + 1) : ""; + String key = (index > 0 ? pair.substring(0, index) : pair); + String value = (index > 0 ? pair.substring(index + 1) : ""); return of(key.trim(), value.trim()); } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java index 7742b0920f..04c504a3a6 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java @@ -19,12 +19,13 @@ package org.springframework.boot.configurationprocessor; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.io.StringWriter; -import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.ProcessingEnvironment; @@ -148,7 +149,6 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor processEndpoint(element); } } - if (roundEnv.processingOver()) { try { writeMetaData(); @@ -372,27 +372,30 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor enabledByDefault = Boolean.TRUE; } String type = this.typeUtils.getQualifiedName(element); - this.metadataCollector.add(ItemMetadata.newGroup(endpointKey(endpointId), - type, type, null)); + this.metadataCollector + .add(ItemMetadata.newGroup(endpointKey(endpointId), type, type, null)); this.metadataCollector.add(ItemMetadata.newProperty(endpointKey(endpointId), - "enabled", Boolean.class.getName(), type, null, String.format( - "Enable the %s endpoint.", endpointId), enabledByDefault, null)); + "enabled", Boolean.class.getName(), type, null, + String.format("Enable the %s endpoint.", endpointId), enabledByDefault, + null)); this.metadataCollector.add(ItemMetadata.newProperty(endpointKey(endpointId), "cache.time-to-live", Long.class.getName(), type, null, "Maximum time in milliseconds that a response can be cached.", 0, null)); - - EndpointTypes endpointTypes = EndpointTypes.parse(elementValues.get("types")); + EndpointExposure endpointTypes = EndpointExposure + .parse(elementValues.get("exposure")); if (endpointTypes.hasJmx()) { this.metadataCollector.add(ItemMetadata.newProperty( endpointKey(endpointId + ".jmx"), "enabled", Boolean.class.getName(), - type, null, String.format("Expose the %s endpoint as a JMX MBean.", - endpointId), enabledByDefault, null)); + type, null, + String.format("Expose the %s endpoint as a JMX MBean.", endpointId), + enabledByDefault, null)); } if (endpointTypes.hasWeb()) { this.metadataCollector.add(ItemMetadata.newProperty( endpointKey(endpointId + ".web"), "enabled", Boolean.class.getName(), type, null, String.format("Expose the %s endpoint as a Web endpoint.", - endpointId), false, null)); + endpointId), + false, null)); } } @@ -400,7 +403,6 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor return "endpoints." + suffix; } - private boolean isNested(Element returnType, VariableElement field, TypeElement element) { if (hasAnnotation(field, nestedConfigurationPropertyAnnotation())) { @@ -521,39 +523,44 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor this.processingEnv.getMessager().printMessage(kind, msg); } - private static class EndpointTypes { + private static class EndpointExposure { - private static final List<String> ALL_TYPES = Arrays.asList("JMX", "WEB"); + private static final List<String> ALL = Arrays.asList("JMX", "WEB"); private final List<String> types; - EndpointTypes(List<String> types) { + EndpointExposure(List<String> types) { this.types = types; } - static EndpointTypes parse(Object typesAttribute) { - if (!(typesAttribute instanceof List)) { - return new EndpointTypes(ALL_TYPES); - } - List<AnnotationValue> values = (List<AnnotationValue>) typesAttribute; + static EndpointExposure parse(Object exposureAttribute) { + List<AnnotationValue> values = asAnnotationValues(exposureAttribute); if (values.isEmpty()) { - return new EndpointTypes(ALL_TYPES); + return new EndpointExposure(ALL); } - List<String> types = new ArrayList<>(); - for (AnnotationValue value : values) { - types.add(((VariableElement) value.getValue()).getSimpleName().toString()); - } - return new EndpointTypes(types); + return new EndpointExposure( + values.stream().map(EndpointExposure::getValueAttribute) + .collect(Collectors.toList())); + } + @SuppressWarnings("unchecked") + private static List<AnnotationValue> asAnnotationValues(Object typesAttribute) { + if (!(typesAttribute instanceof List)) { + return Collections.emptyList(); + } + return (List<AnnotationValue>) typesAttribute; + } + + private static String getValueAttribute(AnnotationValue value) { + return ((VariableElement) value.getValue()).getSimpleName().toString(); } public boolean hasJmx() { - return this.types.contains("JMX"); + return this.types.contains("JMX"); } - public boolean hasWeb() { - return this.types.contains("WEB"); + return this.types.contains("WEB"); } } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java index 7dbfcaa66e..5e78ac0326 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java @@ -211,12 +211,12 @@ public class ConfigurationMetadata { @Override public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(String.format("items: %n")); + StringBuilder result = new StringBuilder(); + result.append(String.format("items: %n")); this.items.values().forEach(itemMetadata -> { - sb.append("\t").append(String.format("%s%n", itemMetadata)); + result.append("\t").append(String.format("%s%n", itemMetadata)); }); - return sb.toString(); + return result.toString(); } } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java index a2d931b2b8..11bfafe330 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java @@ -524,12 +524,11 @@ public class ConfigurationMetadataAnnotationProcessorTests { assertThat(metadata.getItems()).hasSize(3); } - @Test public void simpleEndpoint() throws IOException { ConfigurationMetadata metadata = compile(SimpleEndpoint.class); - assertThat(metadata).has(Metadata.withGroup("endpoints.simple") - .fromSource(SimpleEndpoint.class)); + assertThat(metadata).has( + Metadata.withGroup("endpoints.simple").fromSource(SimpleEndpoint.class)); assertThat(metadata).has(enabledFlag("simple", true)); assertThat(metadata).has(jmxEnabledFlag("simple", true)); assertThat(metadata).has(webEnabledFlag("simple", false)); @@ -554,8 +553,8 @@ public class ConfigurationMetadataAnnotationProcessorTests { ConfigurationMetadata metadata = compile(CustomPropertiesEndpoint.class); assertThat(metadata).has(Metadata.withGroup("endpoints.customprops") .fromSource(CustomPropertiesEndpoint.class)); - assertThat(metadata).has(Metadata.withProperty("endpoints.customprops.name"). - ofType(String.class).withDefaultValue("test")); + assertThat(metadata).has(Metadata.withProperty("endpoints.customprops.name") + .ofType(String.class).withDefaultValue("test")); assertThat(metadata).has(enabledFlag("customprops", true)); assertThat(metadata).has(jmxEnabledFlag("customprops", true)); assertThat(metadata).has(webEnabledFlag("customprops", false)); @@ -566,8 +565,8 @@ public class ConfigurationMetadataAnnotationProcessorTests { @Test public void jmxOnlyEndpoint() throws IOException { ConfigurationMetadata metadata = compile(OnlyJmxEndpoint.class); - assertThat(metadata).has(Metadata.withGroup("endpoints.jmx") - .fromSource(OnlyJmxEndpoint.class)); + assertThat(metadata).has( + Metadata.withGroup("endpoints.jmx").fromSource(OnlyJmxEndpoint.class)); assertThat(metadata).has(enabledFlag("jmx", true)); assertThat(metadata).has(jmxEnabledFlag("jmx", true)); assertThat(metadata).has(cacheTtl("jmx")); @@ -577,8 +576,8 @@ public class ConfigurationMetadataAnnotationProcessorTests { @Test public void webOnlyEndpoint() throws IOException { ConfigurationMetadata metadata = compile(OnlyWebEndpoint.class); - assertThat(metadata).has(Metadata.withGroup("endpoints.web") - .fromSource(OnlyWebEndpoint.class)); + assertThat(metadata).has( + Metadata.withGroup("endpoints.web").fromSource(OnlyWebEndpoint.class)); assertThat(metadata).has(enabledFlag("web", true)); assertThat(metadata).has(webEnabledFlag("web", false)); assertThat(metadata).has(cacheTtl("web")); @@ -622,7 +621,8 @@ public class ConfigurationMetadataAnnotationProcessorTests { assertThat(metadata).has(cacheTtl("incremental")); assertThat(metadata.getItems()).hasSize(5); project.replaceText(IncrementalEndpoint.class, "id = \"incremental\"", - "id = \"incremental\", types = Endpoint.Type.WEB"); + "id = \"incremental\", exposure = org.springframework.boot." + + "configurationsample.EndpointExposure.WEB"); metadata = project.incrementalBuild(IncrementalEndpoint.class); assertThat(metadata).has(Metadata.withGroup("endpoints.incremental") .fromSource(IncrementalEndpoint.class)); @@ -643,8 +643,8 @@ public class ConfigurationMetadataAnnotationProcessorTests { assertThat(metadata).has(jmxEnabledFlag("incremental", true)); assertThat(metadata).has(cacheTtl("incremental")); assertThat(metadata.getItems()).hasSize(4); - project.replaceText(IncrementalJmxEndpoint.class, ", types = Endpoint.Type.JMX", - ""); + project.replaceText(IncrementalJmxEndpoint.class, + ", exposure = EndpointExposure.JMX", ""); metadata = project.incrementalBuild(IncrementalJmxEndpoint.class); assertThat(metadata).has(Metadata.withGroup("endpoints.incremental") .fromSource(IncrementalJmxEndpoint.class)); @@ -658,22 +658,22 @@ public class ConfigurationMetadataAnnotationProcessorTests { private Metadata.MetadataItemCondition enabledFlag(String endpointId, boolean defaultValue) { return Metadata.withEnabledFlag("endpoints." + endpointId + ".enabled") - .withDefaultValue(defaultValue).withDescription( - String.format("Enable the %s endpoint.", endpointId)); + .withDefaultValue(defaultValue) + .withDescription(String.format("Enable the %s endpoint.", endpointId)); } private Metadata.MetadataItemCondition jmxEnabledFlag(String endpointId, boolean defaultValue) { return Metadata.withEnabledFlag("endpoints." + endpointId + ".jmx.enabled") - .withDefaultValue(defaultValue).withDescription(String.format( - "Expose the %s endpoint as a JMX MBean.", endpointId)); + .withDefaultValue(defaultValue).withDescription(String + .format("Expose the %s endpoint as a JMX MBean.", endpointId)); } private Metadata.MetadataItemCondition webEnabledFlag(String endpointId, boolean defaultValue) { return Metadata.withEnabledFlag("endpoints." + endpointId + ".web.enabled") - .withDefaultValue(defaultValue).withDescription(String.format( - "Expose the %s endpoint as a Web endpoint.", endpointId)); + .withDefaultValue(defaultValue).withDescription(String + .format("Expose the %s endpoint as a Web endpoint.", endpointId)); } private Metadata.MetadataItemCondition cacheTtl(String endpointId) { diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/Endpoint.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/Endpoint.java index b685e69353..02eed09a71 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/Endpoint.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/Endpoint.java @@ -37,14 +37,6 @@ public @interface Endpoint { boolean enabledByDefault() default true; - Type[] types() default {}; - - enum Type { - - JMX, - - WEB - - } + EndpointExposure[] exposure() default {}; } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/EndpointExposure.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/EndpointExposure.java new file mode 100644 index 0000000000..1a82c18932 --- /dev/null +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/EndpointExposure.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.configurationsample; + +public enum EndpointExposure { + + JMX, + + WEB + +} diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyJmxEndpoint.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyJmxEndpoint.java index a4e86b9936..a44b4d0530 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyJmxEndpoint.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyJmxEndpoint.java @@ -17,13 +17,14 @@ package org.springframework.boot.configurationsample.endpoint; import org.springframework.boot.configurationsample.Endpoint; +import org.springframework.boot.configurationsample.EndpointExposure; /** * An endpoint that only exposes a JMX MBean. * * @author Stephane Nicoll */ -@Endpoint(id = "jmx", types = Endpoint.Type.JMX) +@Endpoint(id = "jmx", exposure = EndpointExposure.JMX) public class OnlyJmxEndpoint { } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyWebEndpoint.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyWebEndpoint.java index 687744dcb6..fe204f28a2 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyWebEndpoint.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyWebEndpoint.java @@ -17,13 +17,14 @@ package org.springframework.boot.configurationsample.endpoint; import org.springframework.boot.configurationsample.Endpoint; +import org.springframework.boot.configurationsample.EndpointExposure; /** * An endpoints that only exposes a web endpoint. * * @author Stephane Nicoll */ -@Endpoint(id = "web", types = Endpoint.Type.WEB) +@Endpoint(id = "web", exposure = EndpointExposure.WEB) public class OnlyWebEndpoint { } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/incremental/IncrementalJmxEndpoint.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/incremental/IncrementalJmxEndpoint.java index e2f167bd60..61de43af37 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/incremental/IncrementalJmxEndpoint.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/incremental/IncrementalJmxEndpoint.java @@ -17,13 +17,14 @@ package org.springframework.boot.configurationsample.endpoint.incremental; import org.springframework.boot.configurationsample.Endpoint; +import org.springframework.boot.configurationsample.EndpointExposure; /** * An endpoint that only exposes a JMX MBean. * * @author Stephane Nicoll */ -@Endpoint(id = "incremental", types = Endpoint.Type.JMX) +@Endpoint(id = "incremental", exposure = EndpointExposure.JMX) public class IncrementalJmxEndpoint { } diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/build-info-custom-file/src/main/java/org/test/SampleApplication.java b/spring-boot-tools/spring-boot-maven-plugin/src/it/build-info-custom-file/src/main/java/org/test/SampleApplication.java index a270ba5751..8a5b669129 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/it/build-info-custom-file/src/main/java/org/test/SampleApplication.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/build-info-custom-file/src/main/java/org/test/SampleApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java b/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java index 060cf8bd0b..cbc4cb3231 100644 --- a/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java +++ b/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java @@ -395,8 +395,8 @@ public class SpringApplicationBuilder { Map<String, Object> map = new HashMap<>(); for (String property : properties) { int index = lowestIndexOf(property, ":", "="); - String key = index > 0 ? property.substring(0, index) : property; - String value = index > 0 ? property.substring(index + 1) : ""; + String key = (index > 0 ? property.substring(0, index) : property); + String value = (index > 0 ? property.substring(index + 1) : ""); map.put(key, value); } return map; diff --git a/spring-boot/src/main/java/org/springframework/boot/endpoint/EndpointPathResolver.java b/spring-boot/src/main/java/org/springframework/boot/endpoint/EndpointPathResolver.java index 581fad261c..4dec854936 100644 --- a/spring-boot/src/main/java/org/springframework/boot/endpoint/EndpointPathResolver.java +++ b/spring-boot/src/main/java/org/springframework/boot/endpoint/EndpointPathResolver.java @@ -17,8 +17,7 @@ package org.springframework.boot.endpoint; /** - * Strategy interface that can be used to resolve endpoint paths - * based on endpoint id. + * Strategy interface that can be used to resolve endpoint paths based on endpoint id. * * @author Madhura Bhave * @since 2.0.0 @@ -33,4 +32,3 @@ public interface EndpointPathResolver { String resolvePath(String endpointId); } - diff --git a/spring-boot/src/main/java/org/springframework/boot/web/context/ServerPortInfoApplicationContextInitializer.java b/spring-boot/src/main/java/org/springframework/boot/web/context/ServerPortInfoApplicationContextInitializer.java index 146bbbd1a4..017af4138b 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/context/ServerPortInfoApplicationContextInitializer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/context/ServerPortInfoApplicationContextInitializer.java @@ -49,7 +49,8 @@ import org.springframework.core.env.PropertySource; * @since 2.0.0 */ public class ServerPortInfoApplicationContextInitializer - implements ApplicationContextInitializer<ConfigurableApplicationContext>, ApplicationListener<WebServerInitializedEvent> { + implements ApplicationContextInitializer<ConfigurableApplicationContext>, + ApplicationListener<WebServerInitializedEvent> { @Override public void initialize(ConfigurableApplicationContext applicationContext) { diff --git a/spring-boot/src/main/java/org/springframework/boot/web/servlet/DispatcherType.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/DispatcherType.java index e01538bbd7..567dd7e759 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/servlet/DispatcherType.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/DispatcherType.java @@ -18,7 +18,7 @@ package org.springframework.boot.web.servlet; /** * Enumeration of filter dispatcher types, identical to - * {@link javax.servlet.DispatcherType} and used in configuration as the servlet api may + * {@link javax.servlet.DispatcherType} and used in configuration as the servlet API may * not be present. * * @author Stephane Nicoll diff --git a/spring-boot/src/test/java/org/springframework/boot/context/config/DelegatingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/config/DelegatingApplicationListenerTests.java index d91c7aa29d..49501b35f8 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/config/DelegatingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/config/DelegatingApplicationListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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/src/test/java/org/springframework/boot/diagnostics/analyzer/BindFailureAnalyzerTests.java b/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindFailureAnalyzerTests.java index 3060a60e87..f7ff7c782c 100644 --- a/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindFailureAnalyzerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindFailureAnalyzerTests.java @@ -102,8 +102,8 @@ public class BindFailureAnalyzerTests { Map<String, Object> map = new HashMap<>(); for (String pair : environment) { int index = pair.indexOf("="); - String key = index > 0 ? pair.substring(0, index) : pair; - String value = index > 0 ? pair.substring(index + 1) : ""; + String key = (index > 0 ? pair.substring(0, index) : pair); + String value = (index > 0 ? pair.substring(index + 1) : ""); map.put(key.trim(), value.trim()); } sources.addFirst(new MapPropertySource("test", map)); diff --git a/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindValidationFailureAnalyzerTests.java b/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindValidationFailureAnalyzerTests.java index e1cf168bec..6612138ca8 100644 --- a/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindValidationFailureAnalyzerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindValidationFailureAnalyzerTests.java @@ -135,8 +135,8 @@ public class BindValidationFailureAnalyzerTests { Map<String, Object> map = new HashMap<>(); for (String pair : environment) { int index = pair.indexOf("="); - String key = index > 0 ? pair.substring(0, index) : pair; - String value = index > 0 ? pair.substring(index + 1) : ""; + String key = (index > 0 ? pair.substring(0, index) : pair); + String value = (index > 0 ? pair.substring(index + 1) : ""); map.put(key.trim(), value.trim()); } sources.addFirst(new MapPropertySource("test", map)); diff --git a/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/UnboundConfigurationPropertyFailureAnalyzerTests.java b/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/UnboundConfigurationPropertyFailureAnalyzerTests.java index 8d4422353c..9987ccbc55 100644 --- a/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/UnboundConfigurationPropertyFailureAnalyzerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/UnboundConfigurationPropertyFailureAnalyzerTests.java @@ -98,8 +98,8 @@ public class UnboundConfigurationPropertyFailureAnalyzerTests { Map<String, Object> map = new HashMap<>(); for (String pair : environment) { int index = pair.indexOf("="); - String key = index > 0 ? pair.substring(0, index) : pair; - String value = index > 0 ? pair.substring(index + 1) : ""; + String key = (index > 0 ? pair.substring(0, index) : pair); + String value = (index > 0 ? pair.substring(index + 1) : ""); map.put(key.trim(), value.trim()); } sources.addFirst(new MapPropertySource("test", map)); diff --git a/spring-boot/src/test/java/org/springframework/boot/endpoint/AnnotationEndpointDiscovererTests.java b/spring-boot/src/test/java/org/springframework/boot/endpoint/AnnotationEndpointDiscovererTests.java index dfa04fadb7..2199dea9ee 100644 --- a/spring-boot/src/test/java/org/springframework/boot/endpoint/AnnotationEndpointDiscovererTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/endpoint/AnnotationEndpointDiscovererTests.java @@ -119,9 +119,8 @@ public class AnnotationEndpointDiscovererTests { Map<Method, TestEndpointOperation> operations = mapOperations( endpoints.get("test")); assertThat(operations).hasSize(4); - operations.values() - .forEach(operation -> assertThat(operation.getInvoker()) - .isNotInstanceOf(CachingOperationInvoker.class)); + operations.values().forEach(operation -> assertThat(operation.getInvoker()) + .isNotInstanceOf(CachingOperationInvoker.class)); }); } @@ -138,9 +137,8 @@ public class AnnotationEndpointDiscovererTests { Map<Method, TestEndpointOperation> operations = mapOperations( endpoints.get("test")); assertThat(operations).hasSize(4); - operations.values() - .forEach(operation -> assertThat(operation.getInvoker()) - .isNotInstanceOf(CachingOperationInvoker.class)); + operations.values().forEach(operation -> assertThat(operation.getInvoker()) + .isNotInstanceOf(CachingOperationInvoker.class)); }); } @@ -190,8 +188,8 @@ public class AnnotationEndpointDiscovererTests { EndpointInfo<TestEndpointOperation> endpoint) { Map<Method, TestEndpointOperation> operationByMethod = new HashMap<>(); endpoint.getOperations().forEach((operation) -> { - Operation existing = operationByMethod - .put(operation.getOperationMethod(), operation); + Operation existing = operationByMethod.put(operation.getOperationMethod(), + operation); if (existing != null) { throw new AssertionError(String.format( "Found endpoint with duplicate operation method '%s'", diff --git a/spring-boot/src/test/java/org/springframework/boot/endpoint/jmx/EndpointMBeanTests.java b/spring-boot/src/test/java/org/springframework/boot/endpoint/jmx/EndpointMBeanTests.java index 842b8fda41..c19144e3d9 100644 --- a/spring-boot/src/test/java/org/springframework/boot/endpoint/jmx/EndpointMBeanTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/endpoint/jmx/EndpointMBeanTests.java @@ -113,7 +113,7 @@ public class EndpointMBeanTests { // deleteOne Object deleteResponse = this.server.invoke(objectName, "deleteOne", new Object[] { "one" }, new String[] { String.class.getName() }); - assertThat(oneResponse).isEqualTo("ONE"); + assertThat(deleteResponse).isNull(); // getOne validation after delete updatedOneResponse = this.server.invoke(objectName, "getOne", diff --git a/spring-boot/src/test/java/org/springframework/boot/endpoint/web/AbstractWebEndpointIntegrationTests.java b/spring-boot/src/test/java/org/springframework/boot/endpoint/web/AbstractWebEndpointIntegrationTests.java index d89e70b413..1cc910be16 100644 --- a/spring-boot/src/test/java/org/springframework/boot/endpoint/web/AbstractWebEndpointIntegrationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/endpoint/web/AbstractWebEndpointIntegrationTests.java @@ -171,8 +171,8 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable @Test public void deleteOperationWithVoidResponse() { load(VoidDeleteResponseEndpointConfiguration.class, (context, client) -> { - client.delete().uri("/voiddelete").accept(MediaType.APPLICATION_JSON).exchange() - .expectStatus().isNoContent().expectBody().isEmpty(); + client.delete().uri("/voiddelete").accept(MediaType.APPLICATION_JSON) + .exchange().expectStatus().isNoContent().expectBody().isEmpty(); verify(context.getBean(EndpointDelegate.class)).delete(); }); } @@ -346,7 +346,6 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable } - @Configuration @Import(BaseConfiguration.class) static class NullWriteResponseEndpointConfiguration {