Shiro:DelegatingFilterProxy
来源:互联网 发布:照片批量修改大小软件 编辑:程序博客网 时间:2024/05/24 03:23
用途和意义
回忆一下quickStart中的配置过程不难得出结论,shiro的核心配置应当位于Spring的applicationContext中的id为shiroFilter的bean。但我们在web.xml中还有一个name为shiroFilter的Filter的配置,它的类型是org.springframework.web.filter.DelegatingFilterProxy。
DelegatingFilterProxy的作用是:到spring容器中查找与该filter相应的filter(也就是同名)的bean。
这个作用带来的意义是,如果我们使用的不是shiro过滤器,而是其他的安全框架,那么,只需要在spring容器中配置相应的filter即可,降低了代码的耦合性。
接下来我们查看一下源码,以便了解其原理。该类继承GenericFilterBean。有几个私有属性:
//即将获取的shiro核心过滤器的id的值,如果该值没有指定 private String targetBeanName; private boolean targetFilterLifecycle; //获取的spring中shiro核心过滤器bean实例 private volatile Filter delegate;
Filter初始化方法:
protected void initFilterBean() throws ServletException { Object var1 = this.delegateMonitor; synchronized(this.delegateMonitor) { if (this.delegate == null) { //如果targetBeanName没有指定,则调用getFilterName方法 if (this.targetBeanName == null) { this.targetBeanName = this.getFilterName(); } //此处获取webApplicationContext WebApplicationContext wac = this.findWebApplicationContext(); if (wac != null) { this.delegate = this.initDelegate(wac); } } } }
getFilterName方法:
protected final String getFilterName() {//查看是否拥有filter相关配置,如果有,那么将filter的name作为作为beanName值 return this.filterConfig != null ? this.filterConfig.getFilterName() : this.beanName; }
由于targetBeanName是一个初始化参数,因而,在web.xml中使用filter的init-param来指定也是可以的。
protected Filter initDelegate(WebApplicationContext wac) throws ServletException { //反射方式获取filter实例 Filter delegate = (Filter)wac.getBean(this.getTargetBeanName(), Filter.class); if (this.isTargetFilterLifecycle()) { delegate.init(this.getFilterConfig()); } return delegate; }
阅读全文
0 0
- Shiro:DelegatingFilterProxy
- DelegatingFilterProxy
- .DelegatingFilterProxy
- DelegatingFilterProxy
- DelegatingFilterProxy
- DelegatingFilterProxy
- DelegatingFilterProxy
- DelegatingFilterProxy
- DelegatingFilterProxy
- shiro与spring整合之DelegatingFilterProxy源码解析
- DelegatingFilterProxy-api
- DelegatingFilterProxy详解
- DelegatingFilterProxy【转】
- DelegatingFilterProxy【转】
- DelegatingFilterProxy【转】
- Spring DelegatingFilterProxy
- Spring-DelegatingFilterProxy
- DelegatingFilterProxy(转)
- PAT (Basic Level) Practise (中文)1028. 人口普查(20)
- shiro的quick-start
- Material Design控件之TabLayout
- 指针初学,简单应用
- Spring中的自定义事件
- Shiro:DelegatingFilterProxy
- 简单的长连接
- Docker-CE-1
- Android Studio SVN使用指南之文件颜色
- 最新最详细明白的unity3d 和sharesdk 进行登录分享使用过程
- hdu1596 find the safest road
- STM32(RFID)阶段二(读序列,修改金额)
- javaWeb(3)
- java web图片上传和文件上传实例