View Javadoc

1   package org.springframework.security.config;
2   
3   import org.springframework.beans.factory.support.RootBeanDefinition;
4   import org.springframework.beans.factory.xml.BeanDefinitionParser;
5   import org.springframework.beans.factory.xml.ParserContext;
6   import org.springframework.beans.factory.config.BeanDefinition;
7   import org.springframework.beans.factory.config.RuntimeBeanReference;
8   import org.springframework.util.StringUtils;
9   
10  import org.w3c.dom.Element;
11  
12  /**
13   * Registers an alias name for the default ProviderManager used by the namespace
14   * configuration, allowing users to reference it in their beans and clearly see where the name is
15   * coming from. Also allows the ConcurrentSessionController to be set on the ProviderManager.
16   *
17   * @author Luke Taylor
18   * @version $Id: AuthenticationManagerBeanDefinitionParser.java 3194 2008-07-30 11:01:23Z luke_t $
19   */
20  public class AuthenticationManagerBeanDefinitionParser implements BeanDefinitionParser {
21      private static final String ATT_SESSION_CONTROLLER_REF = "session-controller-ref";
22      private static final String ATT_ALIAS = "alias";
23  
24      public BeanDefinition parse(Element element, ParserContext parserContext) {
25          ConfigUtils.registerProviderManagerIfNecessary(parserContext);
26          
27          String alias = element.getAttribute(ATT_ALIAS);
28  
29          if (!StringUtils.hasText(alias)) {
30              parserContext.getReaderContext().error(ATT_ALIAS + " is required.", element );
31          }
32          
33          String sessionControllerRef = element.getAttribute(ATT_SESSION_CONTROLLER_REF);
34          
35          if (StringUtils.hasText(sessionControllerRef)) {
36              BeanDefinition authManager = parserContext.getRegistry().getBeanDefinition(BeanIds.AUTHENTICATION_MANAGER);
37              ConfigUtils.setSessionControllerOnAuthenticationManager(parserContext, 
38                      BeanIds.CONCURRENT_SESSION_CONTROLLER, element);
39              authManager.getPropertyValues().addPropertyValue("sessionController", 
40                      new RuntimeBeanReference(sessionControllerRef));
41              RootBeanDefinition sessionRegistryInjector = new RootBeanDefinition(SessionRegistryInjectionBeanPostProcessor.class);
42              sessionRegistryInjector.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
43              sessionRegistryInjector.getConstructorArgumentValues().addGenericArgumentValue(sessionControllerRef);
44              
45              parserContext.getRegistry().registerBeanDefinition(BeanIds.SESSION_REGISTRY_INJECTION_POST_PROCESSOR, sessionRegistryInjector);
46          }
47  
48          parserContext.getRegistry().registerAlias(BeanIds.AUTHENTICATION_MANAGER, alias);
49  
50          return null;
51      }    
52  }