shiro mgt包下DefaultSubjectFactory类

2023-10-20 15:10

本文主要是介绍shiro mgt包下DefaultSubjectFactory类,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

2021SC@SDUSC
DefaultSubjectFactory类图如下:
在这里插入图片描述

创建DelegatingSubject 实例的默认SubjectFactory实现。
简单来说就是通过工厂模式产生DelegatingSubject实例。

该类只有两个方法:

1.createSubject

public Subject createSubject(SubjectContext context) {SecurityManager securityManager = context.resolveSecurityManager();Session session = context.resolveSession();boolean sessionCreationEnabled = context.isSessionCreationEnabled();PrincipalCollection principals = context.resolvePrincipals();boolean authenticated = context.resolveAuthenticated();String host = context.resolveHost();return new DelegatingSubject(principals, authenticated, host, session, sessionCreationEnabled, securityManager);}

通过传入的上下文对象context来创建新的DelegatingSubject对象,典型的工厂模式应用。

2.newSubjectInstance

protected Subject newSubjectInstance(PrincipalCollection principals, boolean authenticated, String host,Session session, SecurityManager securityManager) {return new DelegatingSubject(principals, authenticated, host, session, true, securityManager);}

函数作用域为protected,留给子类继承,如果需要实例化自定义 Subject 类,就直接覆盖 SubjectContext。

总结

DefaultSubjectFactory类是工厂,createSubject函数通过context对象创建新的DelegatingSubject实例,newSubjectInstance可以通过自定义的参数来创建DelegatingSubject实例

这篇关于shiro mgt包下DefaultSubjectFactory类的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/247898

相关文章

【Shiro】Shiro 的学习教程(三)之 SpringBoot 集成 Shiro

目录 1、环境准备2、引入 Shiro3、实现认证、退出3.1、使用死数据实现3.2、引入数据库,添加注册功能后端代码前端代码 3.3、MD5、Salt 的认证流程 4.、实现授权4.1、基于角色授权4.2、基于资源授权 5、引入缓存5.1、EhCache 实现缓存5.2、集成 Redis 实现 Shiro 缓存 1、环境准备 新建一个 SpringBoot 工程,引入依赖:

【Shiro】Shiro 的学习教程(二)之认证、授权源码分析

目录 1、背景2、相关类图3、解析3.1、加载、解析阶段3.2、认证阶段3.3、授权阶段 1、背景 继上节代码,通过 debug 进行 shiro 源码分析。 2、相关类图 debug 之前,先了解下一些类的结构图: ①:SecurityManager:安全管理器 DefaultSecurityManager: RememberMeManager:实现【记住我】功能

【Shiro】Shiro 的学习教程(一)之快速入门

目录 1、Shiro 简介2、Shiro 认证、授权2.1、认证2.2、授权 3、快速入门4、自定义 Realm5、加密6、实现授权 1、Shiro 简介 Shiro 官网:https://shiro.apache.org/ Shiro 是一个功能强大且易于使用的 Java 安全框架,它执行身份验证、授权、加密和会话管理。使用 Shiro 易于理解的 API,您可以快速轻松地保

shiro session 监听

spring 使用 shiro 后,由于shiro重新封装了原有的session,所以不能再使用原来的session监听方法了 (1)在shiro配额只文件中设置监听类   <!-- shiroSessionListener  监听类--><bean id="shiroSessionListener" class="com.listener.ShiroSessionListener"></

Shiro身份认证流程

http://www.toutiao.com/a6353832181929279746/?tt_from=mobile_qq&utm_campaign=client_share&app=explore_article&utm_source=mobile_qq&iid=5840657922&utm_medium=toutiao_ios

Shiro-721漏洞详解及复现

之前有些Shiro-550反序列化漏洞的文章Shiro-550漏洞详解及复现_shiro框架漏洞-CSDN博客 这里简单补充一下关于Shiro-721漏洞的内容。 目录 Shiro-721漏洞原理 Padding Oracle攻击 利用条件 影响版本 漏洞复现 Shiro-721漏洞原理 Shiro-721用到的加密方式是AES-128-CBC,跟Shiro-550最大的

进阶SpringBoot之 Shiro(6)整合 Thymeleaf

Subject:用户 SecurityManager:管理所有用户 Realm:连接数据 pom.xml 导入 thymeleaf-extras-shiro 的 jar 包,整合 shiro-thymeleaf <!-- shiro-thymeleaf 整合 --><dependency><groupId>com.github.theborakompanioni</grou

Shiro的认证原理(Subject#login的背后故事)

登录操作一般都是我们触发的: Subject subject = SecurityUtils.getSubject();AuthenticationToken authenticationToken = new ...subject.login(authenticationToken); Subject的登录将委托给SecurityManager,SecurityManager的logi

Shiro过滤器的维护与匹配执行

servlet的初始化会触发核心过滤器的创建: public Object getObject() throws Exception {if (instance == null) {instance = createInstance();}return instance;} 在createInstance方法中会调用 FilterChainManager manager = create

shiro的使用入门

shiro是一个权限控制框架,因为项目需要自己看了看,在这里把所有学到的分享一下。shiro主要由AuthorizationInfo、AuthenticationInfo、Subject构成一个权限环境,doGetAuthenticationInfo方法是用户登录的使用调用的( subject.login(token);),doGetAuthorizationInfo方法是在用户进行权限验