diff --git a/core/pom.xml b/core/pom.xml index 9026f8e128..664cee2767 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -7,13 +7,14 @@ acegi-security-parent 1.1-SNAPSHOT + jar acegi-security Acegi Security System for Spring - scm:svn:https://svn.sourceforge.net/svnroot/acegisecurity/trunk/acegisecurity/core - scm:svn:https://svn.sourceforge.net/svnroot/acegisecurity/trunk/acegisecurity/core - http://svn.sourceforge.net/viewcvs.cgi/acegisecurity/trunk/acegisecurity/core/ + scm:svn:https://acegisecurity.svn.sourceforge.net/svnroot/acegisecurity/trunk/acegisecurity/core + scm:svn:https://acegisecurity.svn.sourceforge.net/svnroot/acegisecurity/trunk/acegisecurity/core + http://acegisecurity.svn.sourceforge.net/viewcvs.cgi/acegisecurity/trunk/acegisecurity/core/ @@ -36,9 +37,9 @@ true - ehcache + net.sf.ehcache ehcache - 1.1 + 1.2.4 true @@ -127,7 +128,7 @@ - + ${basedir}/src/main/resources / diff --git a/core/src/main/java/org/acegisecurity/config/AuthenticationRepositoryBeanDefinitionParser.java b/core/src/main/java/org/acegisecurity/config/AuthenticationRepositoryBeanDefinitionParser.java new file mode 100644 index 0000000000..db925acce3 --- /dev/null +++ b/core/src/main/java/org/acegisecurity/config/AuthenticationRepositoryBeanDefinitionParser.java @@ -0,0 +1,190 @@ +/** + * + */ +package org.acegisecurity.config; + +import org.acegisecurity.providers.dao.DaoAuthenticationProvider; +import org.acegisecurity.providers.dao.salt.ReflectionSaltSource; +import org.acegisecurity.providers.dao.salt.SystemWideSaltSource; +import org.acegisecurity.providers.encoding.Md5PasswordEncoder; +import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; +import org.springframework.util.xml.DomUtils; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * @author vpuri + * + */ +public class AuthenticationRepositoryBeanDefinitionParser extends AbstractBeanDefinitionParser { + + // ~~ Instance Variables + + private static final String REPOSITORY_BEAN_REF = "repositoryBeanRef"; + + private static final String USER_DETAILS_SERVICE = "userDetailsService"; + + private static final String SALT_SOURCE_ELEMENT = "salt-source"; + + private static final String SALT_SOURCE_REF = "saltSourceBeanRef"; + + private static final String SYSTEM_WIDE_SALT_SOURCE = "system-wide"; + + private static final String REFLECTION_SALT_SOURCE = "reflection"; + + private static final String PASSWORD_ENCODER_ELEMENT = "password-encoder"; + + private static final String PASSWORD_ENCODER_REF = "encoderBeanRef"; + + private static final String PASSWORD_ENCODER = "encoder"; + + public static final String AUTOWIRE_AUTODETECT_VALUE = "autodetect"; + + + + // ~~ Methods + /** + * TODO: Document Me !!! + */ + public AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { + Assert.notNull(parserContext, "ParserContext must not be null"); + + RootBeanDefinition repositoryBeanDef = new RootBeanDefinition(DaoAuthenticationProvider.class); + + // if repositoryBeanRef is specified use its referred bean + String userDetailsRef = element.getAttribute(REPOSITORY_BEAN_REF); + if (StringUtils.hasLength(userDetailsRef)) { + repositoryBeanDef.getPropertyValues().addPropertyValue(USER_DETAILS_SERVICE, + new RuntimeBeanReference(userDetailsRef)); + } + else { + // autodetect userDetailsService from App Context ? or we could even create this UserDetailsService BD with autodetection of dataSource hahaha Magic !!! + //repositoryBeanDef.getPropertyValues().addPropertyValue(USER_DETAILS_SERVICE, new RuntimeBeanReference(USER_DETAILS_SERVICE)); + repositoryBeanDef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_AUTODETECT); + } + // check if saltSource is defined + Element saltSourceEle = DomUtils.getChildElementByTagName(element, SALT_SOURCE_ELEMENT); + setSaltSourceProperty(repositoryBeanDef, saltSourceEle); + + Element passwordEncoderEle = DomUtils.getChildElementByTagName(element, PASSWORD_ENCODER_ELEMENT); + setPasswordEncoderProperty(repositoryBeanDef, passwordEncoderEle); + + return repositoryBeanDef; + } + + /** + * + * @param repositoryBeanDef + * @param element + */ + private void setSaltSourceProperty(RootBeanDefinition repositoryBeanDef, Element element) { + if(element != null) { + setBeanReferenceOrInnerBeanDefinitions(repositoryBeanDef, element, "saltSource",element.getAttribute(SALT_SOURCE_REF) ); + } + } + + /** + * + * @param repositoryBeanDef + * @param element + */ + private void setPasswordEncoderProperty(RootBeanDefinition repositoryBeanDef, Element element) { + if(element != null) { + setBeanReferenceOrInnerBeanDefinitions(repositoryBeanDef, element, "passwordEncoder",element.getAttribute(PASSWORD_ENCODER_REF) ); + } + } + /** + * + * @param repositoryBeanDef + * @param element + * @param property + * @param reference + */ + private void setBeanReferenceOrInnerBeanDefinitions(RootBeanDefinition repositoryBeanDef, Element element ,String property, String reference) { + // check for encoderBeanRef attribute + if (StringUtils.hasLength(reference)) { + repositoryBeanDef.getPropertyValues().addPropertyValue(property, new RuntimeBeanReference(reference)); + } + else { + doSetInnerBeanDefinitions(repositoryBeanDef, element); + } + } + + /** + * + * @param repositoryBeanDef + * @param element + */ + private void doSetInnerBeanDefinitions(RootBeanDefinition repositoryBeanDef, Element element) { + NodeList children = element.getChildNodes(); + for (int i = 0, n = children.getLength(); i < n; i++) { + Node node = children.item(i); + + if (node.getNodeType() == Node.ELEMENT_NODE) { + Element childElement = (Element) node; + RootBeanDefinition innerBeanDefinition = null; + + if (SYSTEM_WIDE_SALT_SOURCE.equals(node.getLocalName())) { + innerBeanDefinition = createSystemWideSaltSource(childElement); + repositoryBeanDef.getPropertyValues().addPropertyValue("saltSource", innerBeanDefinition); + } + else if (REFLECTION_SALT_SOURCE.equals(node.getLocalName())) { + innerBeanDefinition = createReflectionSaltSource(childElement); + repositoryBeanDef.getPropertyValues().addPropertyValue("saltSource", innerBeanDefinition); + } + if (PASSWORD_ENCODER.equals(node.getLocalName())) { + RootBeanDefinition passwordEncoderInnerBeanDefinition = createPasswordEncoder(childElement); + repositoryBeanDef.getPropertyValues().addPropertyValue("passwordEncoder", passwordEncoderInnerBeanDefinition); + } + } + } + } + + /** + * + * @param childElement + * @return + */ + private RootBeanDefinition createPasswordEncoder(Element childElement) { + String attributeValue = childElement.getAttribute("method"); + RootBeanDefinition definition = null; + // TODO: add other encoders support + if(attributeValue.equals("md5")){ + definition = new RootBeanDefinition(Md5PasswordEncoder.class); + } + return definition; + } + + /** + * + * @param saltSourceTypeElement + * @return + */ + private RootBeanDefinition createReflectionSaltSource(Element saltSourceTypeElement) { + RootBeanDefinition definition = new RootBeanDefinition(ReflectionSaltSource.class); + definition.getPropertyValues().addPropertyValue("userPropertyToUse", saltSourceTypeElement.getAttribute("userPropertyToUse")); + return definition; + } + + /** + * + * @param saltSourceTypeElement + * @return + */ + private RootBeanDefinition createSystemWideSaltSource( Element saltSourceTypeElement) { + RootBeanDefinition definition = new RootBeanDefinition(SystemWideSaltSource.class); + definition.getPropertyValues().addPropertyValue("systemWideSalt", saltSourceTypeElement.getAttribute("systemWideSalt")); + return definition; + } + + +} + + diff --git a/core/src/main/java/org/acegisecurity/config/ContextIntegrationBeanDefinitionParser.java b/core/src/main/java/org/acegisecurity/config/ContextIntegrationBeanDefinitionParser.java new file mode 100644 index 0000000000..03b424e0ef --- /dev/null +++ b/core/src/main/java/org/acegisecurity/config/ContextIntegrationBeanDefinitionParser.java @@ -0,0 +1,78 @@ +/** + * + */ +package org.acegisecurity.config; + +import org.acegisecurity.context.HttpSessionContextIntegrationFilter; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.core.Conventions; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; + +/** + * + * @author vpuri + * + */ +public class ContextIntegrationBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { + + private static final String HTTP_SESSION_CONTEXT_INTEGRATION = "session-context-integration"; + + private static final String SESSION_CREATION = "sessionCreation"; + + + + private static final String IF_REQUIRED = "ifRequired"; + + private static final String ALWAYS = "always"; + + private static final String NEVER = "never"; + + + @Override + protected Class getBeanClass(Element element) { + return HttpSessionContextIntegrationFilter.class; + } + + + @Override + protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + + NamedNodeMap attributes = element.getAttributes(); + + for (int x = 0; x < attributes.getLength(); x++) { + Attr attribute = (Attr) attributes.item(x); + String attributeName = attribute.getLocalName(); + if ( !ID_ATTRIBUTE.equals(attributeName)) { + if (attributeName.equals(SESSION_CREATION)) { + String sessionCreation = element.getAttribute(SESSION_CREATION); + + if(sessionCreation.equals(IF_REQUIRED)) { + builder.addPropertyValue("allowSessionCreation", Boolean.TRUE); + } + + if(sessionCreation.equals(ALWAYS)) { + builder.addPropertyValue("allowSessionCreation", Boolean.TRUE); + } + + if(sessionCreation.equals(NEVER)) { + builder.addPropertyValue("allowSessionCreation", Boolean.FALSE); + } + } + else{ + String propertyName = Conventions.attributeNameToPropertyName(attributeName); + Assert.state(StringUtils.hasText(propertyName), + "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty."); + builder.addPropertyValue(propertyName, attribute.getValue()); + } + } + } + } +} + + diff --git a/core/src/main/java/org/acegisecurity/config/RememberMeFilterBeanDefinitionParser.java b/core/src/main/java/org/acegisecurity/config/RememberMeFilterBeanDefinitionParser.java new file mode 100644 index 0000000000..518af7c2d4 --- /dev/null +++ b/core/src/main/java/org/acegisecurity/config/RememberMeFilterBeanDefinitionParser.java @@ -0,0 +1,49 @@ +/** + * + */ +package org.acegisecurity.config; + +import org.acegisecurity.ui.rememberme.RememberMeProcessingFilter; +import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; +import org.springframework.beans.factory.xml.BeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; +import org.w3c.dom.Element; + +/** + * @author vpuri + * + *@since + */ +public class RememberMeFilterBeanDefinitionParser extends AbstractBeanDefinitionParser implements + BeanDefinitionParser { + + private static final String REMEMBER_ME_SERVICES_REF = "rememberMeServicesBeanRef"; + + private static final String REMEMBER_ME_SERVICES = "rememberMeServices"; + + /** + * + */ + protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { + Assert.notNull(parserContext, "ParserContext must not be null"); + + RootBeanDefinition rememberMeFilterBeanDef = new RootBeanDefinition(RememberMeProcessingFilter.class); + + // detect all the required dependencies and autowire them by type + rememberMeFilterBeanDef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_AUTODETECT); + + // check if rememberMeServicesBeanRef is defined and if it's specified use its referred bean + String rememberMeServicesRef = element.getAttribute(REMEMBER_ME_SERVICES_REF); + if (StringUtils.hasLength(rememberMeServicesRef)) { + rememberMeFilterBeanDef.getPropertyValues().addPropertyValue(REMEMBER_ME_SERVICES, + new RuntimeBeanReference(rememberMeServicesRef)); + } + return rememberMeFilterBeanDef; + } + +} diff --git a/core/src/main/java/org/acegisecurity/config/RememberMeServicesBeanDefinitionParser.java b/core/src/main/java/org/acegisecurity/config/RememberMeServicesBeanDefinitionParser.java new file mode 100644 index 0000000000..d93f44979d --- /dev/null +++ b/core/src/main/java/org/acegisecurity/config/RememberMeServicesBeanDefinitionParser.java @@ -0,0 +1,61 @@ +/** + * + */ +package org.acegisecurity.config; + +import org.acegisecurity.ui.rememberme.TokenBasedRememberMeServices; +import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; +import org.springframework.beans.factory.xml.BeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; +import org.w3c.dom.Element; + +/** + * @author vpuri + * + */ +public class RememberMeServicesBeanDefinitionParser extends AbstractBeanDefinitionParser implements + BeanDefinitionParser { + + private static final String PRINCIPAL_REPOSITORY_BEAN_REF = "principalRepositoryBeanRef"; + + private static final String USER_DETAILS_SERVICE = "userDetailsService"; + + /* + * key is optional; if unspecified, pick a rnd int and use for all unspecified key properties for acegi beans + */ + private static final String KEY = "key"; + + /** + * + */ + protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { + Assert.notNull(parserContext, "ParserContext must not be null"); + + RootBeanDefinition rememberMeServicesBeanDef = new RootBeanDefinition(TokenBasedRememberMeServices.class); + + String keyValue = element.getAttribute(KEY); + if (StringUtils.hasLength(keyValue)) { + rememberMeServicesBeanDef.getPropertyValues().addPropertyValue(KEY,keyValue); + } else { + // pick a rnd int + } + + // check if rememberMeServicesBeanRef is defined and if it's specified use its referred bean + String rememberMeServicesRef = element.getAttribute(PRINCIPAL_REPOSITORY_BEAN_REF); + if (StringUtils.hasLength(rememberMeServicesRef)) { + rememberMeServicesBeanDef.getPropertyValues().addPropertyValue(USER_DETAILS_SERVICE, + new RuntimeBeanReference(rememberMeServicesRef)); + } + else { + // auto-detects everything + rememberMeServicesBeanDef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_AUTODETECT); + } + return rememberMeServicesBeanDef; + } + +} diff --git a/core/src/main/java/org/acegisecurity/config/SecurityNamespaceHandler.java b/core/src/main/java/org/acegisecurity/config/SecurityNamespaceHandler.java new file mode 100644 index 0000000000..9d18e7018f --- /dev/null +++ b/core/src/main/java/org/acegisecurity/config/SecurityNamespaceHandler.java @@ -0,0 +1,28 @@ +/** + * + */ +package org.acegisecurity.config; + +import org.springframework.beans.factory.xml.BeanDefinitionParser; +import org.springframework.beans.factory.xml.NamespaceHandlerSupport; + +/** + * {@link org.springframework.beans.factory.xml.NamespaceHandler} for the 'security' namespace. + * @author vpuri + * + * @since + */ +public class SecurityNamespaceHandler extends NamespaceHandlerSupport { + + /** + * Register the {@link BeanDefinitionParser BeanDefinitionParsers} for the + * 'context-integration', ' and '' elements. + */ + public void init() { + registerBeanDefinitionParser("session-context-integration", new ContextIntegrationBeanDefinitionParser()); + registerBeanDefinitionParser("authentication-repository", new AuthenticationRepositoryBeanDefinitionParser()); + registerBeanDefinitionParser("authentication-remember-me-services", new RememberMeServicesBeanDefinitionParser()); + registerBeanDefinitionParser("authentication-remember-me-filter", new RememberMeFilterBeanDefinitionParser()); + } + +} diff --git a/core/src/main/resources/META-INF/spring.handlers b/core/src/main/resources/META-INF/spring.handlers new file mode 100644 index 0000000000..3ed1602939 --- /dev/null +++ b/core/src/main/resources/META-INF/spring.handlers @@ -0,0 +1 @@ +http\://www.springframework.org/schema/security=org.acegisecurity.config.SecurityNamespaceHandler diff --git a/core/src/main/resources/META-INF/spring.schemas b/core/src/main/resources/META-INF/spring.schemas new file mode 100644 index 0000000000..91ab095477 --- /dev/null +++ b/core/src/main/resources/META-INF/spring.schemas @@ -0,0 +1,2 @@ +http\://www.springframework.org/schema/security/spring-security-2.0.xsd=org/acegisecurity/config/spring-security-2.0.xsd + diff --git a/core/src/main/resources/org/acegisecurity/config/spring-security-2.0.xsd b/core/src/main/resources/org/acegisecurity/config/spring-security-2.0.xsd new file mode 100644 index 0000000000..51dbdc5599 --- /dev/null +++ b/core/src/main/resources/org/acegisecurity/config/spring-security-2.0.xsd @@ -0,0 +1,221 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + HttpSession + for every request before proceeding through the filter chain, even if the + HttpSession would not ordinarily have been created. By + default this is false, which is entirely appropriate for + most circumstances as you do not want a HttpSession + created unless the filter actually needs one. It is envisaged the main + situation in which this property would be set to true is + if using other filters that depend on a HttpSession + already existing, such as those which need to obtain a session ID. This + is only required in specialised cases, so leave it set to + false unless you have an actual requirement and are + conscious of the session creation overhead. + ]]> + + + + + + + SecurityContext will be cloned from + the HttpSession. The default is to simply reference (ie + the default is false). The default may cause issues if + concurrent threads need to have a different security identity from other + threads being concurrently processed that share the same + HttpSession. In most normal environments this does not + represent an issue, as changes to the security identity in one thread is + allowed to affect the security identitiy in other threads associated with + the same HttpSession. For unusual cases where this is not + permitted, change this value to true and ensure the + {@link #context} is set to a SecurityContext that + implements {@link Cloneable} and overrides the clone() + method. + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/test/java/org/acegisecurity/config/AuthenticationRepositoryParserTest.java b/core/src/test/java/org/acegisecurity/config/AuthenticationRepositoryParserTest.java new file mode 100644 index 0000000000..ce1311ddcf --- /dev/null +++ b/core/src/test/java/org/acegisecurity/config/AuthenticationRepositoryParserTest.java @@ -0,0 +1,115 @@ +/** + * + */ +package org.acegisecurity.config; + +import junit.framework.TestCase; + +import org.acegisecurity.providers.AuthenticationProvider; +import org.acegisecurity.providers.dao.DaoAuthenticationProvider; +import org.acegisecurity.providers.dao.SaltSource; +import org.acegisecurity.providers.encoding.Md5PasswordEncoder; +import org.acegisecurity.providers.encoding.PasswordEncoder; +import org.acegisecurity.providers.encoding.PlaintextPasswordEncoder; +import org.acegisecurity.userdetails.jdbc.JdbcDaoImpl; +import org.springframework.beans.PropertyValue; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +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(); + + 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"); + 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(); + // 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()); + } + + 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 + 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() ); + } + + 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()); + + } +} diff --git a/core/src/test/java/org/acegisecurity/config/HttpSessionContextIntegrationParserTest.java b/core/src/test/java/org/acegisecurity/config/HttpSessionContextIntegrationParserTest.java new file mode 100644 index 0000000000..09f05815a6 --- /dev/null +++ b/core/src/test/java/org/acegisecurity/config/HttpSessionContextIntegrationParserTest.java @@ -0,0 +1,44 @@ +/** + * + */ +package org.acegisecurity.config; + +import javax.servlet.Filter; + +import org.acegisecurity.context.HttpSessionContextIntegrationFilter; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + + +import junit.framework.TestCase; + +/** + * @author vpuri + * + */ +public class HttpSessionContextIntegrationParserTest extends TestCase { + + public void testApplicationContext() { + ApplicationContext context = new ClassPathXmlApplicationContext("org/acegisecurity/config/session-context-integration-defaults.xml"); + ConfigurableListableBeanFactory clbf = + (ConfigurableListableBeanFactory)context.getAutowireCapableBeanFactory(); + + String[] names = clbf.getBeanNamesForType(Filter.class); + assertEquals(1, names.length); + + // check bean name + RootBeanDefinition definition = (RootBeanDefinition)clbf.getBeanDefinition(names[0]); + assertEquals(HttpSessionContextIntegrationFilter.class, definition.getBeanClass()); + + // check properties + //get the bean + HttpSessionContextIntegrationFilter filter = (HttpSessionContextIntegrationFilter)context.getBean("httpSessionContextIntegrationFilter"); + assertFalse(filter.isAllowSessionCreation()); + assertNotNull(definition.getPropertyValues().getPropertyValue("allowSessionCreation")); + assertFalse(filter.isForceEagerSessionCreation()); + assertFalse(filter.isCloneFromHttpSession()); + } + +} diff --git a/core/src/test/java/org/acegisecurity/config/RememberMeBeanDefinitionParserTest.java b/core/src/test/java/org/acegisecurity/config/RememberMeBeanDefinitionParserTest.java new file mode 100644 index 0000000000..2c32686c41 --- /dev/null +++ b/core/src/test/java/org/acegisecurity/config/RememberMeBeanDefinitionParserTest.java @@ -0,0 +1,15 @@ +package org.acegisecurity.config; + +import junit.framework.TestCase; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class RememberMeBeanDefinitionParserTest extends TestCase { + + public void testRememberMeDefaults() { + ApplicationContext context = new ClassPathXmlApplicationContext("org/acegisecurity/config/remember-me-defaults.xml"); + + } + +} diff --git a/core/src/test/resources/org/acegisecurity/config/authentication-beanRef-attributes.xml b/core/src/test/resources/org/acegisecurity/config/authentication-beanRef-attributes.xml new file mode 100644 index 0000000000..43b4967648 --- /dev/null +++ b/core/src/test/resources/org/acegisecurity/config/authentication-beanRef-attributes.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + org.hsqldb.jdbcDriver + + + jdbc:hsqldb:mem:test + + + + sa + + + + + + + + + 12345 + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/acegisecurity/config/authentication-dao-defaults.xml b/core/src/test/resources/org/acegisecurity/config/authentication-dao-defaults.xml new file mode 100644 index 0000000000..cf53167f7d --- /dev/null +++ b/core/src/test/resources/org/acegisecurity/config/authentication-dao-defaults.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + org.hsqldb.jdbcDriver + + + jdbc:hsqldb:mem:test + + + + sa + + + + + + + + + 12345 + + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/acegisecurity/config/authentication-defaults.xml b/core/src/test/resources/org/acegisecurity/config/authentication-defaults.xml new file mode 100644 index 0000000000..d4a24931d9 --- /dev/null +++ b/core/src/test/resources/org/acegisecurity/config/authentication-defaults.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + org.hsqldb.jdbcDriver + + + jdbc:hsqldb:mem:test + + + + sa + + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/acegisecurity/config/authentication-innerbeans.xml b/core/src/test/resources/org/acegisecurity/config/authentication-innerbeans.xml new file mode 100644 index 0000000000..f096d01e78 --- /dev/null +++ b/core/src/test/resources/org/acegisecurity/config/authentication-innerbeans.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.hsqldb.jdbcDriver + + + jdbc:hsqldb:mem:test + + + + sa + + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/acegisecurity/config/remember-me-defaults.xml b/core/src/test/resources/org/acegisecurity/config/remember-me-defaults.xml new file mode 100644 index 0000000000..8bd753b1d9 --- /dev/null +++ b/core/src/test/resources/org/acegisecurity/config/remember-me-defaults.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.hsqldb.jdbcDriver + + + jdbc:hsqldb:mem:test + + + + sa + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/acegisecurity/config/security-namespaces.xml b/core/src/test/resources/org/acegisecurity/config/security-namespaces.xml new file mode 100644 index 0000000000..ca133eb5d6 --- /dev/null +++ b/core/src/test/resources/org/acegisecurity/config/security-namespaces.xml @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + **/*=AUTODETECT_ALL_ORDERED_FILTERS + **/*=filter1,filter2,filter3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/acegisecurity/config/session-context-integration-defaults.xml b/core/src/test/resources/org/acegisecurity/config/session-context-integration-defaults.xml new file mode 100644 index 0000000000..1ba0d6483e --- /dev/null +++ b/core/src/test/resources/org/acegisecurity/config/session-context-integration-defaults.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + +