diff --git a/config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java b/config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java index ef0df1e8f7..d60f75671e 100644 --- a/config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java +++ b/config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java @@ -83,8 +83,7 @@ class HttpConfigurationBuilder { private final List interceptUrls; // Use ManagedMap to allow placeholder resolution - private List emptyFilterChainPaths; - private ManagedMap> filterChainMap; + private ManagedMap> filterChainMap; private BeanDefinition cpf; private BeanDefinition securityContextPersistenceFilter; @@ -97,7 +96,6 @@ class HttpConfigurationBuilder { private String portMapperName; private BeanReference fsi; - public HttpConfigurationBuilder(Element element, ParserContext pc, UrlMatcher matcher, String portMapperName) { this.httpElt = element; this.pc = pc; @@ -111,8 +109,7 @@ class HttpConfigurationBuilder { } void parseInterceptUrlsForEmptyFilterChains() { - emptyFilterChainPaths = new ArrayList(); - filterChainMap = new ManagedMap>(); + filterChainMap = new ManagedMap>(); for (Element urlElt : interceptUrls) { String path = urlElt.getAttribute(ATT_PATH_PATTERN); @@ -121,9 +118,10 @@ class HttpConfigurationBuilder { pc.getReaderContext().error("path attribute cannot be empty or null", urlElt); } - if (convertPathsToLowerCase) { - path = path.toLowerCase(); - } + BeanDefinitionBuilder pathBean = BeanDefinitionBuilder.rootBeanDefinition(HttpConfigurationBuilder.class); + pathBean.setFactoryMethod("createPath"); + pathBean.addConstructorArgValue(path); + pathBean.addConstructorArgValue(convertPathsToLowerCase); String filters = urlElt.getAttribute(ATT_FILTERS); @@ -133,14 +131,17 @@ class HttpConfigurationBuilder { "filters attribute", urlElt); } - emptyFilterChainPaths.add(path); - List noFilters = Collections.emptyList(); - filterChainMap.put(path, noFilters); + filterChainMap.put(pathBean.getBeanDefinition(), noFilters); } } } + // Needed to account for placeholders + static String createPath(String path, boolean lowerCase) { + return lowerCase ? path.toLowerCase() : path; + } + void createSecurityContextPersistenceFilter() { BeanDefinitionBuilder scpf = BeanDefinitionBuilder.rootBeanDefinition(SecurityContextPersistenceFilter.class); @@ -463,8 +464,8 @@ class HttpConfigurationBuilder { return allowSessionCreation; } - List getEmptyFilterChainPaths() { - return emptyFilterChainPaths; + public ManagedMap> getFilterChainMap() { + return filterChainMap; } List getFilters() { diff --git a/config/src/main/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParser.java b/config/src/main/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParser.java index b1a5588322..1cec9f698b 100644 --- a/config/src/main/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParser.java +++ b/config/src/main/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParser.java @@ -135,18 +135,13 @@ public class HttpSecurityBeanDefinitionParser implements BeanDefinitionParser { filterChain.add(od.bean); } - ManagedMap> filterChainMap = new ManagedMap>(); - - for (String path : httpBldr.getEmptyFilterChainPaths()) { - filterChainMap.put(path, NO_FILTERS); - } - - filterChainMap.put(matcher.getUniversalMatchPattern(), filterChain); + ManagedMap> filterChainMap = httpBldr.getFilterChainMap(); + BeanDefinition universalMatch = new RootBeanDefinition(String.class); + universalMatch.getConstructorArgumentValues().addGenericArgumentValue(matcher.getUniversalMatchPattern()); + filterChainMap.put(universalMatch, filterChain); registerFilterChainProxy(pc, filterChainMap, matcher, source); - - pc.popAndRegisterContainingComponent(); return null; } @@ -252,7 +247,7 @@ public class HttpSecurityBeanDefinitionParser implements BeanDefinitionParser { return customFilters; } - private void registerFilterChainProxy(ParserContext pc, Map> filterChainMap, UrlMatcher matcher, Object source) { + private void registerFilterChainProxy(ParserContext pc, Map> filterChainMap, UrlMatcher matcher, Object source) { if (pc.getRegistry().containsBeanDefinition(BeanIds.FILTER_CHAIN_PROXY)) { pc.getReaderContext().error("Duplicate element detected", source); }