diff --git a/config/src/test/groovy/org/springframework/security/config/debug/SecurityDebugBeanFactoryPostProcessorTest.groovy b/config/src/test/groovy/org/springframework/security/config/debug/SecurityDebugBeanFactoryPostProcessorTest.groovy deleted file mode 100644 index 60c7779b86..0000000000 --- a/config/src/test/groovy/org/springframework/security/config/debug/SecurityDebugBeanFactoryPostProcessorTest.groovy +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2002-2011 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.security.config.debug - -import org.springframework.security.config.BeanIds -import org.springframework.security.config.http.AbstractHttpConfigTests -import org.springframework.security.web.FilterChainProxy; -import org.springframework.security.web.debug.DebugFilter; - -class SecurityDebugBeanFactoryPostProcessorTest extends AbstractHttpConfigTests { - - // SEC-1885 - def 'SEC-1885 - SecurityDebugBeanFactoryPostProcessor works when dependencies have Autowired constructor'() { - when: 'debug used and FilterChainProxy has dependency with @Autowired constructor' - xml.debug() - httpAutoConfig {} - xml.'authentication-manager'() { - 'authentication-provider'('ref': 'authProvider') - } - xml.'context:component-scan'('base-package':'org.springframework.security.config.debug') - createAppContext('') - then: 'TestAuthenticationProvider.() is not thrown' - appContext.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN) instanceof DebugFilter - appContext.getBean(BeanIds.FILTER_CHAIN_PROXY) instanceof FilterChainProxy - } -} diff --git a/config/src/test/groovy/org/springframework/security/config/debug/AuthProviderDependency.groovy b/config/src/test/java/org/springframework/security/config/debug/AuthProviderDependency.java similarity index 76% rename from config/src/test/groovy/org/springframework/security/config/debug/AuthProviderDependency.groovy rename to config/src/test/java/org/springframework/security/config/debug/AuthProviderDependency.java index 25acb45216..36b9681003 100644 --- a/config/src/test/groovy/org/springframework/security/config/debug/AuthProviderDependency.groovy +++ b/config/src/test/java/org/springframework/security/config/debug/AuthProviderDependency.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.security.config.debug +package org.springframework.security.config.debug; -import org.springframework.stereotype.Component +import org.springframework.stereotype.Component; /** * Fake depenency for {@link TestAuthenticationProvider} diff --git a/config/src/test/java/org/springframework/security/config/debug/SecurityDebugBeanFactoryPostProcessorTests.java b/config/src/test/java/org/springframework/security/config/debug/SecurityDebugBeanFactoryPostProcessorTests.java new file mode 100644 index 0000000000..1300665da4 --- /dev/null +++ b/config/src/test/java/org/springframework/security/config/debug/SecurityDebugBeanFactoryPostProcessorTests.java @@ -0,0 +1,46 @@ +/* + * Copyright 2002-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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.security.config.debug; + +import org.junit.Rule; +import org.junit.Test; +import org.springframework.security.config.test.SpringTestRule; +import org.springframework.security.web.FilterChainProxy; +import org.springframework.security.web.debug.DebugFilter; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.security.config.BeanIds.FILTER_CHAIN_PROXY; +import static org.springframework.security.config.BeanIds.SPRING_SECURITY_FILTER_CHAIN; + +/** + * @author Rob Winch + * @author Josh Cummings + */ +public class SecurityDebugBeanFactoryPostProcessorTests { + + @Rule + public final SpringTestRule spring = new SpringTestRule(); + + @Test + public void contextRefreshWhenInDebugModeAndDependencyHasAutowiredConstructorThenDebugModeStillWorks() { + // SEC-1885 + this.spring.configLocations("classpath:org/springframework/security/config/debug/SecurityDebugBeanFactoryPostProcessorTests-context.xml") + .autowire(); + + assertThat(this.spring.getContext().getBean(SPRING_SECURITY_FILTER_CHAIN)).isInstanceOf(DebugFilter.class); + assertThat(this.spring.getContext().getBean(FILTER_CHAIN_PROXY)).isInstanceOf(FilterChainProxy.class); + } +} diff --git a/config/src/test/groovy/org/springframework/security/config/debug/TestAuthenticationProvider.groovy b/config/src/test/java/org/springframework/security/config/debug/TestAuthenticationProvider.java similarity index 81% rename from config/src/test/groovy/org/springframework/security/config/debug/TestAuthenticationProvider.groovy rename to config/src/test/java/org/springframework/security/config/debug/TestAuthenticationProvider.java index 8f310c9e6e..0eb0ef04f9 100644 --- a/config/src/test/groovy/org/springframework/security/config/debug/TestAuthenticationProvider.groovy +++ b/config/src/test/java/org/springframework/security/config/debug/TestAuthenticationProvider.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -15,11 +15,12 @@ */ package org.springframework.security.config.debug; -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.security.authentication.AuthenticationProvider -import org.springframework.security.core.Authentication -import org.springframework.security.core.AuthenticationException -import org.springframework.stereotype.Service + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.stereotype.Service; /** * An {@link AuthenticationProvider} that has an {@link Autowired} constructor which is necessary to recreate SEC-1885. diff --git a/config/src/test/resources/org/springframework/security/config/debug/SecurityDebugBeanFactoryPostProcessorTests-context.xml b/config/src/test/resources/org/springframework/security/config/debug/SecurityDebugBeanFactoryPostProcessorTests-context.xml new file mode 100644 index 0000000000..904b447437 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/debug/SecurityDebugBeanFactoryPostProcessorTests-context.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + +