最近在学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权限管理入门程序的更多相关文章

  1. shiro权限管理的框架-入门

    shiro权限管理的框架 1.权限管理的概念 基本上涉及到用户参与的系统都要进行权限管理,权限管理属于系统安全的范畴,权限管理实现对用户访问系统的控制,按照安全规则或者安全策略控制用户可以访问而且只能 ...

  2. (补漏)Springboot2.0 集成shiro权限管理

    原文Springboot2.0 集成shiro权限管理 一.关于停止使用外键. 原本集成shiro建立用户.角色.权限表的时候使用了外键,系统自动创建其中两个关联表,用@JoinTable.看起来省事 ...

  3. (39.4) Spring Boot Shiro权限管理【从零开始学Spring Boot】

    在读此文章之前您还可能需要先了解: (39.1) Spring Boot Shiro权限管理[从零开始学Spring Boot] http://412887952-qq-com.iteye.com/b ...

  4. (39.3) Spring Boot Shiro权限管理【从零开始学Spring Boot】

    在学习此小节之前您可能还需要学习: (39.1) Spring Boot Shiro权限管理[从零开始学Spring Boot] http://412887952-qq-com.iteye.com/b ...

  5. (39.2). Spring Boot Shiro权限管理【从零开始学Spring Boot】

    (本节提供源代码,在最下面可以下载) (4). 集成Shiro 进行用户授权 在看此小节前,您可能需要先看: http://412887952-qq-com.iteye.com/blog/229973 ...

  6. (39.1) Spring Boot Shiro权限管理【从零开始学Spring Boot】

    (本节提供源代码,在最下面可以下载)距上一个章节过了二个星期了,最近时间也是比较紧,一直没有时间可以写博客,今天难得有点时间,就说说Spring Boot如何集成Shiro吧.这个章节会比较复杂,牵涉 ...

  7. Spring Boot Shiro 权限管理 【转】

    http://blog.csdn.net/catoop/article/details/50520958 主要用于备忘 本来是打算接着写关于数据库方面,集成MyBatis的,刚好赶上朋友问到Shiro ...

  8. SpringMVC+Shiro权限管理(转载)

    源码 http://pan.baidu.com/s/1pJzG4t1 SpringMVC+Shiro权限管理 博文目录 权限的简单描述 实例表结构及内容及POJO Shiro-pom.xml Shir ...

  9. Spring Boot Shiro 权限管理

    Spring Boot Shiro 权限管理 标签: springshiro 2016-01-14 23:44 94587人阅读 评论(60) 收藏 举报 .embody{ padding:10px ...

随机推荐

  1. CXF整合Sping与Web容器

    1.创建HelloWorld 接口类 package com.googlecode.garbagecan.cxfstudy.helloworld; import javax.jws.WebMethod ...

  2. Spring-boot(二)--thymeleaf

    @Controller @RequestMapping("/") public class MessageController { private final MessageRep ...

  3. mysql存储emoji问题

    前一段时间,项目中需要在数据库中存储emoji,由于编码格式不对,直接导致数据库报错,后来修改mysql的编码,就解决了 emoji符号实际上是文本,并不是图片,它们仅仅显示为图片 在mysql5.5 ...

  4. win10下Redis安装

    环境:win64 1.因为Redis官方不支持Windows,所在只能在GitHub上下载,下载地址:https://github.com/ServiceStack/redis-windows/blo ...

  5. MySQL数据查询

    数据查询语言DQL select [all | distinct] 字段或表达式列表 [from子句] [where子句] [group by子句] [having子句] [order by子句] [ ...

  6. 主席树||可持久化线段树+离散化 || 莫队+分块 ||BZOJ 3585: mex || Luogu P4137 Rmq Problem / mex

    题面:Rmq Problem / mex 题解: 先离散化,然后插一堆空白,大体就是如果(对于以a.data<b.data排序后的A)A[i-1].data+1!=A[i].data,则插一个空 ...

  7. F#周报2019年第5期

    新闻 Ionide的Open Collective 发布SAFE至Google Cloud Kubernetes引擎 .NET Core 3预览2 ASP.NET Core在.NET Core 3预览 ...

  8. 使用Xshell调用linux的图形界面!

    环境说明: OS: centos 6.5 64位,最小化安装. Xmanager: 17.0.0.714 1.设置Xshell 2.将操作系统安装如下包 yum  install xclock xte ...

  9. Socket 的网络编程

    socket 网络编程的服务端: 1) 创建socket 套接字. 2) 和socket绑定主机地址和端口 3) socket 主动监听端口,看又没有来连接. 4) 当执行到 accept() 时, ...

  10. Linux之grep的使用

    基本介绍 Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expression Print,表示全 ...