|
@@ -5,7 +5,10 @@ import org.springframework.beans.factory.config.RuntimeBeanReference;
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
|
|
import org.springframework.beans.factory.support.ManagedList;
|
|
|
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
|
|
+import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
|
|
+import org.springframework.beans.factory.xml.ParserContext;
|
|
|
import org.springframework.security.web.SecurityFilterChain;
|
|
|
+import org.springframework.util.Assert;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.w3c.dom.Element;
|
|
|
|
|
@@ -14,20 +17,24 @@ import java.util.*;
|
|
|
/**
|
|
|
* @author Luke Taylor
|
|
|
*/
|
|
|
-public class FilterChainBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
|
|
|
+public class FilterChainBeanDefinitionParser implements BeanDefinitionParser {
|
|
|
+ private static final String ATT_REQUEST_MATCHER_REF = "request-matcher-ref";
|
|
|
|
|
|
- @Override
|
|
|
- protected Class getBeanClass(Element element) {
|
|
|
- return SecurityFilterChain.class;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void doParse(Element elt, BeanDefinitionBuilder builder) {
|
|
|
+ public BeanDefinition parse(Element elt, ParserContext pc) {
|
|
|
MatcherType matcherType = MatcherType.fromElement(elt);
|
|
|
String path = elt.getAttribute(HttpSecurityBeanDefinitionParser.ATT_PATH_PATTERN);
|
|
|
+ String requestMatcher = elt.getAttribute(ATT_REQUEST_MATCHER_REF);
|
|
|
String filters = elt.getAttribute(HttpSecurityBeanDefinitionParser.ATT_FILTERS);
|
|
|
|
|
|
- builder.addConstructorArgValue(matcherType.createMatcher(path, null));
|
|
|
+ BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(SecurityFilterChain.class);
|
|
|
+
|
|
|
+ if (StringUtils.hasText(path)) {
|
|
|
+ Assert.isTrue(!StringUtils.hasText(requestMatcher), "");
|
|
|
+ builder.addConstructorArgValue(matcherType.createMatcher(path, null));
|
|
|
+ } else {
|
|
|
+ Assert.isTrue(StringUtils.hasText(requestMatcher), "");
|
|
|
+ builder.addConstructorArgReference(requestMatcher);
|
|
|
+ }
|
|
|
|
|
|
if (filters.equals(HttpSecurityBeanDefinitionParser.OPT_FILTERS_NONE)) {
|
|
|
builder.addConstructorArgValue(Collections.EMPTY_LIST);
|
|
@@ -41,5 +48,7 @@ public class FilterChainBeanDefinitionParser extends AbstractSingleBeanDefinitio
|
|
|
|
|
|
builder.addConstructorArgValue(filterChain);
|
|
|
}
|
|
|
+
|
|
|
+ return builder.getBeanDefinition();
|
|
|
}
|
|
|
}
|