SEC-271: removed autowiring by type and explicity introspected the applicationContext to detect the required dependencies of userDetailsService

This commit is contained in:
Vishal Puri 2007-05-18 03:21:21 +00:00
parent e3435da9ae
commit 3f7e00c796
2 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,37 @@
/**
*
*/
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 {
System.out.println("whyyyy??????");
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

@ -0,0 +1,35 @@
/**
*
*/
package org.acegisecurity.config;
import org.acegisecurity.ui.rememberme.RememberMeServices;
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 RemeberMeServicesDependenciesConfigurer implements BeanFactoryPostProcessor {
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
String [] userDetailServices = beanFactory.getBeanNamesForType(UserDetailsService.class);
String [] rememberMeService = beanFactory.getBeanNamesForType(RememberMeServices.class);
RootBeanDefinition definition=(RootBeanDefinition) beanFactory.getBeanDefinition(rememberMeService[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]));
}
}
}