SEC-578: Removed FilterChainMap class

This commit is contained in:
Luke Taylor 2007-10-25 11:51:51 +00:00
parent fb72fa82de
commit 7ef57c67ed
3 changed files with 4 additions and 115 deletions

View File

@ -1,6 +1,5 @@
package org.springframework.security.config; package org.springframework.security.config;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.config.RuntimeBeanReference;
@ -8,9 +7,6 @@ import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.xml.BeanDefinitionDecorator; import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
import org.springframework.beans.factory.xml.ParserContext; import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.security.intercept.web.FilterChainMap;
import org.springframework.security.util.RegexUrlPathMatcher; import org.springframework.security.util.RegexUrlPathMatcher;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -26,7 +22,7 @@ import java.util.*;
* @author Luke Taylor * @author Luke Taylor
* @version $Id$ * @version $Id$
*/ */
public class FilterChainMapBeanDefinitionDecorator implements BeanDefinitionDecorator { class FilterChainMapBeanDefinitionDecorator implements BeanDefinitionDecorator {
public static final String FILTER_CHAIN_ELT_NAME = "filter-chain"; public static final String FILTER_CHAIN_ELT_NAME = "filter-chain";
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder holder, ParserContext parserContext) { public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder holder, ParserContext parserContext) {

View File

@ -1,107 +0,0 @@
package org.springframework.security.intercept.web;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.util.AntUrlPathMatcher;
import org.springframework.security.util.UrlMatcher;
import org.springframework.util.Assert;
import javax.servlet.Filter;
import java.util.*;
/**
* Maps filter invocations to filter chains. Used to configure FilterChainProxy.
*
* @see org.springframework.security.util.FilterChainProxy
*
* @author luke
* @version $Id$
* @since 2.0
*/
public class FilterChainMap implements InitializingBean {
private static final Log logger = LogFactory.getLog(FilterChainMap.class);
private List paths = new ArrayList();
private List compiledPaths = new ArrayList();
private List filterChains = new ArrayList();
private UrlMatcher matcher = new AntUrlPathMatcher();
public FilterChainMap() {
}
public void afterPropertiesSet() throws Exception {
Assert.notEmpty(paths, "No secure URL paths defined");
}
public void addSecureUrl(String path, Filter[] filters) {
Assert.hasText(path, "The Path must not be empty or null");
Assert.notNull(filters, "The Filter array must not be null");
paths.add(path);
compiledPaths.add(matcher.compile(path));
filterChains.add(filters);
if (logger.isDebugEnabled()) {
logger.debug("Added pattern: " + path + "; filters: " + Arrays.asList(filters));
}
}
public void setUrlPathMatcher(UrlMatcher matcher) {
this.matcher = matcher;
}
public UrlMatcher getMatcher() {
return matcher;
}
/**
* Returns the first filter chain matching the supplied URL.
*
* @param url the request URL
* @return an ordered array of Filters defining the filter chain
*/
public Filter[] getFilters(String url) {
for (int i=0; i < compiledPaths.size(); i++) {
Object path = compiledPaths.get(i);
boolean matched = matcher.pathMatchesUrl(path, url);
if (logger.isDebugEnabled()) {
logger.debug("Candidate is: '" + url + "'; pattern is " + paths.get(i) + "; matched=" + matched);
}
if (matched) {
return (Filter[]) filterChains.get(i);
}
}
return null;
}
/**
* Obtains all of the <b>unique</b><code>Filter</code> instances registered in the
* <code>FilterChainMap</code>.
* <p>This is useful in ensuring a <code>Filter</code> is not
* initialized or destroyed twice.</p>
* @return all of the <code>Filter</code> instances which have an entry
* in the <code>FilterChainMap</code> (only one entry is included in the array for
* each <code>Filter</code> instance, even if a given
* <code>Filter</code> is used multiples times by the <code>FilterChainMap</code>)
*/
public Filter[] getAllDefinedFilters() {
Set allFilters = new HashSet();
Iterator it = filterChains.iterator();
while (it.hasNext()) {
Filter[] filterChain = (Filter[])it.next();
for(int i=0; i < filterChain.length; i++) {
allFilters.add(filterChain[i]);
}
}
return (Filter[]) new ArrayList(allFilters).toArray(new Filter[0]);
}
}

View File

@ -112,11 +112,11 @@ public class FilterChainProxy implements Filter, InitializingBean, ApplicationCo
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
// Convert the FilterDefinitionSource to a filterChainMap if set // Convert the FilterDefinitionSource to a filterChainMap if set
if (fids != null) { if (fids != null) {
Assert.isNull(uncompiledFilterChainMap, "Set the FilterChainMap or FilterInvocationDefinitionSource but not both"); Assert.isNull(uncompiledFilterChainMap, "Set the filterChainMap or FilterInvocationDefinitionSource but not both");
setFilterChainMap(new FIDSToFilterChainMapConverter(fids, applicationContext).getFilterChainMap()); setFilterChainMap(new FIDSToFilterChainMapConverter(fids, applicationContext).getFilterChainMap());
} }
Assert.notNull(uncompiledFilterChainMap, "A FilterChainMap must be supplied"); Assert.notNull(uncompiledFilterChainMap, "filterChainMap must be set");
} }
public void init(FilterConfig filterConfig) throws ServletException { public void init(FilterConfig filterConfig) throws ServletException {
@ -204,7 +204,7 @@ public class FilterChainProxy implements Filter, InitializingBean, ApplicationCo
* @return all of the <code>Filter</code> instances in the application context which have an entry * @return all of the <code>Filter</code> instances in the application context which have an entry
* in the map (only one entry is included in the array for * in the map (only one entry is included in the array for
* each <code>Filter</code> that actually exists in application context, even if a given * each <code>Filter</code> that actually exists in application context, even if a given
* <code>Filter</code> is defined multiples times by the <code>FilterChainMap</code>) * <code>Filter</code> is defined multiples times in the filter chain map)
*/ */
protected Filter[] obtainAllDefinedFilters() { protected Filter[] obtainAllDefinedFilters() {
Set allFilters = new HashSet(); Set allFilters = new HashSet();