shiro-permission.ini

#用户
[users]
#admin的密码是111111,此用户具有role1、role2两个角色
admin=111111,role1,role2
zhangsan=222222,role2

#角色
[roles]
#角色role1对用户有create、update权限
role1=user:create,user:update

#角色role2对用户有create、delete权限
role2=user:create,user:delete

#角色role3对用户有create权限
role3=user:create

测试代码

 /**
 * 从shiro-permission.ini文件中读取权限
 */
@Test
public void testPermission(){
    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro/shiro-permission.ini");
    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);
    Subject subject = SecurityUtils.getSubject();
    UsernamePasswordToken token = new UsernamePasswordToken("admin", "111111");
    subject.login(token);
    System.out.println("认证状态:"+subject.isAuthenticated());

    //认证成功后授权
    //基于角色的授权
    System.out.println(subject.hasRole("role1"));
    System.out.println(subject.hasAllRoles(Arrays.asList("role1", "role2")));

    //基于资源的授权
    System.out.println(subject.isPermitted("user:create"));
    System.out.println(subject.isPermittedAll("user:create", "user:update", "user:delete"));
}

测试结果

认证状态:true
true
true
true
true

Shiro入门 - 通过ini文件进行授权的更多相关文章

  1. Shiro入门 - 通过ini文件进行认证

    导入依赖 <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core ...

  2. Shiro入门学习之shi.ini实现授权(三)

    一.Shiro授权 前提:需要认证通过才会有授权一说 1.授权过程 2.相关方法说明 ①subject.hasRole("role1"):判断是否有该角色 ②subject.has ...

  3. 转:JAVAWEB开发之权限管理(二)——shiro入门详解以及使用方法、shiro认证与shiro授权

    原文地址:JAVAWEB开发之权限管理(二)——shiro入门详解以及使用方法.shiro认证与shiro授权 以下是部分内容,具体见原文. shiro介绍 什么是shiro shiro是Apache ...

  4. shiro入门实例,基于ini配置

    基于ini或者关系数据库的,其实都是一样的,重要的是思想. # ==================================================================== ...

  5. shiro解析ini文件

    来吧,看看shiro是怎么解析ini文件的,这里假设ini文件在classpath下,名字叫做shiro.ini Factory<org.apache.shiro.mgt.SecurityMan ...

  6. Shiro入门学习之shi.ini实现认证及源码分析(二)

    一.Shiro.ini文件 1.文件说明 ①ini(InitializationFile)初始文件:Window系统文件扩展名 ②Shiro使用时可以连接数据库,也可以不连接数据库(可以使用shiro ...

  7. shiro入门与认证原理

    一.shiro介绍 1.什么是shiro  shiro是apache的一个开源框架,是一个权限管理的框架,实现 用户认证.用户授权. 2.shiro的优点  (1)shiro将安全认证相关的功能抽取出 ...

  8. Apache Shiro入门实例

    Shiro是一个强大灵活的开源安全框架,提供身份验证.授权.会话管理.密码体系. 1.先创建一个Maven项目 2.配置pom <project xmlns="http://maven ...

  9. Shiro入门(1)

    =============基本概念=================== 什么是Apache Shiro? Apache Shiro(发音为“shee-roh”,日语“堡垒(Castle)”的意思)是 ...

随机推荐

  1. 有趣的js获取input标签中光标的索引

    先看动图如下,我们就可以很清楚的知道获取input标签中光标的索引的意思了. 由于IE支持document.selection,Firefox,Chrome,Safari以及Opera都有select ...

  2. double free or corruption错误

    这是我自己写代码是遇到的错误,完全想不到报错和写错的地方有关联性,记录下来给别人参考. 不允许转载. WhiteBack(&cut_buff,&out_buff,5)函数内有一段 be ...

  3. selenium自动化测试原理和设计的分享

    昨天参加了公司的一个自动化测试的分享,有一些收获,记录一下. 1.主流的web端的UI自动化测试工具 基于浏览器API: selenium2.0,Watir(IE Driver) 基于JS 进行驱动: ...

  4. (BFS 二叉树) leetcode 515. Find Largest Value in Each Tree Row

    You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3 2 / \ \ 5 3 ...

  5. (选择不相交区间)今年暑假不AC hdu2037

    今年暑假不AC Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  6. 苹果中国全系降价:iphone最高降500元,用户可退差价

    本文首发于:风云社区SCOEE(社区旨在普惠软件.图片.音乐.视频.素材.文档等互联网资源.为大众提供多样化的服务,以及主要涵盖学术科学.电脑技术.文化人文.体育健身等领域的知识和信息,获得用户的支持 ...

  7. pandas知识点

    1.选择对象 1.选择特定列和行的数据 a['x'] 那么将会返回columns为x的列,注意这种方式一次只能返回一个列.a.x与a['x']意思一样. 取行数据,通过切片[]来选择 如:a[0:3] ...

  8. flask flash消息

    请求完成,让用户知道状态发生了变化,可以使用flash确认消息 示例: xx.py from flask import Flask,render_template,request,redirect,u ...

  9. 运维监控-Open-Falcon介绍

    运维监控-Open-Falcon介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Open-Falcon 介绍 监控系统是整个运维环节,乃至整个产品生命周期中最重要的一环,事 ...

  10. Spring Boot笔记一 输出hello

    开始学习Spring Boot了,本篇文章你可以学到 1.Spring Boot的基本配置,输出一句hello 许嵩 2.Spring boot打包成jar包 一.Spring boot的基本配置 这 ...