导入依赖

<dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-core</artifactId>
    <version>1.2.3</version>
</dependency>

<dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-web</artifactId>
    <version>1.2.3</version>
</dependency>

在resources目录下创建shiro-first.ini文件

[users]
admin=111111
aaaaa=aaaaa

测试代码

/**
 * 从shiro-first.ini文件中的账号密码进行认证
 */
@Test
public void testLoginAndLogout(){
    //通过ini配置文件创建SecurityManager工厂
    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro/shiro-first.ini");
    //创建SecurityManager
    SecurityManager securityManager = factory.getInstance();
    //将SecurityManager设置在当前的运行环境中
    SecurityUtils.setSecurityManager(securityManager);
    //从SecurityUtils中获取一个subject
    Subject subject = SecurityUtils.getSubject();
    //创建令牌
    UsernamePasswordToken token = new UsernamePasswordToken("admin", "111111");
    subject.login(token);
    System.out.println("认证状态:"+subject.isAuthenticated());
    subject.logout();
    System.out.println("认证状态:"+subject.isAuthenticated());
}

输出结果

认证状态:true
认证状态:false

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

  1. Shiro入门 - 通过ini文件进行授权

    shiro-permission.ini #用户 [users] #admin的密码是111111,此用户具有role1.role2两个角色 admin=111111,role1,role2 zhan ...

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

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

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

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

  4. shiro入门与认证原理

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

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

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

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

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

  7. 用户认证授权和Shiro入门

    1.权限管理基础(认证和授权): 前言 本文主要讲解的知识点有以下: 权限管理的基础知识 模型 粗粒度和细粒度的概念 回顾URL拦截的实现 Shiro的介绍与简单入门 一.Shiro基础知识 在学习S ...

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

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

  9. shiro解析ini文件

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

随机推荐

  1. 第十四节、FAST角点检测(附源码)

    在前面我们已经陆续介绍了许多特征检测算子,我们可以根据图像局部的自相关函数求得Harris角点,后面又提到了两种十分优秀的特征点以及他们的描述方法SIFT特征和SURF特征.SURF特征是为了提高运算 ...

  2. Overloaded Fuction 调用——到底使用的是谁的函数

    #include <stdio.h> class Base{ public: int a(){ ; } }; class Inherit:public Base{ public: int ...

  3. log4net 开启内部调试

    大家都在用LOG4NET,但这是封装好的,在有时我们找不到原因时会想到是不是发生在里面,比如,配置好了日志记录到数据库(Mysql.Oracle.Sql Server)等,但就是记录不上,又找不到原因 ...

  4. sql>desc 存储包——查看包内存储过程、函数

    sql>desc dbms_random: 查询dbms_random包下的存储过程和函数 a. value() 用于返回两个数值之间的随机数, value (low, high) SQL &g ...

  5. springcloud学习笔记

    一.什么是springcloud,有什么作用 Spring Cloud是一系列框架的有序集合.它利用Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发,如服务发现注册.配置中心.消 ...

  6. Hadoop记录-HDFS balancer配置

    HDFS balancer配置(可通过CM配置)dfs.datanode.balance.max.concurrent.moves 并行移动的block数量,默认5 dfs.datanode.bala ...

  7. 解决Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.17 问题

    详细报错如下 Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.17 from http://maven ...

  8. mysql批量替换数据

    如题,项目域名迁移,导致原来商城的商品图片无法查看,地址错误. 怎么办?修改数据库图片路径呗!什么几千行呐,开玩笑.这个任务没人接,只有我干咯! 怎么也得不少时间吧,好吧半天,这是上面的要求. 有聪明 ...

  9. Win10升级.NET Framework 3.5或2.0遇到错误0x800f081f怎么办

    为了让win10系统更好地运行游戏,很多玩家都会在电脑中安装.NET Framework 3.5或.NET Framework 2.0.不过,部分用户在更新升级.NET Framework 3.5和2 ...

  10. 自学python 2.

    1.T or F 1>1 or 3<4 or 4>5 and 2>1 and 9>8 or 7<6 t not 2>1 and 3<4 or 4> ...