shrio 权限管理filterChainDefinitions过滤器配置

shrio 权限管理filterChainDefinitions过滤器配置

/**

* Shiro-1.2.2内置的FilterChain

* @see =============================================================================================================================

* @see 1)Shiro验证URL时,URL匹配成功便不再继续匹配查找(所以要注意配置文件中的URL顺序,尤其在使用通配符时)

* @see   故filterChainDefinitions的配置顺序为自上而下,以最上面的为准

* @see 2)当运行一个Web应用程序时,Shiro将会创建一些有用的默认Filter实例,并自动地在[main]项中将它们置为可用

* @see   自动地可用的默认的Filter实例是被DefaultFilter枚举类定义的,枚举的名称字段就是可供配置的名称

* @see   anon---------------org.apache.shiro.web.filter.authc.AnonymousFilter

* @see   authc--------------org.apache.shiro.web.filter.authc.FormAuthenticationFilter

* @see   authcBasic---------org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter

* @see   logout-------------org.apache.shiro.web.filter.authc.LogoutFilter

* @see   noSessionCreation--org.apache.shiro.web.filter.session.NoSessionCreationFilter

* @see   perms--------------org.apache.shiro.web.filter.authz.PermissionAuthorizationFilter

* @see   port---------------org.apache.shiro.web.filter.authz.PortFilter

* @see   rest---------------org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter

* @see   roles--------------org.apache.shiro.web.filter.authz.RolesAuthorizationFilter

* @see   ssl----------------org.apache.shiro.web.filter.authz.SslFilter

*@see   user---------------org.apache.shiro.web.filter.authz.UserFilter

* @see =============================================================================================================================

* @see 3)通常可将这些过滤器分为两组

* @see   anon,authc,authcBasic,user是第一组认证过滤器

* @see   perms,port,rest,roles,ssl是第二组授权过滤器

* @see   注意user和authc不同:当应用开启了rememberMe时,用户下次访问时可以是一个user,但绝不会是authc,因为authc是需要重新认证的

* @see                      user表示用户不一定已通过认证,只要曾被Shiro记住过登录状态的用户就可以正常发起请求,比如rememberMe

* @see                      说白了,以前的一个用户登录时开启了rememberMe,然后他关闭浏览器,下次再访问时他就是一个user,而不会authc

* @see =============================================================================================================================

* @see 4)举几个例子

* @see   /admin=authc,roles[admin]      表示用户必需已通过认证,并拥有admin角色才可以正常发起‘/admin‘请求

* @see   /edit=authc,perms[admin:edit]  表示用户必需已通过认证,并拥有admin:edit权限才可以正常发起‘/edit‘请求

* @see   /home=user                     表示用户不一定需要已经通过认证,只需要曾经被Shiro记住过登录状态就可以正常发起‘/home‘请求

* @see =============================================================================================================================

* @see 5)各默认过滤器常用如下(注意URL Pattern里用到的是两颗星,这样才能实现任意层次的全匹配)

* @see   /admins/**=anon             无参,表示可匿名使用,可以理解为匿名用户或游客

* @see   /admins/user/**=authc       无参,表示需认证才能使用

* @see   /admins/user/**=authcBasic  无参,表示httpBasic认证

* @see   /admins/user/**=user        无参,表示必须存在用户,当登入操作时不做检查

* @see   /admins/user/**=ssl         无参,表示安全的URL请求,协议为https

* @see   /admins/user/**=perms[user:add:*]

* @see       参数可写多个,多参时必须加上引号,且参数之间用逗号分割,如/admins/user/**=perms["user:add:*,user:modify:*"]

* @see       当有多个参数时必须每个参数都通过才算通过,相当于isPermitedAll()方法

* @see   /admins/user/**=port[8081]

* @see       当请求的URL端口不是8081时,跳转到schemal://serverName:8081?queryString

* @see       其中schmal是协议http或https等,serverName是你访问的Host,8081是Port端口,queryString是你访问的URL里的?后面的参数

* @see   /admins/user/**=rest[user]

* @see       根据请求的方法,相当于/admins/user/**=perms[user:method],其中method为post,get,delete等

* @see   /admins/user/**=roles[admin]

* @see       参数可写多个,多个时必须加上引号,且参数之间用逗号分割,如/admins/user/**=roles["admin,guest"]

* @see       当有多个参数时必须每个参数都通过才算通过,相当于hasAllRoles()方法

* @see

http://liureying.blog.163.com/blog/static/61513520136205574873/

spring中 shiro logout 配置方式
有两种方式实现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>

http://kdboy.iteye.com/blog/1154652

http://blog.csdn.net/peterwanghao/article/details/8084126

http://www.oschina.net/question/593111_62454

http://blog.csdn.net/shadowsick/article/details/17265625

时间: 2024-08-18 12:00:56

shrio 权限管理filterChainDefinitions过滤器配置的相关文章

linux学习随笔——linux文件权限管理和网络配置

一.linux文件权限管理 查看某个文件的权限命令:ls -l linux文件权限有4种:读(r).写(w).执行(x)和无权限(-) 一般用10个字符表示其权限,按照(1-3-3-3)来分组划分 1位置 表示文件类型 "-"表示文件,"d"表示目录 2-4位 表示用户权限(u) 5-7位 表示组权限(g) 8-10  表示其他权限(o) 通常用chmod来修改权限:chmod     u+r 目标文件 也可以用数字来表示权限 r=4 w=2 x=1 chown命令

Shiro权限管理的过滤器解释

默认过滤器(10个) anon -- org.apache.shiro.web.filter.authc.AnonymousFilterauthc -- org.apache.shiro.web.filter.authc.FormAuthenticationFilterauthcBasic -- org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilterperms -- org.apache.shiro.web.filter.a

【权限管理】springboot集成security

摘自: https://www.cnblogs.com/hhhshct/p/9726378.html https://blog.csdn.net/weixin_42849689/article/details/89957823 https://blog.csdn.net/zhaoxichen_10/article/details/88713799 http://www.imooc.com/article/287214 一.Spring Security简介 Spring Security是一个能

HADOOP docker(七):hive权限管理

1. hive权限简介1.1 hive中的用户与组1.2 使用场景1.3 权限模型1.3 hive的超级用户2. 授权管理2.1 开启权限管理2.2 实现超级用户2.3 实现hiveserver2用户名密码2.4 授权2.4.1 角色管理2.4.2 权限管理2.4.3 操作与权限对应关系 文档链接: hive权限管理 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Authorization#LanguageManu

springboot配置shiro权限管理,网搜搜采集网站权限控制代码

import outshine.shiro.authc.AccountSubjectFactory; import outshine.shiro.filter.AuthenticatedFilter; import outshine.shiro.realm.AccountRealm; import org.apache.shiro.cache.CacheManager; import org.apache.shiro.cache.ehcache.EhCacheManager; import or

estore商城案例(三)------Filter过滤器:自动登录&amp;权限管理

前面写好了用户登录\注册\添加商品的功能模块.下面写一下对于这些功能模块的相关过滤器---自动登录与权限管理: 一.自动登录: 业务逻辑是这样的:jsp登录页面有个“自动登录选项”,如果登录这勾选了,那么在serlvet程序中则会额外的生成一个保存用户名和密码的cookie,然后每次用户向服务器发送请求时,Filter过滤器都会先判断用户的登录状态(session),如果已经登录那么无需做出受任何操作直接放行,如果没有登录(无session),那么这时体现自动登录功能作用的时候到了,先获取自动登

spring security3.2配置---权限管理

之前已经在我的博客中发过security的运行流程图了,大家可以先去看看那个图再看这篇.今天我主要在这里贴出了security配置中的几个重要的类和两个xml配置文件,基本上控制权限的就是这几个文件了.因为最近都比较忙,一直没有时间发出来,导致有点忘记配置时的过程了,所以忘记了一些细节的内容,原本我打算写的详细一点的,但现在都有点忘记了,我在这里就不再一一写出来了,因为在每个文件的方法或配置里,我用注释说明了一些配置时所遇到的问题,大家可以看看,可能比较难看,因为表达可能不是很好,有些写得比较详

Jenkins配置基于角色的项目权限管理

 本文将介绍如何配置jenkins,使其可以支持基于角色的项目权限管理. 由于jenkins默认的权限管理体系不支持用户组或角色的配置,因此需要安装第三发插件来支持角色的配置,本文将使用Role Strategy Plugin,介绍页面:https://wiki.jenkins-ci.org/display/JENKINS/Role+Strategy+Plugin 1.配置插件 安装插件后,进入系统设置页面 配置如下: 2.配置权限 在系统管理页面点击Manage and Assign Ro

Jenkins配置基于角色的项目权限管理--转

本文将介绍如何配置jenkins,使其可以支持基于角色的项目权限管理. 由于jenkins默认的权限管理体系不支持用户组或角色的配置,因此需要安装第三发插件来支持角色的配置,本文将使用Role Strategy Plugin,介绍页面:https://wiki.jenkins-ci.org/display/JENKINS/Role+Strategy+Plugin 一.配置插件 安装插件后,进入系统设置页面,配置如下: 官网上安全域设置为Servlet容器代理,实际操作发现Jenkins专有用户数