Apache Shiro的配置主要分为四部分: 
  • 对象和属性的定义与配置
  • URL的过滤器配置
  • 静态用户配置
  • 静态角色配置

其中,由于用户、角色一般由后台进行操作的动态数据,因此Shiro配置一般仅包含前两项的配置。 

Apache Shiro的大多数组件是基于POJO的,因此我们可以使用POJO兼容的任何配置机制进行配置,例如:Java代码、Sping XML、YAML、JSON、ini文件等等。下面,以Spring XML的配置方式为例,并且对其中的一些配置参数进行一些简单说明。 

Shiro对象的配置: 
主要是对Shiro各个组件的实现进行定义配置,主要组件在前文已做过简单介绍,这里不再一一说明。 

  1. <bean id="securityManager" class="org.apache.shiro.mgt.DefaultSecurityManager">
  2. <property name="cacheManager" ref="cacheManager"/>
  3. <property name="sessionMode" value="native"/>
  4. <!-- Single realm app.  If you have multiple realms, use the 'realms' property instead. -->
  5. <property name="realm" ref="myRealm"/>
  6. <property name="sessionManager" ref="sessionManager"/>
  7. </bean>

Shiro过滤器的配置 
Shiro主要是通过URL过滤来进行安全管理,这里的配置便是指定具体授权规则定义。 

  1. <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
  2. <property name="securityManager" ref="securityManager"/>
  3. <property name="loginUrl" value="/login.jsp"/>
  4. <property name="successUrl" value="/home.jsp"/>
  5. <property name="unauthorizedUrl" value="/unauthorized.jsp"/> -->
  6. <property name="filterChainDefinitions">
  7. <value>
  8. # some example chain definitions:
  9. /admin/** = authc, roles[admin]
  10. /docs/** = authc, perms[document:read]
  11. /** = authc
  12. # more URL-to-FilterChain definitions here
  13. </value>
  14. </property>
  15. </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 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
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

Apache Shiro 使用手册(五)Shiro 配置说明的更多相关文章

  1. Shiro学习笔记五(Shiro标签,及通配符)

    1.首先是导入标签库 <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %> ...

  2. Apache Shiro 使用手册(五)Shiro 配置说明(转发:http://kdboy.iteye.com/blog/1169637)

    Apache Shiro的配置主要分为四部分: 对象和属性的定义与配置 URL的过滤器配置 静态用户配置 静态角色配置 其中,由于用户.角色一般由后台进行操作的动态数据,因此Shiro配置一般仅包含前 ...

  3. Apache Shiro 使用手册---转载

    原文地址:http://www.360doc.com/content/12/0104/13/834950_177177202.shtml (一)Shiro架构介绍 一.什么是Shiro Apache ...

  4. Apache Shiro 使用手册

    http://kdboy.iteye.com/blog/1154644 (一)Shiro架构介绍 一.什么是Shiro  Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加 ...

  5. Apache Shiro 使用手册(一)Shiro架构介绍 - kdboy - ITeye技术网站

    转载 原文地址 http://kdboy.iteye.com/blog/1154644 一.什么是Shiro Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理 ...

  6. Apache Shiro 使用手册(三)Shiro 授权

    授权即访问控制,它将判断用户在应用程序中对资源是否拥有相应的访问权限. 如,判断一个用户有查看页面的权限,编辑数据的权限,拥有某一按钮的权限,以及是否拥有打印的权限等等. 一.授权的三要素 授权有着三 ...

  7. Apache Shiro 使用手册(一)Shiro架构介绍

    一.什么是Shiro Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能:  认证 - 用户身份识别,常被称为用户"登录": 授权 - ...

  8. Apache Shiro 使用手册(三)Shiro 授权(转发:http://kdboy.iteye.com/blog/1155450)

    授权即访问控制,它将判断用户在应用程序中对资源是否拥有相应的访问权限. 如,判断一个用户有查看页面的权限,编辑数据的权限,拥有某一按钮的权限,以及是否拥有打印的权限等等. 一.授权的三要素 授权有着三 ...

  9. Apache Shiro 使用手册(一)Shiro架构介绍(转发:http://kdboy.iteye.com/blog/1154644#bc2399255)

    一.什么是Shiro Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能: 认证 - 用户身份识别,常被称为用户“登录”: 授权 - 访问控制: 密码加密 ...

随机推荐

  1. Xshell 登录 AWS CentOS 出现“所选择的用户秘钥未在远程主机上注册“,最终解决办法!

     其实就是 登录用户名错了,是 root,不是centos 也不是 ec2-user !  Xshell 连接配置界面如下 最重要是 登录授权配置 最后,登录成功! 就这么简单

  2. guava学习--File

    使用Files类来执行那些基本的任务,比如:移动或复制文件,或读取文件内容到一个字符串集合 Closer类,提供了一种非常干净的方式,确保Closeable实例被正确的关闭 ByteSource 和 ...

  3. sql server 子找父和父找子

    父找子 with RTD1 as( select Id,pid from Sys_XCode ), RTD2 as( select * from RTD1 where id=1 union all s ...

  4. 常用的获取时间差的sql语句

    "select count(*) from [注册] where datediff(day,time,getdate())<1";//获取当天注册人员数 sql=" ...

  5. easyui 之ComboTree 用法Demo

    实现效果如下: HTML部分: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="ser ...

  6. SVN - 忽略已经提交的文件

    1.在本地删除要忽略的文件 2.与资源库同步,提交删除的文件 3.忽略文件

  7. web前端基础篇⑧

    1.伪类选择器 都以冒号开始.:focus 焦点的地方加样式:first-child 向元素的第一个子元素添加样式锚伪类:a:link {color:red} 未访问的链接 a:visited {co ...

  8. Android中的五大布局

    Android中的五大布局 1.了解布局 一个丰富的界面总是要由很多个控件组成的,那我们如何才能让各个控件都有条不紊地 摆放在界面上,而不是乱糟糟的呢?这就需要借助布局来实现了.布局是一种可用于放置很 ...

  9. hdu 2087

    ps:感觉就是字符串处理...好像没什么好讲的...直接上代码 代码: #include "stdio.h" #include "string.h" ]; ]; ...

  10. Jquery EasyUI DataGrid .net实例

    前台界面:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...