01: package org.acegisecurity.config;
02:
03: import junit.framework.TestCase;
04:
05: import org.acegisecurity.ldap.InitialDirContextFactory;
06: import org.acegisecurity.providers.ldap.LdapAuthenticationProvider;
07: import org.acegisecurity.providers.ldap.authenticator.BindAuthenticator;
08: import org.springframework.beans.PropertyValue;
09: import org.springframework.beans.PropertyValues;
10: import org.springframework.beans.factory.config.BeanDefinition;
11: import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
12: import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
13: import org.springframework.beans.factory.support.ManagedList;
14: import org.springframework.beans.factory.support.RootBeanDefinition;
15: import org.springframework.context.ApplicationContext;
16: import org.springframework.context.support.ClassPathXmlApplicationContext;
17:
18: /**
19: * @author Vishal Puri
20: *
21: */
22: public class LdapAuthenticationProviderBeanDefinitionParserTests extends
23: TestCase {
24:
25: public void testBeanDefinitionCreation() {
26: ApplicationContext context = new ClassPathXmlApplicationContext(
27: "org/acegisecurity/config/ldap-config.xml");
28: ConfigurableListableBeanFactory bf = (ConfigurableListableBeanFactory) context
29: .getAutowireCapableBeanFactory();
30: BeanDefinition def = (RootBeanDefinition) bf
31: .getBeanDefinition("authenticationManager");
32: assertNotNull(def);
33: PropertyValues values = def.getPropertyValues();
34: PropertyValue value = values.getPropertyValue("providers");
35: assertNotNull(value);
36: ManagedList list = (ManagedList) value.getValue();
37: assertEquals(1, list.size());
38:
39: RootBeanDefinition definition = (RootBeanDefinition) list
40: .get(0);
41: assertEquals(LdapAuthenticationProvider.class, definition
42: .getBeanClass());
43:
44: assertEquals(2, definition.getConstructorArgumentValues()
45: .getArgumentCount());
46:
47: ValueHolder holder = definition.getConstructorArgumentValues()
48: .getArgumentValue(0, BindAuthenticator.class);
49: assertNotNull(holder.getConvertedValue() instanceof BindAuthenticator);
50: RootBeanDefinition authenticatorDefinition = (RootBeanDefinition) holder
51: .getValue();
52: assertEquals(1, authenticatorDefinition
53: .getConstructorArgumentValues().getArgumentCount());
54:
55: RootBeanDefinition initialContextDir = (RootBeanDefinition) authenticatorDefinition
56: .getConstructorArgumentValues().getArgumentValue(0,
57: InitialDirContextFactory.class).getValue();
58: assertEquals("cn=manager,dc=acegisecurity,dc=org",
59: initialContextDir.getPropertyValues().getPropertyValue(
60: "managerDn").getValue());
61: assertEquals(
62: "ldap://monkeymachine:389/dc=acegisecurity,dc=org",
63: initialContextDir.getConstructorArgumentValues()
64: .getArgumentValue(0, String.class).getValue());
65: }
66: }
|