From d1005e4cfbad2f0a8c6c506e3e166439ae88c059 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Fri, 23 May 2008 23:25:09 +0000 Subject: [PATCH] SEC-850: custom-authentication-provider Registering Separate Bean Definitions in App Context and Providers List http://jira.springframework.org/browse/SEC-850. Changed bean decorator to add a bean reference to the ProviderManager rather than a bean definition. --- ...cationProviderBeanDefinitionDecorator.java | 3 ++- ...nProviderBeanDefinitionDecoratorTests.java | 25 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/springframework/security/config/CustomAuthenticationProviderBeanDefinitionDecorator.java b/core/src/main/java/org/springframework/security/config/CustomAuthenticationProviderBeanDefinitionDecorator.java index dc5a5e72dc..a95dc47272 100644 --- a/core/src/main/java/org/springframework/security/config/CustomAuthenticationProviderBeanDefinitionDecorator.java +++ b/core/src/main/java/org/springframework/security/config/CustomAuthenticationProviderBeanDefinitionDecorator.java @@ -3,6 +3,7 @@ package org.springframework.security.config; import org.springframework.beans.factory.xml.BeanDefinitionDecorator; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.beans.factory.config.BeanDefinitionHolder; +import org.springframework.beans.factory.config.RuntimeBeanReference; import org.w3c.dom.Node; @@ -16,7 +17,7 @@ import org.w3c.dom.Node; */ public class CustomAuthenticationProviderBeanDefinitionDecorator implements BeanDefinitionDecorator { public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder holder, ParserContext parserContext) { - ConfigUtils.getRegisteredProviders(parserContext).add(holder.getBeanDefinition()); + ConfigUtils.getRegisteredProviders(parserContext).add(new RuntimeBeanReference(holder.getBeanName())); return holder; } diff --git a/core/src/test/java/org/springframework/security/config/CustomAuthenticationProviderBeanDefinitionDecoratorTests.java b/core/src/test/java/org/springframework/security/config/CustomAuthenticationProviderBeanDefinitionDecoratorTests.java index 93e4b40930..77175ce5d1 100644 --- a/core/src/test/java/org/springframework/security/config/CustomAuthenticationProviderBeanDefinitionDecoratorTests.java +++ b/core/src/test/java/org/springframework/security/config/CustomAuthenticationProviderBeanDefinitionDecoratorTests.java @@ -1,21 +1,32 @@ package org.springframework.security.config; +import static org.junit.Assert.*; + import org.junit.Test; +import org.springframework.security.providers.ProviderManager; import org.springframework.security.util.InMemoryXmlApplicationContext; public class CustomAuthenticationProviderBeanDefinitionDecoratorTests { @Test - public void decoratorParsesSuccessfully() { + public void decoratedProviderParsesSuccessfully() { InMemoryXmlApplicationContext ctx = new InMemoryXmlApplicationContext( - "" + - " " + - " " + - " " + - "" + HttpSecurityBeanDefinitionParserTests.AUTH_PROVIDER_XML + "" + + " " + + " " + + "" + + "" + + " " + + " " + + "" + ); - ctx.getBean("someBean"); + Object myProvider = ctx.getBean("myProvider"); + + ProviderManager authMgr = (ProviderManager) ctx.getBean(BeanIds.AUTHENTICATION_MANAGER); + + assertSame(myProvider, authMgr.getProviders().get(0)); } }