diff --git a/config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy b/config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy index 94140e4cab..fb9c6778c6 100644 --- a/config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy @@ -45,6 +45,8 @@ import org.springframework.security.web.servletapi.SecurityContextHolderAwareReq import org.springframework.security.web.session.SessionManagementFilter import org.springframework.security.web.authentication.logout.CookieClearingLogoutHandler import org.springframework.security.web.firewall.DefaultHttpFirewall +import org.springframework.security.BeanNameCollectingPostProcessor +import org.springframework.security.authentication.dao.DaoAuthenticationProvider class MiscHttpConfigTests extends AbstractHttpConfigTests { def 'Minimal configuration parses'() { @@ -409,16 +411,26 @@ class MiscHttpConfigTests extends AbstractHttpConfigTests { * and also has a post processor registered which will modify it. */ def httpElementDoesntInterfereWithBeanPostProcessing() { - httpAutoConfig {} + xml.http('auto-config': 'true', 'entry-point-ref': 'entryPoint') {} xml.'authentication-manager'() { 'authentication-provider'('user-service-ref': 'myUserService') + 'authentication-provider'('ref': 'authProvider') } + bean('authProvider', DaoAuthenticationProvider.class.name, [:], [userDetailsService: 'myUserService']) + bean('entryPoint', MockEntryPoint.class.name) bean('myUserService', PostProcessedMockUserDetailsService) - bean('beanPostProcessor', MockUserServiceBeanPostProcessor) + bean('userServicePostProcessor', MockUserServiceBeanPostProcessor) + bean('nameCollectingPostProcessor', BeanNameCollectingPostProcessor) createAppContext("") + def beanPP = appContext.getBean("nameCollectingPostProcessor") + Set preInitPPBeans = beanPP.beforeInitPostProcessedBeans + Set postInitPPBeans = beanPP.afterInitPostProcessedBeans + Set expectedBeans = ['authProvider', 'entryPoint', 'myUserService'] as Set expect: appContext.getBean("myUserService").getPostProcessorWasHere() == "Hello from the post processor!" + preInitPPBeans.containsAll(expectedBeans) + postInitPPBeans.containsAll(expectedBeans) } /* SEC-934 */ diff --git a/config/src/test/java/org/springframework/security/BeanNameCollectingPostProcessor.java b/config/src/test/java/org/springframework/security/BeanNameCollectingPostProcessor.java new file mode 100644 index 0000000000..95d2a95312 --- /dev/null +++ b/config/src/test/java/org/springframework/security/BeanNameCollectingPostProcessor.java @@ -0,0 +1,28 @@ +package org.springframework.security; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; + +import java.util.*; + +/** + * @author Luke Taylor + */ +public class BeanNameCollectingPostProcessor implements BeanPostProcessor { + Set beforeInitPostProcessedBeans = new HashSet(); + Set afterInitPostProcessedBeans = new HashSet(); + + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + if (beanName != null) { + beforeInitPostProcessedBeans.add(beanName); + } + return bean; + } + + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + if (beanName != null) { + afterInitPostProcessedBeans.add(beanName); + } + return bean; + } +}