SEC-271: removed autowiring by type and explicity introspected the applicationContext to detect the required dependencies of userDetailsService
This commit is contained in:
@@ -22,94 +22,99 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author vpuri
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class AuthenticationRepositoryParserTest extends TestCase {
|
||||
|
||||
|
||||
public void testAuthenticationRepositoryDefaultWithAutoUserdetails() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("org/acegisecurity/config/authentication-dao-defaults.xml");
|
||||
ConfigurableListableBeanFactory clbf =
|
||||
(ConfigurableListableBeanFactory)context.getAutowireCapableBeanFactory();
|
||||
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"org/acegisecurity/config/authentication-dao-defaults.xml");
|
||||
ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory) context
|
||||
.getAutowireCapableBeanFactory();
|
||||
|
||||
String[] names = clbf.getBeanNamesForType(AuthenticationProvider.class);
|
||||
assertEquals(1, names.length);
|
||||
|
||||
|
||||
// check bean class
|
||||
RootBeanDefinition definition = (RootBeanDefinition)clbf.getBeanDefinition(names[0]);
|
||||
assertEquals(DaoAuthenticationProvider.class, definition.getBeanClass());
|
||||
|
||||
DaoAuthenticationProvider provider = (DaoAuthenticationProvider)context.getBean("authenticationRepository");
|
||||
RootBeanDefinition definition = (RootBeanDefinition) clbf.getBeanDefinition(names[0]);
|
||||
assertEquals(DaoAuthenticationProvider.class, definition.getBeanClass());
|
||||
|
||||
DaoAuthenticationProvider provider = (DaoAuthenticationProvider) context.getBean("authenticationRepository");
|
||||
Assert.isAssignable(JdbcDaoImpl.class, provider.getUserDetailsService().getClass());
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void testCollaboratorsAsInnerBeans(){
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("org/acegisecurity/config/authentication-innerbeans.xml");
|
||||
ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory)context.getAutowireCapableBeanFactory();
|
||||
|
||||
public void testCollaboratorsAsInnerBeans() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"org/acegisecurity/config/authentication-innerbeans.xml");
|
||||
ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory) context
|
||||
.getAutowireCapableBeanFactory();
|
||||
// get the main bean definition, there should be only one
|
||||
String[] names = clbf.getBeanNamesForType(AuthenticationProvider.class);
|
||||
assertEquals(1, names.length);
|
||||
RootBeanDefinition definition = (RootBeanDefinition)clbf.getBeanDefinition(names[0]);
|
||||
assertEquals(DaoAuthenticationProvider.class, definition.getBeanClass());
|
||||
|
||||
|
||||
// get the 2 inner beans
|
||||
PropertyValue saltSourceBean = definition.getPropertyValues().getPropertyValue("saltSource");
|
||||
assertEquals("saltSource", saltSourceBean.getName());
|
||||
|
||||
//get the BeanDefinition
|
||||
RootBeanDefinition saltsourceDef = (RootBeanDefinition) saltSourceBean.getValue();
|
||||
Assert.isAssignable(SaltSource.class,saltsourceDef.getBeanClass());
|
||||
|
||||
PropertyValue encoder = definition.getPropertyValues().getPropertyValue("passwordEncoder");
|
||||
assertEquals("passwordEncoder", encoder.getName());
|
||||
|
||||
//get the BeanDefinition
|
||||
RootBeanDefinition encoderDef = (RootBeanDefinition) encoder.getValue();
|
||||
Assert.isAssignable(PasswordEncoder.class,encoderDef.getBeanClass());
|
||||
|
||||
assertEquals("incorrect bean class name", encoderDef.getBeanClassName(),Md5PasswordEncoder.class.getName());
|
||||
RootBeanDefinition definition = (RootBeanDefinition) clbf.getBeanDefinition(names[0]);
|
||||
assertEquals(DaoAuthenticationProvider.class, definition.getBeanClass());
|
||||
|
||||
// get the 2 inner beans
|
||||
PropertyValue saltSourceBean = definition.getPropertyValues().getPropertyValue("saltSource");
|
||||
assertEquals("saltSource", saltSourceBean.getName());
|
||||
|
||||
// get the BeanDefinition
|
||||
RootBeanDefinition saltsourceDef = (RootBeanDefinition) saltSourceBean.getValue();
|
||||
Assert.isAssignable(SaltSource.class, saltsourceDef.getBeanClass());
|
||||
|
||||
PropertyValue encoder = definition.getPropertyValues().getPropertyValue("passwordEncoder");
|
||||
assertEquals("passwordEncoder", encoder.getName());
|
||||
|
||||
// get the BeanDefinition
|
||||
RootBeanDefinition encoderDef = (RootBeanDefinition) encoder.getValue();
|
||||
Assert.isAssignable(PasswordEncoder.class, encoderDef.getBeanClass());
|
||||
|
||||
assertEquals("incorrect bean class name", encoderDef.getBeanClassName(), Md5PasswordEncoder.class.getName());
|
||||
}
|
||||
|
||||
|
||||
public void testCollaboratorsAsBeanRef() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("org/acegisecurity/config/authentication-beanRef-attributes.xml");
|
||||
ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory)context.getAutowireCapableBeanFactory();
|
||||
// get the main bean definition, there should be only one
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"org/acegisecurity/config/authentication-beanRef-attributes.xml");
|
||||
ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory) context
|
||||
.getAutowireCapableBeanFactory();
|
||||
// get the main bean definition, there should be only one
|
||||
String[] names = clbf.getBeanNamesForType(AuthenticationProvider.class);
|
||||
assertEquals(1, names.length);
|
||||
RootBeanDefinition definition = (RootBeanDefinition)clbf.getBeanDefinition(names[0]);
|
||||
assertEquals(DaoAuthenticationProvider.class, definition.getBeanClass());
|
||||
|
||||
// get the referred collaborators
|
||||
|
||||
PropertyValue userDetailsBean = definition.getPropertyValues().getPropertyValue("userDetailsService");
|
||||
assertEquals("userDetailsService", userDetailsBean.getName());
|
||||
|
||||
PropertyValue saltSourceBean = definition.getPropertyValues().getPropertyValue("saltSource");
|
||||
assertEquals("saltSource", saltSourceBean.getName());
|
||||
|
||||
//get the BeanDefinition
|
||||
RuntimeBeanReference saltsourceDef = (RuntimeBeanReference) saltSourceBean.getValue();
|
||||
assertEquals("refToSaltSource",saltsourceDef.getBeanName());
|
||||
|
||||
PropertyValue encoder = definition.getPropertyValues().getPropertyValue("passwordEncoder");
|
||||
assertEquals("passwordEncoder", encoder.getName());
|
||||
|
||||
//get the BeanDefinition
|
||||
RuntimeBeanReference encoderDef = (RuntimeBeanReference) encoder.getValue();
|
||||
assertEquals("refToPasswordEncoder",encoderDef.getBeanName());
|
||||
|
||||
DaoAuthenticationProvider provider = (DaoAuthenticationProvider)context.getBean("authenticationRepository");
|
||||
assertTrue(provider.getPasswordEncoder() instanceof PasswordEncoder);
|
||||
assertEquals(Md5PasswordEncoder.class, provider.getPasswordEncoder().getClass() );
|
||||
RootBeanDefinition definition = (RootBeanDefinition) clbf.getBeanDefinition(names[0]);
|
||||
assertEquals(DaoAuthenticationProvider.class, definition.getBeanClass());
|
||||
|
||||
// get the referred collaborators
|
||||
|
||||
PropertyValue userDetailsBean = definition.getPropertyValues().getPropertyValue("userDetailsService");
|
||||
assertEquals("userDetailsService", userDetailsBean.getName());
|
||||
|
||||
PropertyValue saltSourceBean = definition.getPropertyValues().getPropertyValue("saltSource");
|
||||
assertEquals("saltSource", saltSourceBean.getName());
|
||||
|
||||
// get the BeanDefinition
|
||||
RuntimeBeanReference saltsourceDef = (RuntimeBeanReference) saltSourceBean.getValue();
|
||||
assertEquals("refToSaltSource", saltsourceDef.getBeanName());
|
||||
|
||||
PropertyValue encoder = definition.getPropertyValues().getPropertyValue("passwordEncoder");
|
||||
assertEquals("passwordEncoder", encoder.getName());
|
||||
|
||||
// get the BeanDefinition
|
||||
RuntimeBeanReference encoderDef = (RuntimeBeanReference) encoder.getValue();
|
||||
assertEquals("refToPasswordEncoder", encoderDef.getBeanName());
|
||||
|
||||
DaoAuthenticationProvider provider = (DaoAuthenticationProvider) context.getBean("authenticationRepository");
|
||||
assertTrue(provider.getPasswordEncoder() instanceof PasswordEncoder);
|
||||
assertEquals(Md5PasswordEncoder.class, provider.getPasswordEncoder().getClass());
|
||||
}
|
||||
|
||||
public void testAutodetectionOfUserDetailsService(){
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("org/acegisecurity/config/authentication-defaults.xml");
|
||||
DaoAuthenticationProvider provider = (DaoAuthenticationProvider)context.getBean("authenticationRepository");
|
||||
assertNotNull(provider.getUserDetailsService());
|
||||
assertNull(provider.getSaltSource());
|
||||
assertEquals(PlaintextPasswordEncoder.class, provider.getPasswordEncoder().getClass());
|
||||
|
||||
|
||||
public void testAutodetectionOfUserDetailsService() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"org/acegisecurity/config/authentication-defaults.xml");
|
||||
DaoAuthenticationProvider provider = (DaoAuthenticationProvider) context.getBean("authenticationRepository");
|
||||
assertNotNull(provider.getUserDetailsService());
|
||||
assertNull(provider.getSaltSource());
|
||||
assertEquals(PlaintextPasswordEncoder.class, provider.getPasswordEncoder().getClass());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,10 @@ http://www.springframework.org/schema/security http://www.springframework.org/sc
|
||||
|
||||
<!-- If LogoutFilter does not have setHandlers populated, introspect app ctx for LogoutHandlers, using Ordered (if present, otherwise assume Integer.MAX_VALUE) -->
|
||||
<!-- The logoutUrl and redirectAfterLogout are both optional and default to that shown -->
|
||||
<security:logout-support id="logoutFilter"
|
||||
redirectAfterLogoutUrl="/" logoutUrl="/logout" />
|
||||
|
||||
<security:logout-support id="logoutFilter" logoutUrl="/logout" redirectAfterLogoutUrl="/"/>
|
||||
|
||||
|
||||
|
||||
<security:authentication-remember-me-services
|
||||
id="rememberMeServices" key="someValue" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user