Shiro源码学习之ShiroFilter
来源:互联网 发布:js连接mysql数据库 编辑:程序博客网 时间:2024/06/07 20:12
一、shiroFilter的继承关系
二、接口说明
1、ServletContextSupport :封装了一个ServletContext
2、Filter 接口
public
interface
Filter {
void
init(FilterConfig filterConfig)
throws
ServletException;
void
doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws
IOException, ServletException;
void
destroy();
}
3、AbstractFilter
AbstractFilter extends ServletContextSupport implements Filter
它实现了init方法,将ServletContext赋值给了ServletContextSupport ,同时提供了onFilterConfigSet方法让子类实现,可以让子类在过滤器初始化的时候做些事情
4、Nameable接口
public interface Nameable {
void setName(String name);
}
5、NameableFilter
用于给过滤器设置一个名词,默认为配置文件中的名称
6、OncePerRequestFilter:防止重复使用相同名字(这里的名字从NameableFilter中获取)的过滤器,他实现了Filter的 doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)方法,同时提供了doFilterInternal方法让子类继承,以便在过滤请求的时候能够让子类实现自己的操作
主要方法:
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
String alreadyFilteredAttributeName = getAlreadyFilteredAttributeName();
if ( request.getAttribute(alreadyFilteredAttributeName) != null ) {
log.trace("Filter '{}' already executed. Proceeding without invoking this filter.", getName());
filterChain.doFilter(request, response);
} else //noinspection deprecation
if (!isEnabled(request, response) ||
shouldNotFilter(request) ) {
log.debug("Filter '{}' is not enabled for the current request. Proceeding without invoking this filter.",
getName());
filterChain.doFilter(request, response);
} else {
log.trace("Filter '{}' not yet executed. Executing now.", getName());
request.setAttribute(alreadyFilteredAttributeName, Boolean.TRUE);
try {
doFilterInternal(request, response, filterChain);
} finally {
// Once the request has finished, we're done and we don't
// need to mark as 'already filtered' any more.
request.removeAttribute(alreadyFilteredAttributeName);
}
}
}
7、AbstractShiroFilter
该接口封装了WebSecurityManager securityManager与FilterChainResolver filterChainResolver;,实现了onFilterConfigSet方法,调用了init()方法,该方法子类可覆盖,做些事情,然后确保了securityManager的存在。实现了doFilterInternal方法,在访问请求拦截的时候,将原来的FilterChain代理成立了ProxiedFilterChain,然后进行我们配置的过滤器处理
8、ShiroFilter
覆盖了父类AbstractShiroFilter的init方法,将环境变量中的securityManager与filterChainResolver赋值给AbstractShiroFilter中相应的对象
- Shiro源码学习之ShiroFilter
- shiro源码分析之shiroFilter初始化过程
- Shiro系列教程ShiroFilter源码分析
- Shiro 之 Filter(上):ShiroFilter
- Shiro 3 shiroFilter
- Shiro源码学习之二
- 【解决】SpringMVC整合Shiro之 Error creating bean with name 'shiroFilter' defined in class path resource...
- Shiro源码学习之一
- Shiro源码之SecurityManager
- ShiroFilter
- Shiro源码研究之ShiroFilterFactoryBean
- Shiro学习之身份验证
- Shiro学习之HelloWord
- Shiro学习之JdbcRealm
- Shiro在Web.xml中shiroFilter的Mapping配置错误
- apache shiro在加载shiroFilter时报BeanCurrentlyInCreationException异常
- Shiro学习之权限认证
- Apache Shiro学习(2)--源码分析
- Mybatis 示例之 TypeHandler
- java基础之 JDBC、DBUtils
- 监控摄像头主动应用一例
- 二、Oracle12c中的CDB与PDB
- ListView实现分页功能
- Shiro源码学习之ShiroFilter
- MVC三层模(struts+spring+hibernate(SSH)总结
- 实现图像处理算法中采用策略“Strategy”模式+Qt中相对路径
- 九度OJ题目1031:xxx定律
- (十三)装饰模式
- linux 信号发送简单用法
- 机器视觉代码大全
- SSH是怎么分工的
- 分支管理---创建与合并分支