SEC-271: Removed AuthenticationRepositoryDependenciesConfigurer as the introspection of applicationcontext for collaborators is implemented in the bean itself

This commit is contained in:
Vishal Puri 2007-06-14 06:27:32 +00:00
parent 2987b62893
commit 23024b20ad
5 changed files with 59 additions and 59 deletions

View File

@ -21,23 +21,22 @@ public class AuthenticationProcessingFilterDependenciesConfigurer implements Bea
// ================================================================================================
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
String [] authenticationProcessingFilter = beanFactory.getBeanNamesForType(AuthenticationProcessingFilter.class);
RootBeanDefinition def = (RootBeanDefinition)beanFactory.getBeanDefinition(authenticationProcessingFilter[0]);
String[] remServiceNames = beanFactory.getBeanNamesForType(RememberMeServices.class);
RootBeanDefinition rememberMeServices = (RootBeanDefinition) beanFactory.getBeanDefinition(remServiceNames[0]);
String[] authenticationProcessingFilter = beanFactory.getBeanNamesForType(AuthenticationProcessingFilter.class);
if (remServiceNames.length > 0)
def.getPropertyValues()
.addPropertyValue("rememberMeServices", rememberMeServices);
RootBeanDefinition def = (RootBeanDefinition) beanFactory.getBeanDefinition(authenticationProcessingFilter[0]);
String[] remServiceNames = beanFactory.getBeanNamesForType(RememberMeServices.class);
if (remServiceNames.length > 0) {
def.getPropertyValues().addPropertyValue("rememberMeServices",
(RootBeanDefinition) beanFactory.getBeanDefinition(remServiceNames[0]));
}
String[] authManager = beanFactory.getBeanNamesForType(AuthenticationManager.class);
RootBeanDefinition authenticationManager = (RootBeanDefinition) beanFactory.getBeanDefinition(authManager[0]);
RootBeanDefinition authenticationMechanism = (RootBeanDefinition) beanFactory.getBeanDefinition(authManager[0]);
if (authManager.length > 0)
def.getPropertyValues().addPropertyValue("authenticationManager", authenticationManager);
def.getPropertyValues().addPropertyValue("authenticationManager", authenticationMechanism);
}
}

View File

@ -1,36 +0,0 @@
/**
*
*/
package org.acegisecurity.config;
import org.acegisecurity.providers.dao.DaoAuthenticationProvider;
import org.acegisecurity.userdetails.UserDetailsService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.RootBeanDefinition;
/**
* @author vpuri
*
*/
public class AuthenticationRepositoryDependenciesConfigurer implements BeanFactoryPostProcessor {
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
String[] userDetailServices = beanFactory.getBeanNamesForType(UserDetailsService.class);
String[] authenticationProvider = beanFactory.getBeanNamesForType(DaoAuthenticationProvider.class);
RootBeanDefinition definition = (RootBeanDefinition) beanFactory.getBeanDefinition(authenticationProvider[0]);
// there should be only one principal-repository defined, pick the first
// one
if (userDetailServices.length != 0) {
definition.getPropertyValues().addPropertyValue("userDetailsService",
new RuntimeBeanReference(userDetailServices[0]));
}
}
}

View File

@ -3,14 +3,17 @@
*/
package org.acegisecurity.config;
import javax.servlet.Filter;
import java.lang.reflect.Field;
import junit.framework.TestCase;
import org.acegisecurity.context.HttpSessionContextIntegrationFilter;
import org.acegisecurity.ui.logout.LogoutFilter;
import org.acegisecurity.ui.logout.LogoutHandler;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.ReflectionUtils;
/**
* @author Vishal Puri
@ -18,18 +21,51 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
*/
public class AutoConfigBeanDefinitionParserTests extends TestCase {
private ApplicationContext context;
ConfigurableListableBeanFactory bf;
// ~ Methods
// ========================================================================================================
public void setUp() {
this.context = new ClassPathXmlApplicationContext("org/acegisecurity/config/auto-config.xml");
this.bf = (ConfigurableListableBeanFactory) context.getAutowireCapableBeanFactory();
}
public void testContextBeanDefinitionCreated() {
ApplicationContext context = new ClassPathXmlApplicationContext("org/acegisecurity/config/auto-config.xml");
ConfigurableListableBeanFactory bf = (ConfigurableListableBeanFactory) context.getAutowireCapableBeanFactory();
String[] names = bf.getBeanNamesForType(HttpSessionContextIntegrationFilter.class);
assertEquals(1, names.length);
HttpSessionContextIntegrationFilter filter = (HttpSessionContextIntegrationFilter) bf.getBean(names[0]);
// check properties
//get the bean
// check properties
// get the bean
assertTrue(filter.isAllowSessionCreation());
assertFalse(filter.isForceEagerSessionCreation());
assertFalse(filter.isCloneFromHttpSession());
}
public void testLogoutFilterDefinitionCreatedWithDefaults() throws Exception{
String[] names = bf.getBeanNamesForType(LogoutFilter.class);
assertEquals(1, names.length);
LogoutFilter filter = (LogoutFilter) context.getBean(names[0]);
assertNotNull(filter);
Field logoutSuccessUrl = makeAccessibleAndGetFieldByName(filter.getClass().getDeclaredFields(), "logoutSuccessUrl");
String value = (String) logoutSuccessUrl.get(filter);
assertEquals("/", value);
Field handlers = makeAccessibleAndGetFieldByName(filter.getClass().getDeclaredFields(), "handlers");
assertNotNull(handlers);
LogoutHandler[] handlersArray = (LogoutHandler[])handlers.get(filter);
assertEquals(2, handlersArray.length);
}
private Field makeAccessibleAndGetFieldByName(Field[] declaredFields, String name) {
Field field = null;
for (int i = 0, n = declaredFields.length; i < n; i++) {
ReflectionUtils.makeAccessible(declaredFields[i]);
if (declaredFields[i].getName().equals(name)) {
return declaredFields[i];
}
}
return field;
}
}

View File

@ -22,12 +22,12 @@ import org.springframework.util.ReflectionUtils;
public class ExceptionTranslationParserTests extends TestCase {
public void OFFtestParsingBeanReferences() {
public void testParsingBeanReferences() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"org/acegisecurity/config/exception-translation-beanref.xml");
ConfigurableListableBeanFactory factory = (ConfigurableListableBeanFactory) context
.getAutowireCapableBeanFactory();
String[] beanNames = factory.getBeanNamesForType(Filter.class);
String[] beanNames = factory.getBeanNamesForType(ExceptionTranslationFilter.class);
assertEquals(1, beanNames.length);
RootBeanDefinition def = (RootBeanDefinition) factory.getBeanDefinition(beanNames[0]);
assertEquals(ExceptionTranslationFilter.class.getName(), def.getBeanClassName());
@ -40,7 +40,7 @@ public class ExceptionTranslationParserTests extends TestCase {
assertEquals(entryPoint.getValue(), new RuntimeBeanReference("authenticationProcessingFilterEntryPoint"));
}
public void OFFtestRuntimeBeanDependencies() {
public void testRuntimeBeanDependencies() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"org/acegisecurity/config/exception-translation-beanref.xml");
ExceptionTranslationFilter filter = (ExceptionTranslationFilter) context.getBean("exceptionTranslationFilter");

View File

@ -18,6 +18,7 @@ http://www.springframework.org/schema/security http://www.springframework.org/sc
<security:exception-translation id="exceptionTranslationFilter">
<security:entry-point
entryPointBeanRef="authenticationProcessingFilterEntryPoint" />
<security:access-denied accessDeniedBeanRef="theBeanToUse" />
</security:exception-translation>
<bean id="theBeanToUse"