mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-08 11:32:47 +00:00
SEC-1404: Use a factory method to convert the path to lower case for use in the filter-chain map.
Delays the conversion till after palceholders have been substituted, preventing the placeholder from being converted (or the value not being converted).
This commit is contained in:
parent
d2413cf237
commit
2173029216
@ -83,8 +83,7 @@ class HttpConfigurationBuilder {
|
|||||||
private final List<Element> interceptUrls;
|
private final List<Element> interceptUrls;
|
||||||
|
|
||||||
// Use ManagedMap to allow placeholder resolution
|
// Use ManagedMap to allow placeholder resolution
|
||||||
private List<String> emptyFilterChainPaths;
|
private ManagedMap<BeanDefinition, List<BeanMetadataElement>> filterChainMap;
|
||||||
private ManagedMap<String, List<BeanMetadataElement>> filterChainMap;
|
|
||||||
|
|
||||||
private BeanDefinition cpf;
|
private BeanDefinition cpf;
|
||||||
private BeanDefinition securityContextPersistenceFilter;
|
private BeanDefinition securityContextPersistenceFilter;
|
||||||
@ -97,7 +96,6 @@ class HttpConfigurationBuilder {
|
|||||||
private String portMapperName;
|
private String portMapperName;
|
||||||
private BeanReference fsi;
|
private BeanReference fsi;
|
||||||
|
|
||||||
|
|
||||||
public HttpConfigurationBuilder(Element element, ParserContext pc, UrlMatcher matcher, String portMapperName) {
|
public HttpConfigurationBuilder(Element element, ParserContext pc, UrlMatcher matcher, String portMapperName) {
|
||||||
this.httpElt = element;
|
this.httpElt = element;
|
||||||
this.pc = pc;
|
this.pc = pc;
|
||||||
@ -111,8 +109,7 @@ class HttpConfigurationBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void parseInterceptUrlsForEmptyFilterChains() {
|
void parseInterceptUrlsForEmptyFilterChains() {
|
||||||
emptyFilterChainPaths = new ArrayList<String>();
|
filterChainMap = new ManagedMap<BeanDefinition, List<BeanMetadataElement>>();
|
||||||
filterChainMap = new ManagedMap<String, List<BeanMetadataElement>>();
|
|
||||||
|
|
||||||
for (Element urlElt : interceptUrls) {
|
for (Element urlElt : interceptUrls) {
|
||||||
String path = urlElt.getAttribute(ATT_PATH_PATTERN);
|
String path = urlElt.getAttribute(ATT_PATH_PATTERN);
|
||||||
@ -121,9 +118,10 @@ class HttpConfigurationBuilder {
|
|||||||
pc.getReaderContext().error("path attribute cannot be empty or null", urlElt);
|
pc.getReaderContext().error("path attribute cannot be empty or null", urlElt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (convertPathsToLowerCase) {
|
BeanDefinitionBuilder pathBean = BeanDefinitionBuilder.rootBeanDefinition(HttpConfigurationBuilder.class);
|
||||||
path = path.toLowerCase();
|
pathBean.setFactoryMethod("createPath");
|
||||||
}
|
pathBean.addConstructorArgValue(path);
|
||||||
|
pathBean.addConstructorArgValue(convertPathsToLowerCase);
|
||||||
|
|
||||||
String filters = urlElt.getAttribute(ATT_FILTERS);
|
String filters = urlElt.getAttribute(ATT_FILTERS);
|
||||||
|
|
||||||
@ -133,14 +131,17 @@ class HttpConfigurationBuilder {
|
|||||||
"filters attribute", urlElt);
|
"filters attribute", urlElt);
|
||||||
}
|
}
|
||||||
|
|
||||||
emptyFilterChainPaths.add(path);
|
|
||||||
|
|
||||||
List<BeanMetadataElement> noFilters = Collections.emptyList();
|
List<BeanMetadataElement> 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() {
|
void createSecurityContextPersistenceFilter() {
|
||||||
BeanDefinitionBuilder scpf = BeanDefinitionBuilder.rootBeanDefinition(SecurityContextPersistenceFilter.class);
|
BeanDefinitionBuilder scpf = BeanDefinitionBuilder.rootBeanDefinition(SecurityContextPersistenceFilter.class);
|
||||||
|
|
||||||
@ -463,8 +464,8 @@ class HttpConfigurationBuilder {
|
|||||||
return allowSessionCreation;
|
return allowSessionCreation;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> getEmptyFilterChainPaths() {
|
public ManagedMap<BeanDefinition, List<BeanMetadataElement>> getFilterChainMap() {
|
||||||
return emptyFilterChainPaths;
|
return filterChainMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<OrderDecorator> getFilters() {
|
List<OrderDecorator> getFilters() {
|
||||||
|
@ -135,18 +135,13 @@ public class HttpSecurityBeanDefinitionParser implements BeanDefinitionParser {
|
|||||||
filterChain.add(od.bean);
|
filterChain.add(od.bean);
|
||||||
}
|
}
|
||||||
|
|
||||||
ManagedMap<String, List<BeanMetadataElement>> filterChainMap = new ManagedMap<String, List<BeanMetadataElement>>();
|
ManagedMap<BeanDefinition, List<BeanMetadataElement>> filterChainMap = httpBldr.getFilterChainMap();
|
||||||
|
BeanDefinition universalMatch = new RootBeanDefinition(String.class);
|
||||||
for (String path : httpBldr.getEmptyFilterChainPaths()) {
|
universalMatch.getConstructorArgumentValues().addGenericArgumentValue(matcher.getUniversalMatchPattern());
|
||||||
filterChainMap.put(path, NO_FILTERS);
|
filterChainMap.put(universalMatch, filterChain);
|
||||||
}
|
|
||||||
|
|
||||||
filterChainMap.put(matcher.getUniversalMatchPattern(), filterChain);
|
|
||||||
|
|
||||||
registerFilterChainProxy(pc, filterChainMap, matcher, source);
|
registerFilterChainProxy(pc, filterChainMap, matcher, source);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pc.popAndRegisterContainingComponent();
|
pc.popAndRegisterContainingComponent();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -252,7 +247,7 @@ public class HttpSecurityBeanDefinitionParser implements BeanDefinitionParser {
|
|||||||
return customFilters;
|
return customFilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerFilterChainProxy(ParserContext pc, Map<String, List<BeanMetadataElement>> filterChainMap, UrlMatcher matcher, Object source) {
|
private void registerFilterChainProxy(ParserContext pc, Map<BeanDefinition, List<BeanMetadataElement>> filterChainMap, UrlMatcher matcher, Object source) {
|
||||||
if (pc.getRegistry().containsBeanDefinition(BeanIds.FILTER_CHAIN_PROXY)) {
|
if (pc.getRegistry().containsBeanDefinition(BeanIds.FILTER_CHAIN_PROXY)) {
|
||||||
pc.getReaderContext().error("Duplicate <http> element detected", source);
|
pc.getReaderContext().error("Duplicate <http> element detected", source);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user