From 70d92037bda8be428ea7170485e300767f19f9ba Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Mon, 27 Nov 2017 16:46:38 +0900 Subject: [PATCH 1/2] Use BeanIds.SPRING_SECURITY_FILTER_CHAIN See gh-11162 --- .../servlet/ServletManagementChildContextConfiguration.java | 5 +++-- .../servlet/CloudFoundryActuatorAutoConfigurationTests.java | 3 ++- .../security/WebSecurityEnablerConfiguration.java | 5 +++-- .../oauth2/client/OAuth2WebSecurityConfigurationTests.java | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java index 36217442353..ddf32267f2e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java @@ -42,6 +42,7 @@ import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerF import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; +import org.springframework.security.config.BeanIds; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; /** @@ -78,13 +79,13 @@ class ServletManagementChildContextConfiguration { @Configuration @ConditionalOnClass({ EnableWebSecurity.class, Filter.class }) - @ConditionalOnBean(name = "springSecurityFilterChain", search = SearchStrategy.ANCESTORS) + @ConditionalOnBean(name = BeanIds.SPRING_SECURITY_FILTER_CHAIN, search = SearchStrategy.ANCESTORS) class ServletManagementContextSecurityConfiguration { @Bean public Filter springSecurityFilterChain(HierarchicalBeanFactory beanFactory) { BeanFactory parent = beanFactory.getParentBeanFactory(); - return parent.getBean("springSecurityFilterChain", Filter.class); + return parent.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN, Filter.class); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfigurationTests.java index 1dd27bb16da..c91c7e586b9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfigurationTests.java @@ -47,6 +47,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockServletContext; +import org.springframework.security.config.BeanIds; import org.springframework.security.web.FilterChainProxy; import org.springframework.security.web.SecurityFilterChain; import org.springframework.test.util.ReflectionTestUtils; @@ -181,7 +182,7 @@ public class CloudFoundryActuatorAutoConfigurationTests { .applyTo(this.context); this.context.refresh(); FilterChainProxy securityFilterChain = (FilterChainProxy) this.context - .getBean("springSecurityFilterChain"); + .getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN); SecurityFilterChain chain = securityFilterChain.getFilterChains().get(0); MockHttpServletRequest request = new MockHttpServletRequest(); request.setServletPath("/cloudfoundryapplication/my-path"); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/WebSecurityEnablerConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/WebSecurityEnablerConfiguration.java index ab713d20e25..b4376fa9b3c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/WebSecurityEnablerConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/WebSecurityEnablerConfiguration.java @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.security; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.security.config.BeanIds; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @@ -27,14 +28,14 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur * {@link EnableWebSecurity} annotation. This will make sure that the annotation is * present with default security auto-configuration and also if the user adds custom * security and forgets to add the annotation. If {@link EnableWebSecurity} has already - * been added or if a bean with name springSecurityFilterChain has been configured by the + * been added or if a bean with name {@value BeanIds#SPRING_SECURITY_FILTER_CHAIN} has been configured by the * user, this will back-off. * * @author Madhura Bhave * @since 2.0.0 */ @ConditionalOnBean(WebSecurityConfigurerAdapter.class) -@ConditionalOnMissingBean(name = "springSecurityFilterChain") +@ConditionalOnMissingBean(name = BeanIds.SPRING_SECURITY_FILTER_CHAIN) @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) @EnableWebSecurity public class WebSecurityEnablerConfiguration { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfigurationTests.java index 5c61e96f608..40404b67e50 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfigurationTests.java @@ -30,6 +30,7 @@ import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactor import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.security.config.BeanIds; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.oauth2.client.InMemoryOAuth2AuthorizedClientService; @@ -123,7 +124,7 @@ public class OAuth2WebSecurityConfigurationTests { @SuppressWarnings("unchecked") private List getAuthCodeFilters(AssertableApplicationContext context) { FilterChainProxy filterChain = (FilterChainProxy) context - .getBean("springSecurityFilterChain"); + .getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN); List filterChains = filterChain.getFilterChains(); List filters = (List) ReflectionTestUtils .getField(filterChains.get(0), "filters"); From 9543327406d20d45edbb13549b1ca8264f70cc35 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 27 Nov 2017 10:32:28 +0100 Subject: [PATCH 2/2] Polish "Use BeanIds.SPRING_SECURITY_FILTER_CHAIN" Closes gh-11162 --- .../security/WebSecurityEnablerConfiguration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/WebSecurityEnablerConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/WebSecurityEnablerConfiguration.java index b4376fa9b3c..a60704e99a1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/WebSecurityEnablerConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/WebSecurityEnablerConfiguration.java @@ -28,8 +28,8 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur * {@link EnableWebSecurity} annotation. This will make sure that the annotation is * present with default security auto-configuration and also if the user adds custom * security and forgets to add the annotation. If {@link EnableWebSecurity} has already - * been added or if a bean with name {@value BeanIds#SPRING_SECURITY_FILTER_CHAIN} has been configured by the - * user, this will back-off. + * been added or if a bean with name {@value BeanIds#SPRING_SECURITY_FILTER_CHAIN} has + * been configured by the user, this will back-off. * * @author Madhura Bhave * @since 2.0.0