View Javadoc

1   package org.springframework.security.config;
2   
3   import org.springframework.beans.factory.config.BeanDefinition;
4   import org.springframework.beans.factory.support.RootBeanDefinition;
5   import org.springframework.beans.factory.xml.BeanDefinitionParser;
6   import org.springframework.beans.factory.xml.ParserContext;
7   import org.springframework.security.providers.dao.salt.ReflectionSaltSource;
8   import org.springframework.security.providers.dao.salt.SystemWideSaltSource;
9   import org.springframework.util.StringUtils;
10  import org.w3c.dom.Element;
11  
12  /**
13   * @author Luke Taylor
14   * @version $Id: SaltSourceBeanDefinitionParser.java 2884 2008-04-07 20:20:58Z luke_t $
15   * @since 2.0
16   */
17  public class SaltSourceBeanDefinitionParser implements BeanDefinitionParser {
18      static final String ATT_USER_PROPERTY = "user-property";
19      static final String ATT_SYSTEM_WIDE = "system-wide";
20  
21      public BeanDefinition parse(Element element, ParserContext parserContext) {
22          RootBeanDefinition saltSource;
23          String userProperty = element.getAttribute(ATT_USER_PROPERTY);
24  
25          if (StringUtils.hasText(userProperty)) {
26              saltSource = new RootBeanDefinition(ReflectionSaltSource.class);
27              saltSource.getPropertyValues().addPropertyValue("userPropertyToUse", userProperty);
28              saltSource.setSource(parserContext.extractSource(element));
29              saltSource.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
30              
31              return saltSource;
32          }
33  
34          String systemWideSalt = element.getAttribute(ATT_SYSTEM_WIDE);
35  
36          if (StringUtils.hasText(systemWideSalt)) {
37              saltSource = new RootBeanDefinition(SystemWideSaltSource.class);
38              saltSource.getPropertyValues().addPropertyValue("systemWideSalt", systemWideSalt);
39              saltSource.setSource(parserContext.extractSource(element));
40              saltSource.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
41  
42              return saltSource;
43          }
44  
45          parserContext.getReaderContext().error(Elements.SALT_SOURCE + " requires an attribute", element);
46          return null;
47      }
48  }