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3CqXpnmph/yNSlajzbC61nIJhnvP0p6Rd6HZd2kXXR1NizWb5ljtPj6aT+r333LLUPGkDza5V3+or3FnP/mWnY7Pmx32qr1ehXV9p454et1fv3KBUstX23ufYNTvq3NoKZe8svkl3RTbL457V77ziG1+t5rHGIf2A1Hle93Lsmj5o9tLo5wq77r+vZYebtbBBHuuHuv7VX2Fk0td9qRtCn8G73aDnfvuXoo/rfcqu/0q6ep+Srp1N8bj/KVENmfrhuedJ0vjU5/Lo7KfqkFVL9BXoMwrqC9vHPyZL/+LsL4+l36oKJ12u2ou0mXQU0di27BXSeUR9yiJdolpd403/i1Z6UnpuUOO6AfDnNoENwGNgA/AY2AA8BjYAj4ENwGNgA/AY2AA8BjYAj4ENwGNgAzWPX3jt3cePvfr9Z14HYLt4/NirL7z2buHxl199/cFH9wDYRr786uv/Bwdr8+tQtGiUAAAAAElFTkSuQmCC" alt="" />

2.    三种授权方法

        

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}

Shiro 支持三种方式的授权:

编程式:通过写if/else 授权代码块完成:

Subject subject = SecurityUtils.getSubject();

if(subject.hasRole(“admin”)) {

//有权限

} else {

//无权限

}

注解式:通过在执行的Java方法上放置相应的注解完成:

@RequiresRoles("admin")

public void hello() {

//有权限

}

JSP/GSP 标签:在JSP/GSP 页面通过相应的标签完成:

<shiro:hasRole name="admin">

<!— 有权限—>

</shiro:hasRole>

3.shiro-permission.ini

#用户
[users]
#用户zhang的密码是123,此用户具有role1和role2两个角色
zhangsan=123,role1,role2
wang=123,role2 #权限
[roles]
#角色role1对资源user拥有create、update权限
role1=user:create,user:update
#角色role2对资源user拥有create、delete权限
role2=user:create,user:delete
#角色role3对资源user拥有create权限
role3=user:create

权限标识符号规则:资源:操作:实例(中间使用半角:分隔)

user:create:01  表示对用户资源的01实例进行create操作。

user:create:表示对用户资源进行create操作,相当于user:create:*,对所有用户资源实例进行create操作。

user:*:01  表示对用户资源实例01进行所有操作。

4.程序

@Test
public void testActhorization() {
// 1.创建securityManager工厂
Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro-permission.ini"); // 2.创建securityManager
SecurityManager securityManager = factory.getInstance(); // 3.将securityManager绑定到运行环境
SecurityUtils.setSecurityManager(securityManager); // 4.创建主体
Subject subject = SecurityUtils.getSubject(); // 5.创建token用于认证
UsernamePasswordToken token = new UsernamePasswordToken("zhangsan", "123"); // 6.登录(认证)
try {
subject.login(token);
} catch (AuthenticationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("认证状态:" + subject.isAuthenticated()); // 7.授权 基于角色授权 基于资源的授权 // 7.1基于角色授权
// 授权单个
boolean permitted = subject.hasRole("role1");
System.out.println("这是授权单个:" + permitted); boolean hasAllRoles = subject.hasAllRoles(Arrays.asList("role1", "role2", "role3"));
System.out.println("这是多个授权:" + hasAllRoles); // 使用check方法进行授权,如果授权不通过会抛出异常
// subject.checkRole("role13"); // 7.2 基于资源的授权
// isPermitted传入权限标识符
boolean isPermitted = subject.isPermitted("user:create:1");
System.out.println("单个权限判断" + isPermitted); boolean isPermittedAll = subject.isPermittedAll("user:create:1", "user:delete");
System.out.println("多个权限判断" + isPermittedAll); // 使用check方法进行授权,如果授权不通过会抛出异常
subject.checkPermission("items:create:1"); }

------------------------------------------------------自定义realm授权--------------------------------------------------------------------------------------------------

在原来自定义的realm中,修改doGetAuthorizationInfo方法。

package cn.qlq.realm;

import java.util.ArrayList;
import java.util.List; import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection; /**
* 自定义realm。根据上面穿下来的token去数据库查信息,查到返回一个SimpleAuthenticationInfo,查不到返回null
*
* @author: qlq
* @date : 2017年7月28日下午8:45:52
*/
public class CustomRealm extends AuthorizingRealm { // 设置realm的名称
@Override
public void setName(String name) {
super.setName("customRealm");
} // 用于认证
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { // token是用户输入的
// 第一步从token中取出身份信息(token代表用户输入的传下来的信息)
String userCode = (String) token.getPrincipal(); // 第二步:根据用户输入的userCode从数据库查询
// ....从数据库查数据 // 如果查询不到返回null
// 数据库中用户账号是zhangsansan
/*
* if(!userCode.equals("zhangsansan")){// return null; }
*/ // 模拟从数据库查询到密码
String password = "111111"; // 如果查询到返回认证信息AuthenticationInfo
SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(userCode, password,
this.getName()); return simpleAuthenticationInfo;
} // 用于授权
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { // 从 principals获取主身份信息
// 将getPrimaryPrincipal方法返回值转为真实身份类型(在上边的doGetAuthenticationInfo认证通过填充到SimpleAuthenticationInfo中身份类型),
String userCode = (String) principals.getPrimaryPrincipal(); // 根据身份信息获取权限信息
// 连接数据库...
// 模拟从数据库获取到数据
List<String> permissions = new ArrayList<String>();
permissions.add("user:create");// 用户的创建
permissions.add("items:add");// 商品添加权限
// .... // 查到权限数据,返回授权信息(要包括 上边的permissions)
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
// 将上边查询到授权信息填充到simpleAuthorizationInfo对象中
simpleAuthorizationInfo.addStringPermissions(permissions); return simpleAuthorizationInfo;
} }

ini文件

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZoAAAB7CAIAAADCC9GnAAAaj0lEQVR4nO2d728cx3nH988p9KI/YyVZJyRQAoX6pukLoi8SIHQB6oC2VIEGhEs6Ic+uzZiyZWclhwGlHCtDrkhadKLaF68MW+CV9Tl2bLGyBIEtfIKPlA2q5lUUZcs2RSmYvtjd2WdmnpmdPe79fr4YEPtjZvbZmXk++8zs3dHZ2PyKEiVKlLogOf7FS5QoUaLUBcm5urFDqUGJMRa0MiM1XUHLt3wMUGpmIpw1KgUe1Wqn7nUR0XoqEc4alYhlbSIiWu8kwllDEqPQrG1EOOud5FxZ36GUeSKWtZX8i5daPiQoNSERzhqSCGdtJcJZjyTn0pXLLTei+xKKs5I/rabyW8/f/Xyr+R7eU0Jx9tozf6wm/8R3ySPaKqXqJue15x7+3QdvX1m/TSnDhOLs4m+eubf3QEofvjFRuvD87VufNN/Je0f+xUtqH50/+idqd1w69wh5RFulVN3kfPDyI78+9vB7mfbfG0cHnFyx3apqZkJxduG1576+90BK10uTly9MvvW6t33rUxvPXC8cckZLNgeboDquay6SWOHfRUo8CIXibOnpP0W7oxEe0Vaps3wqVTc5leXJ919+5OWjrrbGd064jjO02Jr26qym5wnFWfG8d/frB8fPvjt1qjT2vP8P//Kru18/+Lg8XVmeXPUn/FdPJLJA5/A9hbPEDVUozham/uzu1w94+quJhUeeOR90h9kj3jg64ERK5RfZpMUjDlAdBnSWT6XqJufzr+5//tX9l578huHm3f4Bp//EG+YLv3PCdY7MZdJeoKqmlsXSh1VT0pVCcXb+lReC1kbT+VdeSCCBncM3U803BjJLisjS4uylJ78B2//gyKmDI6f4rsYjrj7e7wBfuPp4f5rBlsngXDwSG7B4xElfYRNwVp/XoClVNzk7d+/v3L1/+omHNNe+mu8byJeLQ85Avmy0snzCdY4Uqrc/rN6+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pNgwhIUlzhgr5YRrjYuzWil8gzNoZCpKOAOyxxn/H3X6VwEVz3VghKP1NilEkE81D2dwLUlZAxPycbAJNynVrTfeVEpChV141xCcaaozGa89logzvPqEySZjrOqFLIBzNP7SU1UCzmIzlLeNDYrOlJoNrIHI1hlPOOOyxdnWsmfxuTNhwmJazZEdRDoDZyRZ4CzJlFwuB09j8zbEO2MTLXGGlxLiwhSGJ7VGcBH5PmzXOvVnxFvW1muPM9t5cige2ggLSfqPPsjU0yyxMXXSp5ILVFICpcIK7XEmXktaO5NMkiBIODMo6R/TyR+hZUzEmRRZSINSnqLAsSyew2epOV+eAxpWc3TzJOVqqJGyaVqcyXX5wEJTaKkvhVgvsRU9ZYczy5clCdcy3zJqvBFn5mGjMS6eFeJzQzEDPpvLCd8okN5gqjSEGeBZYV1fRKolzqRlO/ldqlgnf61Z8oQZqzxFtaBqd6u7vuRUl9LFBtkLfydY5zJ5D0j3KQ0Sqedx1nJ2KAboJ+Ikxhgb742PUJHqUO/ijM93Wh8HyRO21ltEInWi/h9nWmDHgol3KgAAAABJRU5ErkJggg==" alt="" />

测试:

// 自定义realm进行资源授权测试
@Test
public void testAuthorizationCustomRealm() { // 创建SecurityManager工厂
Factory<SecurityManager> factory = new IniSecurityManagerFactory(
"classpath:shiro-realm.ini"); // 创建SecurityManager
SecurityManager securityManager = factory.getInstance(); // 将SecurityManager设置到系统运行环境,和spring后将SecurityManager配置spring容器中,一般单例管理
SecurityUtils.setSecurityManager(securityManager); // 创建subject
Subject subject = SecurityUtils.getSubject(); // 创建token令牌
UsernamePasswordToken token = new UsernamePasswordToken("zhangsan",
"111111"); // 执行认证
try {
subject.login(token);
} catch (AuthenticationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} System.out.println("认证状态:" + subject.isAuthenticated());
// 认证通过后执行授权 // 基于资源的授权,调用isPermitted方法会调用CustomRealm从数据库查询正确权限数据
// isPermitted传入权限标识符,判断user:create:1是否在CustomRealm查询到权限数据之内
boolean isPermitted = subject.isPermitted("user:create:1");
System.out.println("单个权限判断" + isPermitted); boolean isPermittedAll = subject.isPermittedAll("user:create:1",
"user:create");
System.out.println("多个权限判断" + isPermittedAll); // 使用check方法进行授权,如果授权不通过会抛出异常
subject.checkPermission("items:add:1"); }

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWUAAADpCAIAAABz4rH7AAAgAElEQVR4nO1dS3brsI7MurygrCer8aiX0DvwqCe9hDfVG/hHEoVigVYS5brq5NxzbYogCJIlABapj//7//+0f+f/+d9twOXr9PHx8Xkev7+VnL4uzw/hqvMnrIsvZpi0VRdI+lW7RtSQCpy20wnvcf7cWSAsOn9+fMAKE8snE4Aqn+n0uHDsXS6lLzl/Nl3oPvQN6PKRnuDK3gp9Z1LhiaxR7DAoUfjzY24NVqudEB8zvriabsCzzba47RuoNowNnqsMWVtLAlm/mrJ1oYk1yBIdJ8d11KaK6HxBBM7bwoSRWp5OgInyAKO4vk6nfdfUUMIMMpTxFpmeOXNBYcQEoV+430Tz09e50YhZI6/Vlc79C8PYtttkq7P8e2HuE+gIRLLgRE8klmG+MCRUIrM3xo58Edhh0S1vYL4wfgBp7sIYkcfMKxjjkVclmi8Mw/g5mC8Mw1BhvjAMQ4X5wjAMFSNfbB8f/vvNP8M4MMwXB/szjAMj4Yv2ijCJP2YXpI1VKupiMV7/7eiHYb4wDo85X2zCOr9+Mz67egeXk/GC+cIwjgaJL8Y6wrRWqOHxkdNN5B0J5gvD2Bs/xBfbnQ5EOdz14IA7yZ4PJ54/P05fl+bRuWyj4Eg47cN230FE5gvj8JjwBby3x4/THEf75dR3ICEMaXFE5l/clv2NQNqH9AlfgO3Uu1OG+cI4PPbMX8D/lOSIol7mi2YrxOXrdP+Y80VzERf+CswXxuFR5gsYKcBFHn0HLoc4GnvmL9SzVdqP8RyCb4hJzBfG4fGNfBGFTOVkja5gb7749typ+cI4PAp8Ef+NF2R8Ab2J6WVE2pxNsiRDvvbHXMZHlr/4HpgvjMND5YtswWcXiLkJ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pPikCgbMHBgF3+nvGCgkZ6uMZV9XynrtCifyGkPEpkMfwYOfcvZrX28S/yRdW1j73LhC/W8lykrQXfViELiVA0DanAaTvjUDfQ8xdMYLwLoTTZoAHp8v7j9axI+GK7fJ26X5i5N/4sqtCXnr/oxKduNrcDsnwUnvW47RerRWZYiS9i7rabh20xCFbw7Y9MfoasrSWBrF9N2brQxBp5hAL9Y8F50PmCC2yVB61BwmCDsu94Aa8quXez1UNkFsgrX+OdkloSAXQMMTUz7u6H7vVzYCl/Ybw7QFr4TbGWf8KAmaOXpC/nsxSYLwwJlcjsX8eOfBHYYdH3bmC+MH4XSSjytiAx2ALGeORVieYLwzAOAfOFYRgqzBeGYcyAND8AAABbSURBVKgwXxiGocJ8YRiGCvOFYRgqzBeGYagwXxiGocJ8YRiGCvOFYRgqzBeGYagwXxiGocJ8YRiGCvOFYRgqzBeGYagwXxiGocJ8YRiGCvOFYRgqzBeGYaj4L0jOy8oukIuXAAAAAElFTkSuQmCC" alt="" />

总结授权流程:

1、对subject进行授权,调用方法isPermitted("permission串")

2、SecurityManager执行授权,通过ModularRealmAuthorizer执行授权

3、ModularRealmAuthorizer执行realm(自定义的CustomRealm)从数据库查询权限数据

调用realm的授权方法:doGetAuthorizationInfo

4、realm从数据库查询权限数据,返回ModularRealmAuthorizer

5、ModularRealmAuthorizer调用PermissionResolver进行权限串比对

6、如果比对后,isPermitted中"permission串"在realm查询到权限数据中,说明用户访问permission串有权限,否则 没有权限,抛出异常。

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}

shiro授权及自定义realm授权(七)的更多相关文章

  1. Shiro入门 - 通过自定义Realm连数数据库进行授权

    shiro-realm.ini [main] #自定义Realm myRealm=test.shiro.MyRealm #将myRealm设置到securityManager,相当于Spring中的注 ...

  2. Shiro第三篇【授权、自定义reaml授权】

    Shiro授权 上一篇我们已经讲解了Shiro的认证相关的知识了,现在我们来弄Shiro的授权 Shiro授权的流程和认证的流程其实是差不多的: Shiro支持的授权方式 Shiro支持的授权方式有三 ...

  3. shiro教程2(自定义Realm)

    通过shiro教程1我们发现仅仅将数据源信息定义在ini文件中与我们实际开发环境有很大不兼容,所以我们希望能够自定义Realm. 自定义Realm的实现 创建自定义Realmjava类 创建一个jav ...

  4. Shiro入门 - 通过自定义Realm连数数据库进行认证(md5+salt形式)

    shiro-realm-md5.ini [main] #定义凭证匹配器 credentialsMatcher=org.apache.shiro.authc.credential.HashedCrede ...

  5. Shiro入门 - 通过自定义Realm连数数据库进行认证

    添加shiro-realm.ini文件 [main] #自定义Realm myRealm=test.shiro.MyRealm #将myRealm设置到securityManager,相当于Sprin ...

  6. 【Shiro】Apache Shiro架构之自定义realm

    [Shiro]Apache Shiro架构之身份认证(Authentication) [Shiro]Apache Shiro架构之权限认证(Authorization) [Shiro]Apache S ...

  7. 当shiro不进入自定义realm的权限认证方法时

    需要加入下面的一个bean @Bean public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator(){ DefaultAdvisorA ...

  8. shiro学习笔记_0600_自定义realm实现授权

    博客shiro学习笔记_0400_自定义Realm实现身份认证 介绍了认证,这里介绍授权. 1,仅仅通过配置文件来指定权限不够灵活且不方便.在实际的应用中大多数情况下都是将用户信息,角色信息,权限信息 ...

  9. Shiro入门学习之自定义Realm实现授权(五)

    一.自定义Realm授权 前提:认证通过,查看Realm接口的继承关系结构图如下,要想通过自定义的Realm实现授权,只需继承AuthorizingRealm并重写方法即可 二.实现过程 1.新建mo ...

随机推荐

  1. EF 更新 删除

    为了避免先查询后更新或删除的问题 可以使用如下语句 Entities db = new Entities(); Orders o = new Orders(); o.id = 6; o.name = ...

  2. day5 列表

    列表 查 索引(下标),默认从0开始 切片 .count 查某个元素的出现次数 .index 根据内容找元素的对应索引位置 增加 .append() 追加在最后 .insert(index,'内容') ...

  3. Mysql 主从服务器数据同步

    安装2台windows Server 服务器,分别安装Mysql,配置环境变量,完成安装确认在CMD窗口可以使用Mysql命令 在Master服务器上创建同步账号,确保Slave服务器能访问Maste ...

  4. LCT模板(指针版)

    本来是想做THUWC2017的泰勒展开xLCT题的-- 然后觉得数组写很麻烦-- 然后就决定挑战指针版-- 然后写得全是BUG-- 与BUG鏖战三千年后,有了这个指针版LCT板子! #include ...

  5. 一种BCD码转换的算法

    #include "stdio.h" typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef ...

  6. 洛谷 P1582 倒水 解题报告

    P1582 倒水 题目描述 一天,CC买了N个容量可以认为是无限大的瓶子,开始时每个瓶子里有1升水.接着~~CC发现瓶子实在太多了,于是他决定保留不超过K个瓶子.每次他选择两个当前含水量相同的瓶子,把 ...

  7. bzoj1001/luogu4001 狼抓兔子 (最小割/平面图最小割转对偶图最短路)

    平面图转对偶图:先在原图中加一个s->t的边,然后对每个面建一个点,对每条分隔两个面的边加一条连接这两个面对应点的边,边权等于原边权. 然后从刚才加的s->t分割出来的两面对应的两个点跑最 ...

  8. Windows下查看游戏服务器的IP地址

    在任务管理器中查看进程的PID 在cmd中使用netstat -aon,找到PID对应的IP地址

  9. 51nod1238 最小公倍数之和 V3

    又被这神仙题给坑爆了. 神仙题解. 一开始我把lcm变成ij/gcd然后按照常规套路去推,推到最后发现不是miu * Id而是miu · Id......这还搞鬼啊. 正解居然跟这个差不多,先转成求其 ...

  10. 《CSS揭秘》笔记(一)

    前言 我们在现代 CSS 中所面临的挑战已经不在于如何绕过这些转瞬即逝的浏览器 bug.如今的挑战是,在保证 DRY ① .可维护.灵活性.轻量级并且尽可能符合标准的前提下,把我们手中的这些CSS特性 ...