这个类有两个成员变量
private PatternMatcher pathMatcher = new AntPathMatcher();
private FilterChainManager filterChainManager;
filterChainManager是由上文创建的,pathMatcher 是用于匹配路径的。
核心方法是getChain(ServletRequest request, ServletResponse response, FilterChain originalChain) ;
作用是为每一个request分配给它对应的filter链。
原版中只要匹配到一个链接链就结束了,这里我改成匹配所有拦截链,合并filter。
这个方法返回的是ProxiedFilterChain的实例。
@Override
public FilterChain getChain(ServletRequest request, ServletResponse response, FilterChain originalChain) {
FilterChainManager filterChainManager = this.getFilterChainManager();
if(!filterChainManager.hasChains()) {
return null;
} else {
String requestURI = this.getPathWithinApplication(request);
Iterator var6 = filterChainManager.getChainNames().iterator();
String pathPattern;
Set<String> paths=null;
while (var6.hasNext()){
pathPattern = (String)var6.next();
if (this.pathMatches(pathPattern, requestURI)){
if (paths==null)
paths=new HashSet<>();
paths.add(pathPattern);
}
}
// do {
// if(!var6.hasNext()) {
// return null;
// }
// pathPattern = (String)var6.next();
// } while(!this.pathMatches(pathPattern, requestURI));
if (paths==null)
return null;
return filterChainManager.proxy(originalChain, paths);
}
}