SEC-1383: Make MethodSecurityMetadataSourceBeanDefinitionParser extend AbstractBeanDefinitionParser for automatic support of ID attribute.

This commit is contained in:
Luke Taylor 2010-06-26 16:07:23 +01:00
parent 4da4734750
commit 6a79cf7be2
2 changed files with 11 additions and 6 deletions

View File

@ -1,7 +1,7 @@
package org.springframework.security.config; package org.springframework.security.config;
/** /**
* Contains all the element names used by Spring Security 2 namespace support. * Contains all the element names used by Spring Security 3 namespace support.
* *
* @author Ben Alex * @author Ben Alex
*/ */

View File

@ -4,9 +4,9 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext; import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.security.access.ConfigAttribute; import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig; import org.springframework.security.access.SecurityConfig;
@ -16,11 +16,16 @@ import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils; import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element; import org.w3c.dom.Element;
public class MethodSecurityMetadataSourceBeanDefinitionParser implements BeanDefinitionParser { /**
*
* @author Luke Taylor
* @since 3.1
*/
public class MethodSecurityMetadataSourceBeanDefinitionParser extends AbstractBeanDefinitionParser {
static final String ATT_METHOD = "method"; static final String ATT_METHOD = "method";
static final String ATT_ACCESS = "access"; static final String ATT_ACCESS = "access";
public BeanDefinition parse(Element elt, ParserContext pc) { public AbstractBeanDefinition parseInternal(Element elt, ParserContext pc) {
// Parse the included methods // Parse the included methods
List<Element> methods = DomUtils.getChildElementsByTagName(elt, Elements.PROTECT); List<Element> methods = DomUtils.getChildElementsByTagName(elt, Elements.PROTECT);
Map<String, List<ConfigAttribute>> mappings = new LinkedHashMap<String, List<ConfigAttribute>>(); Map<String, List<ConfigAttribute>> mappings = new LinkedHashMap<String, List<ConfigAttribute>>();
@ -32,7 +37,7 @@ public class MethodSecurityMetadataSourceBeanDefinitionParser implements BeanDef
mappings.put(methodName, SecurityConfig.createList(tokens)); mappings.put(methodName, SecurityConfig.createList(tokens));
} }
BeanDefinition metadataSource = new RootBeanDefinition(MapBasedMethodSecurityMetadataSource.class); RootBeanDefinition metadataSource = new RootBeanDefinition(MapBasedMethodSecurityMetadataSource.class);
metadataSource.getConstructorArgumentValues().addGenericArgumentValue(mappings); metadataSource.getConstructorArgumentValues().addGenericArgumentValue(mappings);
return metadataSource; return metadataSource;