Apache Shiro 使用手册(五)Shiro 配置说明
来源:互联网 发布:红拂夜奔 知乎 编辑:程序博客网 时间:2024/06/04 00:22
Apache Shiro的配置主要分为四部分:
Apache Shiro的大多数组件是基于POJO的,因此我们可以使用POJO兼容的任何配置机制进行配置,例如:Java代码、Sping XML、YAML、JSON、ini文件等等。下面,以Spring XML的配置方式为例,并且对其中的一些配置参数进行一些简单说明。
Shiro对象的配置:
主要是对Shiro各个组件的实现进行定义配置,主要组件在前文已做过简单介绍,这里不再一一说明。
Shiro过滤器的配置
Shiro主要是通过URL过滤来进行安全管理,这里的配置便是指定具体授权规则定义。
URL过滤器配置说明:
Shiro可以通过配置文件实现基于URL的授权验证。FilterChain定义格式:
URL_Ant_Path_Expression = Path_Specific_Filter_Chain
每个URL配置,表示匹配该URL的应用程序请求将由对应的过滤器进行验证。
例如:
[urls]
/index.html = anon
/user/create = anon
/user/** = authc
/admin/** = authc, roles[administrator]
/rest/** = authc, rest
/remoting/rpc/** = authc, perms["remote:invoke"]
URL表达式说明
1、URL目录是基于HttpServletRequest.getContextPath()此目录设置
2、URL可使用通配符,**代表任意子目录
3、Shiro验证URL时,URL匹配成功便不再继续匹配查找。所以要注意配置文件中的URL顺序,尤其在使用通配符时。
Filter Chain定义说明
1、一个URL可以配置多个Filter,使用逗号分隔
2、当设置多个过滤器时,全部验证通过,才视为通过
3、部分过滤器可指定参数,如perms,roles
Shiro内置的FilterChain
Filter NameClassanonorg.apache.shiro.web.filter.authc.AnonymousFilterauthcorg.apache.shiro.web.filter.authc.FormAuthenticationFilterauthcBasicorg.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilterpermsorg.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
- 对象和属性的定义与配置
- URL的过滤器配置
- 静态用户配置
- 静态角色配置
Apache Shiro的大多数组件是基于POJO的,因此我们可以使用POJO兼容的任何配置机制进行配置,例如:Java代码、Sping XML、YAML、JSON、ini文件等等。下面,以Spring XML的配置方式为例,并且对其中的一些配置参数进行一些简单说明。
Shiro对象的配置:
主要是对Shiro各个组件的实现进行定义配置,主要组件在前文已做过简单介绍,这里不再一一说明。
- <bean id="securityManager" class="org.apache.shiro.mgt.DefaultSecurityManager">
- <property name="cacheManager" ref="cacheManager"/>
- <property name="sessionMode" value="native"/>
- <!-- Single realm app. If you have multiple realms, use the 'realms' property instead. -->
- <property name="realm" ref="myRealm"/>
- <property name="sessionManager" ref="sessionManager"/>
- </bean>
Shiro过滤器的配置
Shiro主要是通过URL过滤来进行安全管理,这里的配置便是指定具体授权规则定义。
- <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
- <property name="securityManager" ref="securityManager"/>
- <property name="loginUrl" value="/login.jsp"/>
- <property name="successUrl" value="/home.jsp"/>
- <property name="unauthorizedUrl" value="/unauthorized.jsp"/> -->
- <property name="filterChainDefinitions">
- <value>
- # some example chain definitions:
- /admin/** = authc, roles[admin]
- /docs/** = authc, perms[document:read]
- /** = authc
- # more URL-to-FilterChain definitions here
- </value>
- </property>
- </bean>
URL过滤器配置说明:
Shiro可以通过配置文件实现基于URL的授权验证。FilterChain定义格式:
URL_Ant_Path_Expression = Path_Specific_Filter_Chain
每个URL配置,表示匹配该URL的应用程序请求将由对应的过滤器进行验证。
例如:
[urls]
/index.html = anon
/user/create = anon
/user/** = authc
/admin/** = authc, roles[administrator]
/rest/** = authc, rest
/remoting/rpc/** = authc, perms["remote:invoke"]
URL表达式说明
1、URL目录是基于HttpServletRequest.getContextPath()此目录设置
2、URL可使用通配符,**代表任意子目录
3、Shiro验证URL时,URL匹配成功便不再继续匹配查找。所以要注意配置文件中的URL顺序,尤其在使用通配符时。
Filter Chain定义说明
1、一个URL可以配置多个Filter,使用逗号分隔
2、当设置多个过滤器时,全部验证通过,才视为通过
3、部分过滤器可指定参数,如perms,roles
Shiro内置的FilterChain
Filter NameClassanonorg.apache.shiro.web.filter.authc.AnonymousFilterauthcorg.apache.shiro.web.filter.authc.FormAuthenticationFilterauthcBasicorg.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilterpermsorg.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
- Apache Shiro 使用手册(五)Shiro 配置说明
- Apache Shiro 使用手册(五)Shiro 配置说明
- Apache Shiro 使用手册(五)Shiro 配置说明
- Apache Shiro 使用手册(五)Shiro 配置说明
- Apache Shiro 使用手册(五)Shiro 配置说明
- Apache Shiro 使用手册(五)Shiro 配置说明
- Apache Shiro 使用手册(五)Shiro 配置说明
- Apache Shiro 使用手册(五)Shiro 配置说明
- Apache Shiro 使用手册(五)Shiro 配置说明
- Apache Shiro 使用手册(五)Shiro 配置说明
- Apache Shiro 使用手册(五)Shiro 配置说明
- Apache Shiro 使用手册(五)Shiro 配置说明
- Apache Shiro 使用手册(五)Shiro 配置说明
- Apache Shiro学习(五)Shiro 配置说明
- Apache Shiro 使用手册(二)Shiro 认证
- Apache Shiro 使用手册(三)Shiro 授权
- Apache Shiro 使用手册(三)Shiro 授权
- Apache Shiro 使用手册(二)Shiro 认证
- LVM一种支持在线增大和减小的分区技术
- Apache Shiro 使用手册(四)Realm 实现
- action的配置
- Java_io体系之BufferedWriter、BufferedReader简介、走进源码及示例——16
- 64位机器上安装plsql-(第一种方法,安装64位oracle,然后配置安装plsql)
- Apache Shiro 使用手册(五)Shiro 配置说明
- sencha touch笔记(3)
- 黑马程序员---java基础之day10-11
- How to POST a django form with AJAX & jQuery
- NOR与NAND闪存对比
- 安装SQL SERVER 2000时提示"系统有挂起的程序"之解决
- 飞秋教程:日程安排记事提醒
- result配置
- 如何在Hadoop中控制Map的数量