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.
This commit is contained in:
Luke Taylor 2008-05-23 23:25:09 +00:00
parent 9ce0270226
commit d1005e4cfb
2 changed files with 20 additions and 8 deletions

View File

@ -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;
}

View File

@ -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(
"<b:bean id='someBean' class='org.springframework.security.config.TestBusinessBeanImpl'>" +
" <intercept-methods>" +
" <protect method='org.springframework.security.config.TestBusinessBean.*' access='ROLE_A' />" +
" </intercept-methods>" +
"</b:bean>" + HttpSecurityBeanDefinitionParserTests.AUTH_PROVIDER_XML
"<b:bean id='myProvider' class='org.springframework.security.providers.dao.DaoAuthenticationProvider'>" +
" <custom-authentication-provider />" +
" <b:property name='userDetailsService' ref='us'/>" +
"</b:bean>" +
"<user-service id='us'>" +
" <user name='bob' password='bobspassword' authorities='ROLE_A,ROLE_B' />" +
" <user name='bill' password='billspassword' authorities='ROLE_A,ROLE_B,AUTH_OTHER' />" +
"</user-service>"
);
ctx.getBean("someBean");
Object myProvider = ctx.getBean("myProvider");
ProviderManager authMgr = (ProviderManager) ctx.getBean(BeanIds.AUTHENTICATION_MANAGER);
assertSame(myProvider, authMgr.getProviders().get(0));
}
}