spring中 shiro logout 配置方式
2016-08-05 14:56
260 查看
有两种方式实现logout
1. 普通的action中 实现自己的logout方法,取到Subject,然后logout
这种需要在ShiroFilterFactoryBean 中配置 filterChainDefinitions
对应的action的url为anon
<property name="filterChainDefinitions">
<value>
# some example chain definitions:
/index.htm = anon
/logout = anon
/unauthed = anon
/console/** = anon
/css/** = anon
/js/** = anon
/lib/** = anon
/admin/** = authc, roles[admin]
/docs/** = authc, perms[document:read]
/** = authc
# more URL-to-FilterChain definitions here
</value>
2. 使用shiro提供的logout filter
需要定义 相应的bean
<bean id="logout" class="org.apache.shiro.web.filter.authc.LogoutFilter">
<property name="redirectUrl" value="/loginform" />
</bean>
然后将相应的url filter配置为logout如下
<property name="filterChainDefinitions">
<value>
# some example chain definitions:
/index.htm = anon
/logout = logout
/unauthed = anon
/console/** = anon
/css/** = anon
/js/** = anon
/lib/** = anon
/admin/** = authc, roles[admin]
/docs/** = authc, perms[document:read]
/** = authc
# more URL-to-FilterChain definitions here
</value>
注:anon,authcBasic,auchc,user是认证过滤器,perms,roles,ssl,rest,port是授权过滤器
关于自定义filter
分类: shiro | 标签: shiro | 作者: lhacker 相关 | 发布日期
: 2014-11-29 | 热度 : 63°
前段时间比较懒,项目也有些紧,没有写什么东西。现在再对Shiro做一些整理。上一篇主要介绍了一个完整而又简单的shiro集成到项目的例子,主要是spring项目。这篇文章,想谈一下关于shiro的filter,这需要读者对shiro有一定的理解,至少有用过shiro。
从上面的配置我们可以看到,当用户没有登录的时候,会重发一个login请求,引导用户去登录。当然,这个login请求做些什么工作,引导用户去那里,完全由开发者决定。successUrl是当用户登录成功,重发home请求,引导用户到主页。unauthorizedUrl指如果请求失败,重发/unauthorized请求,引导用户到认证异常错误页面。
以上是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来改变。如上面的配置
把PassThruAuthenticationFilter添加别名为authc,这时/admin请求会交给PassThruAuthenticationFilter处理,替换了原来由FormAuthenticationFilter来处理。
由此一来,如果有些特殊的请求需要特殊处理,就可以自己写一个filter,添加一个别名,如:
view
source
print?
请求用/new = new,这样/new请求交由NewFilter来处理。
1. 普通的action中 实现自己的logout方法,取到Subject,然后logout
这种需要在ShiroFilterFactoryBean 中配置 filterChainDefinitions
对应的action的url为anon
<property name="filterChainDefinitions">
<value>
# some example chain definitions:
/index.htm = anon
/logout = anon
/unauthed = anon
/console/** = anon
/css/** = anon
/js/** = anon
/lib/** = anon
/admin/** = authc, roles[admin]
/docs/** = authc, perms[document:read]
/** = authc
# more URL-to-FilterChain definitions here
</value>
2. 使用shiro提供的logout filter
需要定义 相应的bean
<bean id="logout" class="org.apache.shiro.web.filter.authc.LogoutFilter">
<property name="redirectUrl" value="/loginform" />
</bean>
然后将相应的url filter配置为logout如下
<property name="filterChainDefinitions">
<value>
# some example chain definitions:
/index.htm = anon
/logout = logout
/unauthed = anon
/console/** = anon
/css/** = anon
/js/** = anon
/lib/** = anon
/admin/** = authc, roles[admin]
/docs/** = authc, perms[document:read]
/** = authc
# more URL-to-FilterChain definitions here
</value>
注:anon,authcBasic,auchc,user是认证过滤器,perms,roles,ssl,rest,port是授权过滤器
关于自定义filter
我的shiro之旅: 三 浅谈shiro的filter
分类: shiro | 标签: shiro | 作者: lhacker 相关 | 发布日期: 2014-11-29 | 热度 : 63°
前段时间比较懒,项目也有些紧,没有写什么东西。现在再对Shiro做一些整理。上一篇主要介绍了一个完整而又简单的shiro集成到项目的例子,主要是spring项目。这篇文章,想谈一下关于shiro的filter,这需要读者对shiro有一定的理解,至少有用过shiro。
01 | < bean id = "shiroFilter" class = "org.apache.shiro.spring.web.ShiroFilterFactoryBean" > |
02 | < property name = "securityManager" ref = "securityManager" /> |
03 | < property name = "loginUrl" value = "/login" /> |
04 | < property name = "successUrl" value = "/home" /> |
05 | < property name = "unauthorizedUrl" value = "/unauthorized" /> |
06 | <!-- The 'filters' property is usually not necessary unless performing |
07 | an override, which we want to do here (make authc point to a PassthruAuthenticationFilter |
08 | instead of the default FormAuthenticationFilter: --> |
09 | <!-- <property name="filters"> |
10 | <map> |
11 | <entry key="authc"> |
12 | <bean class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter" /> |
13 | </entry> |
14 | </map> |
15 | </property> --> |
16 | < property name = "filterChainDefinitions" > |
17 | < value > |
18 | /admin = authc,roles[admin] |
19 | /edit = authc,perms[admin:edit] |
20 | /home = user |
21 | /** = anon |
22 | </ value > |
23 | </ property > |
24 | </ bean > |
Filter Name | Class |
anon | org.apache.shiro.web.filter.authc.AnonymousFilter |
authc | org.apache.shiro.web.filter.authc.FormAuthenticationFilter |
authcBasic | org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter |
logout | org.apache.shiro.web.filter.authc.LogoutFilter |
noSessionCreation | org.apache.shiro.web.filter.session.NoSessionCreationFilter |
perms | org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter |
port | org.apache.shiro.web.filter.authz.PortFilter |
rest | org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter |
roles | org.apache.shiro.web.filter.authz.RolesAuthorizationFilter |
ssl | org.apache.shiro.web.filter.authz.SslFilter |
user | org.apache.shiro.web.filter.authc.UserFilter |
1 | < span style = "white-space:pre" > </ span >< property name = "filters" > |
2 | < map > |
3 | < entry key = "authc" > |
4 | < bean class = "org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter" /> |
5 | </ entry > |
6 | </ map > |
7 | </ property > |
由此一来,如果有些特殊的请求需要特殊处理,就可以自己写一个filter,添加一个别名,如:
view
source
print?
1 | < span style = "white-space:pre" > </ span >< property name = "filters" > |
2 | < map > |
3 | < entry key = "new" > |
4 | < bean class = "org.xx.xx.NewFilter" /> |
5 | </ entry > |
6 | </ map > |
7 | </ property > |
相关文章推荐
- Angularjs 跨域请求
- Apache Shiro 使用手册(一) Shiro架构介绍
- Apache Shiro 使用手册(二) Shiro 认证
- Apache Shiro 使用手册(五) Shiro 配置说明
- Apache Shiro 使用手册(四) Realm 实现
- 详解Spring Boot 集成Shiro和CAS
- 让Apache Shiro保护你的应用
- 基于Spring框架的Shiro配置方法
- spring boot 1.5.4 集成shiro+cas,实现单点登录和权限控制
- 使用Shiro实现登录成功后跳转到之前的页面
- Shiro 控制并发登录人数限制及登录踢出的实现代码
- Shiro 整合 SpringMVC 配置文件详解篇
- 搭建分布式架构5--ZooKeeper 集群的安装 3ff0
- Spring+mybatis+shiro+freemarker+ehcache+ldap+mongo
- 第四章 INI配置
- 第五章 编码/加密
- 第六章 Realm及相关对象
- Shiro预览
- JFinal-Beetl-Shiro(JdbcRealm)-例子