Shiro的基本概念与快速入门

【模型转换】将.mindir文件转换成.ms文件(Windows篇) 首先需要在MindSpore中训练好并经过评估可用的模型,可以以标准格式(例如onnx, mindir等)导出,得到.mindir模型文件(例如lenet.mindir)。为了将模型部署到自定义应用中,还需要将其转换为更为紧凑和高效的ms格式模型,用于在MindSpore-Lite环境中推理,这可以通过MindSpore Lite提供的模型转换工具converter_lite完成。 阅读详情

目录

什么是Shiro

Shiro的功能 

Shiro的架构

Shiro快速开始

分析Shiro的执行逻辑 


 

什么是Shiro

 

正如它的Logo所写,简单的java安全框架

 

 

 

Shiro的功能 

 

  • Authentication:身份认证
  • Authorization:权限验证
  • Session Manager:会话管理
  • Cryptography:加密
  • Web Support:Web环境支持
  • Caching:缓存
  • Concurrency:多线程应用的并发验证
  • Testing:测试
  • Run As:允许一个用户假装为另一个用户的身份进行访问
  • Remember Me:记住我~

 

 

Shiro的架构

 

 

 

Shiro快速开始

 

 1.新建一个maven项目,搞一个Shiro的子模块

2.导入jar包

    <dependencies>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-core</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.21</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.21</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
    </dependencies>

3.新建log4j.properties文件

log4j.rootLogger=INFO, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m %n

# General Apache libraries
log4j.logger.org.apache=WARN

# Spring
log4j.logger.org.springframework=WARN

# Default Shiro logging
log4j.logger.org.apache.shiro=INFO

# Disable verbose logging
log4j.logger.org.apache.shiro.util.ThreadContext=WARN
log4j.logger.org.apache.shiro.cache.ehcache.EhCache=WARN

4.新建shiro.ini文件,建立安装个ini插件,这样ini文件中的代码会有色彩标记

[users]
# user 'root' with password 'secret' and the 'admin' role
root = secret, admin
# user 'guest' with the password 'guest' and the 'guest' role
guest = guest, guest
# user 'presidentskroob' with password '12345' ("That's the same combination on
# my luggage!!!" ;)), and role 'president'
presidentskroob = 12345, president
# user 'darkhelmet' with password 'ludicrousspeed' and roles 'darklord' and 'schwartz'
darkhelmet = ludicrousspeed, darklord, schwartz
# user 'lonestarr' with password 'vespa' and roles 'goodguy' and 'schwartz'
lonestarr = vespa, goodguy, schwartz

# -----------------------------------------------------------------------------
# Roles with assigned permissions
#
# Each line conforms to the format defined in the
# org.apache.shiro.realm.text.TextConfigurationRealm#setRoleDefinitions JavaDoc
# -----------------------------------------------------------------------------
[roles]
# 'admin' role has all permissions, indicated by the wildcard '*'
admin = *
# The 'schwartz' role can do anything (*) with any lightsaber:
schwartz = lightsaber:*
# The 'goodguy' role is allowed to 'drive' (action) the winnebago (type) with
# license plate 'eagle5' (instance specific id)
goodguy = winnebago:drive:eagle5

5.把Quickstart.java复制到java目录下,启动这个类

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Simple Quickstart application showing how to use Shiro's API.
 *
 * @since 0.9 RC2
 */
public class Quickstart {

    private static final transient Logger log = LoggerFactory.getLogger(Quickstart.class);


    public static void main(String[] args) {

        // The easiest way to create a Shiro SecurityManager with configured
        // realms, users, roles and permissions is to use the simple INI config.
        // We'll do that by using a factory that can ingest a .ini file and
        // return a SecurityManager instance:

        // Use the shiro.ini file at the root of the classpath
        // (file: and url: prefixes load from files and urls respectively):
        Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
        SecurityManager securityManager = factory.getInstance();

        // for this simple example quickstart, make the SecurityManager
        // accessible as a JVM singleton.  Most applications wouldn't do this
        // and instead rely on their container configuration or web.xml for
        // webapps.  That is outside the scope of this simple quickstart, so
        // we'll just do the bare minimum so you can continue to get a feel
        // for things.
        SecurityUtils.setSecurityManager(securityManager);

        // Now that a simple Shiro environment is set up, let's see what you can do:

        // get the currently executing user:
        Subject currentUser = SecurityUtils.getSubject();

        // Do some stuff with a Session (no need for a web or EJB container!!!)
        Session session = currentUser.getSession();
        session.setAttribute("someKey", "aValue");
        String value = (String) session.getAttribute("someKey");
        if (value.equals("aValue")) {
            log.info("Retrieved the correct value! [" + value + "]");
        }

        // let's login the current user so we can check against roles and permissions:
        if (!currentUser.isAuthenticated()) {
            UsernamePasswordToken token = new UsernamePasswordToken("lonestarr", "vespa");
            token.setRememberMe(true);
            try {
                currentUser.login(token);
            } catch (UnknownAccountException uae) {
                log.info("There is no user with username of " + token.getPrincipal());
            } catch (IncorrectCredentialsException ice) {
                log.info("Password for account " + token.getPrincipal() + " was incorrect!");
            } catch (LockedAccountException lae) {
                log.info("The account for username " + token.getPrincipal() + " is locked.  " +
                        "Please contact your administrator to unlock it.");
            }
            // ... catch more exceptions here (maybe custom ones specific to your application?
            catch (AuthenticationException ae) {
                //unexpected condition?  error?
            }
        }

        //say who they are:
        //print their identifying principal (in this case, a username):
        log.info("User [" + currentUser.getPrincipal() + "] logged in successfully.");

        //test a role:
        if (currentUser.hasRole("schwartz")) {
            log.info("May the Schwartz be with you!");
        } else {
            log.info("Hello, mere mortal.");
        }

        //test a typed permission (not instance-level)
        if (currentUser.isPermitted("lightsaber:wield")) {
            log.info("You may use a lightsaber ring.  Use it wisely.");
        } else {
            log.info("Sorry, lightsaber rings are for schwartz masters only.");
        }

        //a (very powerful) Instance Level permission:
        if (currentUser.isPermitted("winnebago:drive:eagle5")) {
            log.info("You are permitted to 'drive' the winnebago with license plate (id) 'eagle5'.  " +
                    "Here are the keys - have fun!");
        } else {
            log.info("Sorry, you aren't allowed to drive the 'eagle5' winnebago!");
        }

        //all done - log out!
        currentUser.logout();

        System.exit(0);
    }
}

下图代表快速搭建shiro成功~

 

 

分析Shiro的执行逻辑 

 

 

  • subject:应用代码直接交互的对象,subject代表了当前的用户,这个用户不一定是一个具体的人,与当前应用交互的任何东西都是Subject,如网络爬虫,机器人等。与subject交互的所有内容都委托给了securitymanager,subject其实是一个门面,securitymanager才是真正的执行者
  • sucuritymanager:安全管理器,所有与安全有关的操作都会与它交互,并且管理着所有subject,可以看出它是shiro的核心,负责与shiro的其他组件进行交互,相当于springmvc中的dispatcherservlet
  • realm:当需要进行用户、角色、权限验证时,需要从realm获取相应的用户信息,可以把realm看做datasource
大语言模型在构建UNSPSC 分类数据中的应用 UNSPSC 是联合国标准产品和服务代码。本文研究如何利用大语言模型生成分类系统的分析 阅读详情

相关推荐

CH569 USBSS库函数分析

CH569 USB3.0 解析

havc_W的博客 7683

2021-11-25 shiro-core IniRealm源码分析(一)

2021SC@SDUSC IniRealm的类继承关系图 1.TextConfigurationRealm SimpleAccountRealm,它可以用于验证在启动时创建的初始用户、角色和权限对象的基于文本的配置。 每个用户帐户定义指定用户的用户名、密码和角色。 每个角色定义指定一个名称和一个可选的分配权限集合。 可以为用户分配角色,并且可以为角色分配权限。 通过传递关联,每个用户“拥有”他们所有角色的权限。 用户和用户到角色的定义通过setUserDefinitions方法指定,角色到权限的定义通过

Niall_Tonshall的博客 335

告别编译臃肿!手把手教你为Arduino UNO打造超轻量级U8g2中文字库(附完整工具链)

本文详细介绍了如何为Arduino UNO打造超轻量级U8g2中文字库,解决默认字库占用大量存储空间的问题。通过自定义字体工具链,提取项目所需汉字并生成精简字库,显著减少程序体积。文章包含完整实现步骤、优化技巧及实战经验,帮助开发者在资源受限的微控制器上高效显示中文。

weixin_29274337的博客 255

学习Shiro随笔

引言 这里记录我刚学习的Shiro体会,我觉得shiro和Spring Security功能都一样都是认证和授权来拦截url但是各有各的好处 后者功能比较多,前者更适合和SSM整合 Shiro三大重点 我这里做的是一个Springboot例子简单介绍 pom依赖 <dependency> <groupId>org.apache.shiro</groupId&g...

jiohfgj的博客 219

亚马逊SP-API授权实战:从OAuth流程到Refresh Token获取

本文详细解析了亚马逊SP-API授权流程,从OAuth认证到Refresh Token获取的全过程。通过实战经验分享,帮助开发者快速掌握Marketplace Appstore、Website Workflow和自行授权三种方式,解决常见错误如MD5100和MD9999,并提供了安全存储Refresh Token的最佳实践。

weixin_30379531的博客 518

深入解析安卓/Linux固件:从DTB到DTS的反编译实战

本文详细介绍了如何从安卓/Linux设备固件中提取并反编译DTB文件,将其转换为可读的DTS源码。通过实战步骤,包括拆解boot.img、处理resource.img以及使用dtc工具,帮助开发者深入理解设备硬件配置,为固件定制、驱动调试和系统移植提供关键支持。

weixin_29274337的博客 339

2_springboot_shiro_jwt_多端认证鉴权_Realm与匹配器

Realm 源码分析,自定义Realm,自定义匹配器,鉴权异常处理

paopao_wu的专栏 1174

Hadoop与Kafka集群部署与优化实践指南

分布式系统是现代大数据处理的核心架构,其中Hadoop作为分布式存储与计算框架,Kafka作为分布式消息队列系统,共同构成了实时数据处理的基础设施。通过HDFS实现海量数据存储,结合YARN进行资源调度,而Kafka则保障了数据流的实时传输与高吞吐。这种技术组合在电商用户行为分析、物联网数据采集等场景中表现卓越。部署过程中需关注硬件资源配置、关键参数调优以及集群监控方案,例如通过调整HDFS块大小和Kafka partition数量来优化性能。合理运用Flume、Spark Streaming等工具可实现系

weixin_29061997的博客 358

Shrio认证详解+自定义Realm

Authentication(身份认证)是Shiro权限控制的第一步,用来告诉系统你就是你。 在提交认证的时候,我们需要给系统提交两个信息: Principals:是一个表示用户的唯一属性,可以是用户名,邮箱之类的。 Credentials:是证明用户身份的证书,可以是密码或者指纹之类的。 认证主要分为三步: 1、收集认证信息 2、提交认证信息 3、如果认证成功,则允许访问...

dengjuyan2649的博客 218

第三节:Vben Admin 最新 v5.0 (vben5) + Python Flask 快速入门 - 对接后端登录接口(上)

这里是Vben Admin V5版本实战体验,上一节我们前端已正常运行,但是没有实现登录。本节的重点是对接后端接口。上一节地址:第一节:Vben Admin 最新 v5.0初体验第二节:Vben Admin 登录逻辑梳理和对接后端准备后端我们采用Python的Flask项目,Flask-SQLAlchemy管理数据库模型,Flask-Migrate进行模型迁移。参考版本如下:Flask3.0.23.1.1到这里,登录接口完成,下一步要实现获取用户信息和权限的接口功能。

cuiwin的专栏 1859

多agv系统调度的MATLAB仿真

从起点出发,到货物点领取货物最后到卸货点,以完成任务总时间最短为目标进行单目标优化,约束条件为,任务不冲突,路径不冲突,要能实现路径规避 ,4-6台agv一起工作。左右货架间隔可通过1个agv,上下货架间隔可通过两个agv,通道为双向行驶通道。一台agv只能带一个货物,优化目标为完成任务总的时间最短,agv的速度是匀速,转弯也不会减速,取货物时间为固定值。上面的图里面货物看为正方形跟agv一样的长度大小,agv试做是跟货物一样大小的正方形agv的速度是每秒1个车身。多台agv一起完成...

FPGA/MATLAB学习教程/源码/项目合作开发 7563

Shiro源码分析-初始化-Realm

在上一篇介绍SecurityManager的初始化过程中,也有realm的粗略介绍。 realm的概念在安全领域随处可见: 各种中间件的realm、spring security的realm、shiro的realm。。。如下: tomcat的realm:[url]http://tomcat.apache.org/tomcat-7.0-doc/realm-howto.html[/url] w...

Dead_Knight的专栏 381

华为OD机试 - 报文响应时间 - 贪心算法、位运算(Python/JS/C/C++ 2024 E卷 200分)

贪心算法是在每一步选择中都做出当前最优的选择,期望通过局部最优解推导出全局最优解的算法。

学Java,找哪吒 1757

Shiro基本使用springboot集成Shiro

这里写目录标题Shiro简介导入Shiro依赖配置文件HelloShiro:简单的快速入门应用程序,展示了如何使用Shiro的API。 Shiro简介 什么是Shiro Apache Shiro是一个Java的安全(权限)框架. Shiro可以非常容易的开发出足够好的应用,其不仅可以用在JavaSE环境,也可以用在JavaEE环境。 Shiro可以完成,认证,授权,加密,会话管理,Web集成,缓存等。 导入Shiro依赖 <dependency> <groupI

yang13676084606的博客 420

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Spring Boot Shiro 入门

1. 概述 艿艿:本文是《芋道 Spring Boot 安全框架 Spring Security 入门》的姊妹篇,所以开头就“重复”再来一遍,嘿嘿。 基本上,在所有的开发的系统中,都必须做认证(authentication)和授权(authorization),以保证系统的安全性。???? 考虑到很多胖友对认证和授权有点分不清楚,艿艿这里引用一个网上有趣的例子: FROM《认证 (aut...

weixin_42073629的博客 925

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Shiro基础入门篇

对Shiro安全框架的详解,主要理解认证和授权!

Czh的博客 727

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Apache Shiro入门

Apache Shiro入门@(Shiro)[shiro,安全框架]Apache Shiro入门 Apache Shiro基本概述 Apache Shiro基本概念 使用Shiro能做什么 Shiro的特性 Shiro框架的调用流程 Shiro框架 快速入门案例 引入Maven依赖 在webxml中配置spring框架提供的过滤器用于整合shiro框架 在Spring配置文件中配置bean 配置安全

Switch的博客 4164

Spring Boot 安全框架 Shiro 入门

1. 概述 Apache Shiro 是 Java 的一个安全框架。目前,使用 Apache Shiro 的人越来越多,因为它相当简单,对比 Spring Security,可能没有 Spring Security 做的功能强大,但是在实际工作时可能并不需要那么复杂的东西,所以使用小而简单的 Shiro 就足够了。对于它俩到底哪个好,这个不必纠结,能更简单的解决项目问题就好了。 以打飞机举例子: 【认证】你要登机,你需要出示你的 passport 和 ticket,passport 是为了证明你张三确实是你

Lans2716的博客 475

Shiro的简单入门

Shiro的简单入门1、什么是Shiro2、快速入门3、在SpringBoot整合Shiro1、在IDEA创建一个SpringBoot工程2、导入Shiro的依赖3、编写简单的页面和Controller4、编写ShiroConfig和UserRealm5、实现登录拦截6、实现用户认证7、实现请求授权1、权限过滤2、授权8、整合Thymeleaf 1、什么是Shiro shiro (java安全框架) Apache Shiro是一个强大且易用的Java安全框架,执行身份验证、授权、密码和会话管理。使用Shir

RRRRengar的博客 304

SpringBoot整合Shiro框架

目录 1、Shiro简介 1.1、Shiro是什么? 1.2、有哪些功能? 1.3、Shiro架构(外部) 2、快速入门(QuickStartShiro) 2.1、项目结构 2.2、导入shiro依赖,这是我的pom所有依赖。(pom.xml) 2.3、相关配置文件 (1)log4j.properties——官网 (2)shiro.ini——官网 (3)启动类 Quickstart——官网 3、SpringBoot集成Shiro框架 3.1SpringBoot整合Shir...

koko创作 8905

springboot+mybatis整合shiro

springboot+mybatis整合shiro 简单学习了一下shiro,简单记录一下。 1.shiro是什么 Apache Shiro是一个强大且易用的Java安全框架,执行身份验证、授权、密码和会话管理。使用Shiro的易于理解的API,您可以快速、轻松地获得任何应用程序,从最小的移动应用程序到最大的网络和企业应用程序。 2.主要功能 shiro主要有三大功能模块: Subject:主体,一般指用户。 SecurityManager:安全管理器,管理所有Subject,可以配合内部安全

心藏_的博客 469

SpringBoot集成Shiro

1、Shiro简介 1.1、什么是Shiro? Apache Shiro 是一个java的安全(权限)框架。 Shiro 可以非常容易的开发出足够好的应用,其不仅可以用在JavaSE环境,也可以用在JavaEE环境。 Shiro可以完成,认证,授权,加密,会话管理,Web集成,缓存等。 shiro官网 下载: 1.2、shiro有哪些功能? Authentication:身份认证、登录,验证用户是不是拥有相应的身份; Authorization:授权,即权限验证,验证某个已认证的用户是否拥有某

Jiao的博客 232

Shiro安全框架最全面解析

Shiro 一、权限框架介绍 1. 什么是权限管理 权限管理属于系统安全的范畴,权限管理实现对用户访问系统的控制,按照安全规则或者安全策略控制用户可以访问而且只能访问自己被授权的资源。   权限管理包括用户身份认证和授权两部分,简称认证授权。对于需要访问控制的资源用户首先经过身份认证,认证通过后用户具有该资源的访问权限方可访问。 1.1 用户身份认证 身份认证,就是判断一个用户是否为合法用户的处理过程。最常用的简单身份认证方式是系统通过核对用户输入的用户名和口令,看其是否与系统中存储的该用户的用户名和口令一

S_mengyong的博客 1537

从零开始认识Shiro,基于ini文件认识Shiro

从零开始认识shiro Apache Shiro是一个强大且易用的Java安全框架,执行身份验证、授权、密码学和会话管理。使用Shiro的易于理解的API,您可以快速、轻松地获得任何应用程序,从最小的移动应用程序到最大的网络和企业应用程序。上个月写了一个在线教育的项目用到了shiro权限控制,这几天又复盘了一下,对其进行了深入探究,来总结一下。本文只是简单介绍Shiro,并没有进行详细的整合 1. shiro简介以及功能描述 Shiro 是 Java 的一个安全框架。目前,使用 Apache Shiro 的

lh_mnbj的博客 352

补习系列(6)- springboot 整合 shiro 一指禅

目标 了解ApacheShiro是什么,能做什么; 通过QuickStart 代码领会 Shiro的关键概念; 能基于SpringBoot 整合Shiro 实现URL安全访问; 掌握基于注解的方法,以实现灵活定制。 一、Apache Shiro是什么 Apache Shiro 是一个强大且易用的Java安全框架,用于实现身份认证、鉴权、会话管理及加密功能。 框架提供了非常简单且易于上手的...

华为云官方博客 1513

Shiro笔记

1. Shiro是什么?简介 http://jinnianshilongnian.iteye.com/blog/2018936 2.Shiro入门实例 https://www.cnblogs.com/janes/p/7553198.html 3.Shiro简单登录实例 https://blog.youkuaiyun.com/w_x_z_/article/details/69734028 ...

a13141289705的博客 66
上一篇: Maven使用镜像加速+Maven使用JDK1.8编译
下一篇: Springboot整合Shiro的认证功能
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值