DelegatingFilterProxy干了什么?
org.springframework.web.filter.DelegatingFilterProxy
一般情况,创建一个Filter是交给自己来实现的。基于servlet规范,在web.xml中配置,自定义filter实现Filter接口:
public interface Filter {
void init(FilterConfig var1) throws ServletException;
void doFilter(ServletRequest var1, ServletResponse var2, FilterChain var3) throws IOException, ServletException;
void destroy();
}
但是从shiro的操作方式来看,这个反过来了:spring提供了DelegatingFilterProxy作为通用Filter代理类,shiro以factoryBean的形式来构造自己的filter。
那么这个DelegatingFilterProxy究竟干了些什么?
- 利用初始化方法获取被代理的对象delegate
protected Filter initDelegate(WebApplicationContext wac) throws ServletException {
Filter delegate = wac.getBean(getTargetBeanName(), Filter.class);
if (isTargetFilterLifecycle()) {
delegate.init(getFilterConfig());
}
return delegate;
}
- 通过doFilter方法来调用目标过滤器的doFilter方法
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
// Lazily initialize the delegate if necessary.
Filter delegateToUse = this.delegate;
if (delegateToUse == null) {
synchronized (this.delegateMonitor) {
if (this.delegate == null) {
WebApplicationContext wac = findWebApplicationContext();
if (wac == null) {
throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?");
}
this.delegate = initDelegate(wac);
}
delegateToUse = this.delegate;
}
}
// Let the delegate perform the actual doFilter operation.
invokeDelegate(delegateToUse, request, response, filterChain);
}
protected void invokeDelegate(
Filter delegate, ServletRequest request, ServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
delegate.doFilter(request, response, filterChain);
}
- 通过destory方法来释放一些资源
@Override
public void destroy() {
Filter delegateToUse = this.delegate;
if (delegateToUse != null) {
destroyDelegate(delegateToUse);
}
}
protected void destroyDelegate(Filter delegate) {
if (isTargetFilterLifecycle()) {
delegate.destroy();
}
}
这个三个操作就完全将详细的实现转移到被代理的Filter。因为spring是所有bean的容器,这个filter的实际创建就交给了其它框架,但是前提是,这些框架必须要实现FactoryBean接口。所以有了shiro的ShiroFilterFactoryBean(springSecurity原理应该跟这个差不多)。
DelegatingFilterProxy干了什么?的更多相关文章
- 简述9种社交概念 SNS究竟用来干嘛?
1.QQ 必备型交流工具基本上每一个网民最少有一个QQ,QQ已经成为网民的标配,网络生活中已经离不开QQ了.虽然大家嘴上一直在骂 QQ这个不好,那个不对,但是很少有人能彻底离开QQ.QQ属于IM软件, ...
- Stored Procedure 里的 WITH RECOMPILE 到底是干麻的?
在 SQL Server 创建或修改「存储过程(stored procedure)」时,可加上 WITH RECOMPILE 选项,但多数文档或书籍都写得语焉不详,或只解释为「每次执行此存储过程时,都 ...
- 【单页应用】全局控制器app应该干些什么?
前言 之前,我们形成了页面片相关的mvc结构,但是该结构还仅适用于view(页面)级,那么真正的全局控制器app应该干些什么事情呢?我觉得至少需要干这些: 功能点 ① 提供URL解析机制,以便让控制器 ...
- META-INF文件夹是干啥的,META-INF文件夹的作用, META-INF文件夹能删吗
今天有人问到 META-INF文件夹是干啥的,META-INF文件夹的作用, META-INF文件夹能删吗,还有项目的META-INF下面一般会有个MANIFEST.MF 文件,都是干啥的. 百度搜了 ...
- 配置DelegatingFilterProxy使用Spring管理filter chain
项目环境:JDK7 + Maven3.04 0. 项目使用springmvc作为controller层 1. 引入spring-security <dependency> <grou ...
- 在指定时间干,必须干(kbmmw 中的事件调度)
从去年开始,kbmmw 慢慢增加内涵,除了完善各种服务外,陆续增加和扩展了作为一个中间件必须有的功能, 例如,权限管理.日志系统.调度系统.内存调试等功能. 今天给大家介绍一下kbmmw 的调度事件, ...
- Team Leader炖完石头汤后干嘛
在万众创业的互联网年代,挖人组建全明星团队过于奢侈.面对水平参差不齐的团队咋办? 命运真是捉弄,半年前在大美团打工时准备做个NABC的教学项目 ,结果自己就被挖到"Competitors 竞 ...
- 好好写,好好干-PHP基础(二)
hi 好久没写,昨儿一写,感觉还是有人看的,至少是有一两个评论的~~好好干! 每天需要坚持的就那么4件事儿:写这个,学一点法语,看会儿书,锻炼.单身狗也有好处. 1.PHP 一.PHP基础(二) 1. ...
- Spring MVC过滤器-委派过滤器代理(DelegatingFilterProxy)
org.springframework.web.filter中有一个特殊的类——DelegatingFilterProxy,该类其实并不能说是一个过滤器,它的原型是FilterToBeanProxy, ...
随机推荐
- 深入HBase架构解析(一)
前记 公司内部使用的是MapR版本的Hadoop生态系统,因而从MapR的官网看到了这篇文文章:An In-Depth Look at the HBase Architecture,原本想翻译全文,然 ...
- 【CodeForces】896 B. Ithea Plays With Chtholly
[题目]B. Ithea Plays With Chtholly [题意]交互题,有n格,每次给一个[1,c]的数字,回答填入的位置后再次给数字,要求在m轮内使n格填满且数列不递减.n,m>=2 ...
- centos_7.1.1503_src_5
http://vault.centos.org/7.1.1503/os/Source/SPackages/ minicom-2.6.2-5.el7.src.rpm 05-Jul-2014 13:50 ...
- 从LFS官方文档构建完整Linux系统
从LFS官方文档构建完整Linux系统 http://www.cnblogs.com/sonofdark/p/4962609.html 这不是新手教程!!! Parallels Desktop (为防 ...
- 【COGS2622】后缀平衡树
这是个后缀平衡树的裸题.... 然后傻逼的我调了一下午. #include<bits/stdc++.h> typedef long long ll; using namespace std ...
- 【POJ2420】A star not a tree?
蒟蒻开始学模拟退火…… 起初一直不肯学,因为毕竟玄学算法…… 哎呀玄学怎么就没用呢?对不对? #include<iostream> #include<cstdio> #incl ...
- 设计模式之笔记--抽象工厂模式(Abstract Factory)
抽象工厂模式(Abstract Factory) 定义 抽象工厂模式(Abstract Factory),提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类. 类图 描述 多个抽象产品 ...
- C++中多线程与Singleton的那些事儿
前言 前段时间在网上看到了个的面试题,大概意思是如何在不使用锁和C++11的情况下,用C++实现线程安全的Singleton. 看到这个题目后,第一个想法就是用Scott Meyer在<Effe ...
- git学习笔记三
1.每个分支的历史版本维护信息位置是.git/logs/refs/heads/master,这个位置的信息是文本文件,不是引用. harvey@harvey-Virtual-Machine:~/dem ...
- App推广
一行业常见名词解释 开发商:也叫CP,即Content Provider内容提供商的英文首字母缩写. 发行商(运营商):即代理CP开发出来的产品. 渠道:拥有用户,能够进行流量分发的公司,即可成为渠道 ...