shiro权限管理入门程序
最近在学shiro,觉得入门程序还是有用的,记下来防止遗忘,也可供大家参考。
package cn.itcast.shiro.authentication; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
import org.junit.Test; /**
*
* @author yxf
* shiro验证用户的登录
*
*/
public class AuthenticationTest { //用户登录退出
@Test
public void testLoginAndLogout() {
//创建securityManager工厂
Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro-first.ini"); //创建securityManager
SecurityManager securityManager = factory.getInstance(); //securityManager设置到当前运行环境中
SecurityUtils.setSecurityManager(securityManager); //SecurityUtils创建一个subject
Subject subject = SecurityUtils.getSubject(); //认证提交前准备token
UsernamePasswordToken token = new UsernamePasswordToken("zhangsan", "111111"); //执行认证提交
try {
subject.login(token);
} catch (AuthenticationException e) {
e.printStackTrace();
} //是否认证通过
boolean flag = subject.isAuthenticated(); System.out.println("是否认证通过:" + flag); //退出操作
subject.logout(); flag = subject.isAuthenticated(); System.out.println("是否认证通过:" + flag); }
}
shiro权限管理入门程序的更多相关文章
- shiro权限管理的框架-入门
shiro权限管理的框架 1.权限管理的概念 基本上涉及到用户参与的系统都要进行权限管理,权限管理属于系统安全的范畴,权限管理实现对用户访问系统的控制,按照安全规则或者安全策略控制用户可以访问而且只能 ...
- (补漏)Springboot2.0 集成shiro权限管理
原文Springboot2.0 集成shiro权限管理 一.关于停止使用外键. 原本集成shiro建立用户.角色.权限表的时候使用了外键,系统自动创建其中两个关联表,用@JoinTable.看起来省事 ...
- (39.4) Spring Boot Shiro权限管理【从零开始学Spring Boot】
在读此文章之前您还可能需要先了解: (39.1) Spring Boot Shiro权限管理[从零开始学Spring Boot] http://412887952-qq-com.iteye.com/b ...
- (39.3) Spring Boot Shiro权限管理【从零开始学Spring Boot】
在学习此小节之前您可能还需要学习: (39.1) Spring Boot Shiro权限管理[从零开始学Spring Boot] http://412887952-qq-com.iteye.com/b ...
- (39.2). Spring Boot Shiro权限管理【从零开始学Spring Boot】
(本节提供源代码,在最下面可以下载) (4). 集成Shiro 进行用户授权 在看此小节前,您可能需要先看: http://412887952-qq-com.iteye.com/blog/229973 ...
- (39.1) Spring Boot Shiro权限管理【从零开始学Spring Boot】
(本节提供源代码,在最下面可以下载)距上一个章节过了二个星期了,最近时间也是比较紧,一直没有时间可以写博客,今天难得有点时间,就说说Spring Boot如何集成Shiro吧.这个章节会比较复杂,牵涉 ...
- Spring Boot Shiro 权限管理 【转】
http://blog.csdn.net/catoop/article/details/50520958 主要用于备忘 本来是打算接着写关于数据库方面,集成MyBatis的,刚好赶上朋友问到Shiro ...
- SpringMVC+Shiro权限管理(转载)
源码 http://pan.baidu.com/s/1pJzG4t1 SpringMVC+Shiro权限管理 博文目录 权限的简单描述 实例表结构及内容及POJO Shiro-pom.xml Shir ...
- Spring Boot Shiro 权限管理
Spring Boot Shiro 权限管理 标签: springshiro 2016-01-14 23:44 94587人阅读 评论(60) 收藏 举报 .embody{ padding:10px ...
随机推荐
- 3 Oracle 32位客户端安装及arcgis连接
关于Oracle服务器端安装及配置的过程详见第2篇文章,链接如下:http://www.cnblogs.com/gistrd/p/8494292.html,本篇介绍客户端安装配置及连接arcgis过程 ...
- Spring AOP 随记
本周经历各种面试失败后,最后一站张建飞老大的阿里,感觉有着这般年纪不该有的垃圾履历而忧伤中,不过还是要继续加油的,毕竟他说的好,都是经历,无愧初心. 所以为了更加深入理解Spring AOP我又翻起了 ...
- Yarn Node Labels
Yarn Node Labels + Capacity-Scheduler 在yarn-site.xml中开启capacity-schedule yarn-site.xml <property& ...
- JavaScript基础知识(三个判断、三个循环)
三个判断 if…else…只会执行其中一个条件 如果if条件中只有一个值,那么会默认转布尔: if(1=="1"){ // 当括号中条件为true时,执行此处的代码 console ...
- Codeforces 1090M - The Pleasant Walk - [签到水题][2018-2019 Russia Open High School Programming Contest Problem M]
题目链接:https://codeforces.com/contest/1090/problem/M There are n houses along the road where Anya live ...
- python 当前时间多加一天、一小时、一分钟
datetime模块 import datetime # 获取当前时间 print(datetime.datetime.now()) # 2017-07-15 15:01:24.619000 # 格式 ...
- python框架之Flask(3)-Blueprint(蓝图)
蓝图 用途 给开发者提供清晰的目录结构. 使用 目录结构 1.创建项目. 2.在项目目录下创建与项目名同名文件夹. 3.在 test_prj 文件夹下创建 __init__.py 文件,并在其中实例化 ...
- python中的双冒号作用
Python序列切片地址可以写为[开始:结束:步长],其中的开始和结束可以省略. 1. range(n)生成[0,n)区间整数 2. 开始start省略时,默认从第0项开始 3. 结尾省略的时候,默认 ...
- 家庭记账本之微信小程序(二)
在网上查阅了资料后,了解到了在完成微信小程序之前要完成注册阶段的工作,此次在这介绍注册阶段的流程. 1.首先你要确定小程序的定位.目的以及文案资料等(准备工作). 2.打开微信公众平台官网,点击右上角 ...
- ajax 显示,删除,批量删除,修改反填功能实现
1.页面代码 <body> <h1>显示所有员工信息</h1> <input id="Button1" type="button ...