我的shiro之旅: 三 浅谈shiro的filter
来源:互联网 发布:剑网三卡卢比捏脸数据 编辑:程序博客网 时间:2024/05/18 05:43
前段时间比较懒,项目也有些紧,没有写什么东西。现在再对Shiro做一些整理。上一篇主要介绍了一个完整而又简单的shiro集成到项目的例子,主要是spring项目。这篇文章,想谈一下关于shiro的filter,这需要读者对shiro有一定的理解,至少有用过shiro。
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"><property name="securityManager" ref="securityManager" /><property name="loginUrl" value="/login" /><property name="successUrl" value="/home" /><property name="unauthorizedUrl" value="/unauthorized" /><!-- The 'filters' property is usually not necessary unless performing an override, which we want to do here (make authc point to a PassthruAuthenticationFilter instead of the default FormAuthenticationFilter: --><!-- <property name="filters"><map><entry key="authc"><bean class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter" /></entry></map></property> --><property name="filterChainDefinitions"><value>/admin = authc,roles[admin]/edit = authc,perms[admin:edit]/home = user/** = anon</value></property></bean>
从上面的配置我们可以看到,当用户没有登录的时候,会重发一个login请求,引导用户去登录。当然,这个login请求做些什么工作,引导用户去那里,完全由开发者决定。successUrl是当用户登录成功,重发home请求,引导用户到主页。unauthorizedUrl指如果请求失败,重发/unauthorized请求,引导用户到认证异常错误页面。
Filter NameClassanonorg.apache.shiro.web.filter.authc.AnonymousFilterauthcorg.apache.shiro.web.filter.authc.FormAuthenticationFilterauthcBasicorg.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilterlogoutorg.apache.shiro.web.filter.authc.LogoutFilternoSessionCreationorg.apache.shiro.web.filter.session.NoSessionCreationFilterpermsorg.apache.shiro.web.filter.authz.PermissionsAuthorizationFilterportorg.apache.shiro.web.filter.authz.PortFilterrestorg.apache.shiro.web.filter.authz.HttpMethodPermissionFilterrolesorg.apache.shiro.web.filter.authz.RolesAuthorizationFiltersslorg.apache.shiro.web.filter.authz.SslFilteruserorg.apache.shiro.web.filter.authc.UserFilter以上是shiro的一些Filter,如我们在filterChainDefinitions里配置了/admin=authc,roles[admin],那么/admin这个请求会由org.apache.shiro.web.filter.authc.FormAuthenticationFilter和org.apache.shiro.web.filter.authz.RolesAuthorizationFilter这两个filter来处理,其中authc,roles只是filter的别名。如要更改别名,可以通过filters来改变。如上面的配置
<property name="filters"><map><entry key="authc"><bean class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter" /></entry></map></property>把PassThruAuthenticationFilter添加别名为authc,这时/admin请求会交给PassThruAuthenticationFilter处理,替换了原来由FormAuthenticationFilter来处理。
由此一来,如果有些特殊的请求需要特殊处理,就可以自己写一个filter,添加一个别名,如:
<property name="filters"><map><entry key="new"><bean class="org.xx.xx.NewFilter" /></entry></map></property>请求用/new = new,这样/new请求交由NewFilter来处理。
- 我的shiro之旅: 三 浅谈shiro的filter
- 我的shiro之旅:自定义filter
- 我的shiro之旅: 四 自定义filter
- 我的shiro之旅: 六 自定义shiro的sessionId
- 我的shiro之旅: 十 自定义shiro的SessionIdCookie
- 我的shiro之旅: 十一 shiro的权限设计
- 我的shiro之旅: 一 shiro简介
- 我的shiro之旅: 七 shiro session 共享
- 我的shiro之旅: 十四 shiro 自动登录
- 我的shiro之旅: 十四 shiro 自动登录
- shiro filter的入口
- 我的shiro之旅-realm
- shiro讲解之 Shiro Filter
- shiro 认证filter 的原理
- Shiro添加自己的Filter
- 我的shiro之旅: 二 让Shiro保护你的应用
- 我的shiro之旅: 八 shiro session 共享的进一步
- 我的shiro之旅: 九 shiro 清理缓存的权限信息
- 五大常用算法之四:回溯法
- AD0错误:0x80040e14 在sysservers中找不到服务器QPGameUserDBLink
- MFC内结构结构体定义
- hdu 状态压缩dp小集(中低难度)
- zencart DPS payment gateway在哪里
- 我的shiro之旅: 三 浅谈shiro的filter
- 在线程里面要改变主进程的一个值,并通知主进程(如进度条),以及资源占用自动延时
- Android界面设计之:使用水平视图切换
- Android系统Surface机制的SurfaceFlinger服务对帧缓冲区(Frame Buffer)的管理分析
- xcode运行模拟器时弹出密码输入框之解决方案
- 五大常用算法之五:分支限界法
- 今天开始学习python
- CLR无法从COM 上下文*****转换为COM上下文*****,这种状态已持续60秒。
- 设置读取失败