Pulled methods and fields up into AbstractFilterInvocationDefinitionSource to make it easier to query the map size etc, regardless of the specific type.
This commit is contained in:
@@ -17,6 +17,9 @@ package org.springframework.security.intercept.web;
|
||||
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract implementation of <Code>FilterInvocationDefinitionSource</code>.
|
||||
@@ -26,6 +29,10 @@ import org.springframework.security.ConfigAttributeDefinition;
|
||||
*/
|
||||
public abstract class AbstractFilterInvocationDefinitionSource implements FilterInvocationDefinitionSource {
|
||||
|
||||
protected List requestMap = new Vector();
|
||||
|
||||
private boolean convertUrlToLowercaseBeforeComparison = false;
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public ConfigAttributeDefinition getAttributes(Object object)
|
||||
@@ -58,4 +65,20 @@ public abstract class AbstractFilterInvocationDefinitionSource implements Filter
|
||||
public boolean supports(Class clazz) {
|
||||
return FilterInvocation.class.isAssignableFrom(clazz);
|
||||
}
|
||||
|
||||
public int getMapSize() {
|
||||
return this.requestMap.size();
|
||||
}
|
||||
|
||||
public boolean isConvertUrlToLowercaseBeforeComparison() {
|
||||
return convertUrlToLowercaseBeforeComparison;
|
||||
}
|
||||
|
||||
public void setConvertUrlToLowercaseBeforeComparison(boolean convertUrlToLowercaseBeforeComparison) {
|
||||
this.convertUrlToLowercaseBeforeComparison = convertUrlToLowercaseBeforeComparison;
|
||||
}
|
||||
|
||||
List getRequestMap() {
|
||||
return requestMap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,22 +49,18 @@ public class PathBasedFilterInvocationDefinitionMap extends AbstractFilterInvoca
|
||||
|
||||
private static final Log logger = LogFactory.getLog(PathBasedFilterInvocationDefinitionMap.class);
|
||||
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private List requestMap = new Vector();
|
||||
private PathMatcher pathMatcher = new AntPathMatcher();
|
||||
private boolean convertUrlToLowercaseBeforeComparison = false;
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void addSecureUrl(String antPath, ConfigAttributeDefinition attr) {
|
||||
// SEC-501: If using lower case comparison, we should convert the paths to lower case
|
||||
// as any upper case characters included by mistake will prevent the URL from ever being matched.
|
||||
if (convertUrlToLowercaseBeforeComparison) {
|
||||
if (isConvertUrlToLowercaseBeforeComparison()) {
|
||||
antPath = antPath.toLowerCase();
|
||||
}
|
||||
|
||||
requestMap.add(new EntryHolder(antPath, attr));
|
||||
getRequestMap().add(new EntryHolder(antPath, attr));
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Added Ant path: " + antPath + "; attributes: " + attr);
|
||||
@@ -73,7 +69,7 @@ public class PathBasedFilterInvocationDefinitionMap extends AbstractFilterInvoca
|
||||
|
||||
public Iterator getConfigAttributeDefinitions() {
|
||||
Set set = new HashSet();
|
||||
Iterator iter = requestMap.iterator();
|
||||
Iterator iter = getRequestMap().iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
EntryHolder entryHolder = (EntryHolder) iter.next();
|
||||
@@ -83,14 +79,6 @@ public class PathBasedFilterInvocationDefinitionMap extends AbstractFilterInvoca
|
||||
return set.iterator();
|
||||
}
|
||||
|
||||
public int getMapSize() {
|
||||
return this.requestMap.size();
|
||||
}
|
||||
|
||||
public boolean isConvertUrlToLowercaseBeforeComparison() {
|
||||
return convertUrlToLowercaseBeforeComparison;
|
||||
}
|
||||
|
||||
public ConfigAttributeDefinition lookupAttributes(String url) {
|
||||
// Strip anything after a question mark symbol, as per SEC-161. See also SEC-321
|
||||
int firstQuestionMarkIndex = url.indexOf("?");
|
||||
@@ -127,14 +115,6 @@ public class PathBasedFilterInvocationDefinitionMap extends AbstractFilterInvoca
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setConvertUrlToLowercaseBeforeComparison(boolean convertUrlToLowercaseBeforeComparison) {
|
||||
this.convertUrlToLowercaseBeforeComparison = convertUrlToLowercaseBeforeComparison;
|
||||
}
|
||||
|
||||
List getRequestMap() {
|
||||
return requestMap;
|
||||
}
|
||||
|
||||
//~ Inner Classes ==================================================================================================
|
||||
|
||||
protected class EntryHolder {
|
||||
|
||||
@@ -46,17 +46,12 @@ public class RegExpBasedFilterInvocationDefinitionMap extends AbstractFilterInvo
|
||||
|
||||
private static final Log logger = LogFactory.getLog(RegExpBasedFilterInvocationDefinitionMap.class);
|
||||
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private List requestMap = new Vector();
|
||||
private boolean convertUrlToLowercaseBeforeComparison = false;
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void addSecureUrl(String regExp, ConfigAttributeDefinition attr) {
|
||||
Pattern pattern = Pattern.compile(regExp);
|
||||
|
||||
requestMap.add(new EntryHolder(pattern, attr));
|
||||
getRequestMap().add(new EntryHolder(pattern, attr));
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Added regular expression: " + regExp + "; attributes: " + attr);
|
||||
@@ -65,7 +60,7 @@ public class RegExpBasedFilterInvocationDefinitionMap extends AbstractFilterInvo
|
||||
|
||||
public Iterator getConfigAttributeDefinitions() {
|
||||
Set set = new HashSet();
|
||||
Iterator iter = requestMap.iterator();
|
||||
Iterator iter = getRequestMap().iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
EntryHolder entryHolder = (EntryHolder) iter.next();
|
||||
@@ -75,16 +70,8 @@ public class RegExpBasedFilterInvocationDefinitionMap extends AbstractFilterInvo
|
||||
return set.iterator();
|
||||
}
|
||||
|
||||
public int getMapSize() {
|
||||
return this.requestMap.size();
|
||||
}
|
||||
|
||||
public boolean isConvertUrlToLowercaseBeforeComparison() {
|
||||
return convertUrlToLowercaseBeforeComparison;
|
||||
}
|
||||
|
||||
public ConfigAttributeDefinition lookupAttributes(String url) {
|
||||
Iterator iter = requestMap.iterator();
|
||||
Iterator iter = getRequestMap().iterator();
|
||||
|
||||
if (isConvertUrlToLowercaseBeforeComparison()) {
|
||||
url = url.toLowerCase();
|
||||
@@ -114,14 +101,6 @@ public class RegExpBasedFilterInvocationDefinitionMap extends AbstractFilterInvo
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setConvertUrlToLowercaseBeforeComparison(boolean convertUrlToLowercaseBeforeComparison) {
|
||||
this.convertUrlToLowercaseBeforeComparison = convertUrlToLowercaseBeforeComparison;
|
||||
}
|
||||
|
||||
List getRequestMap() {
|
||||
return requestMap;
|
||||
}
|
||||
|
||||
//~ Inner Classes ==================================================================================================
|
||||
|
||||
protected class EntryHolder {
|
||||
|
||||
Reference in New Issue
Block a user