SpringSecurity2

AuthenticationManagerBuilder

在这里插入图片描述
继承了之前提到的AbstractConfiguredSecurityBuilder构造器
在这里插入图片描述
postProcess安全对象的后处理,那么ProviderManager是什么

ProviderManager

Authentication

public interface Authentication extends Principal, Serializable {/**** 权限*/Collection<? extends GrantedAuthority> getAuthorities();/**** 凭证,用户名/密码登陆方式密码就是凭证*/Object getCredentials();/**** 存放ip或者证书序列号*/Object getDetails();/*** 要进行身份验证的主体的身份。对于带有用户名和密码的身份验证请求,这将是用户名。调用方应填充身份验证请求的主体*/Object getPrincipal();/*** 判断是否被认证*/boolean isAuthenticated();/*** 设置authenticated属性*/void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException;}

AuthenticationProvider

策略模式典型实现
认证登录不仅仅是账户密码登录,还可能是QQ、微信登录等
之后新增只需要新继承这个Provider即可,符合开闭模式,保证只新增代码,不修改以往代码

public interface AuthenticationProvider {/*** 使用与 AuthenticationManager.authenticate(Authentication) 相同的协定执行身份验证。* 完全经过身份验证的对象,包括凭据。*/Authentication authenticate(Authentication authentication) throws AuthenticationException;/*** 如果这AuthenticationProvider支持指示Authentication的对象,则返回true。*/boolean supports(Class<?> authentication);}

AuthenticationManager

public interface AuthenticationManager {/*** Attempts to authenticate the passed {@link Authentication} object, returning a* fully populated <code>Authentication</code> object (including granted authorities)* if successful.* <p>* An <code>AuthenticationManager</code> must honour the following contract concerning* exceptions:* <ul>* <li>A {@link DisabledException} must be thrown if an account is disabled and the* <code>AuthenticationManager</code> can test for this state.</li>* <li>A {@link LockedException} must be thrown if an account is locked and the* <code>AuthenticationManager</code> can test for account locking.</li>* <li>A {@link BadCredentialsException} must be thrown if incorrect credentials are* presented. Whilst the above exceptions are optional, an* <code>AuthenticationManager</code> must <B>always</B> test credentials.</li>* </ul>
*尝试对传递 Authentication 的对象进行身份验证,如果成功,则返回完全填充的 Authentication 对象
*必须 AuthenticationManager 履行以下有关例外情况的合同:
* 如果帐户被禁用,AuthenticationManager则必须抛出 ADisabledException,并且可以测试此状态。
* 如果帐户被锁定,AuthenticationManager则必须抛出 ALockedException,并且可以测试帐户锁定。
* 如果提供不正确的凭据,则必须抛出 A BadCredentialsException 。虽然上述例外是可选的, AuthenticationManager 但必须 始终 测试凭据。*/Authentication authenticate(Authentication authentication) throws AuthenticationException;}

在这里插入图片描述
关键属性

// 事件发布器private AuthenticationEventPublisher eventPublisher = new NullEventPublisher();
// 之前说的策略,用自己授权private List<AuthenticationProvider> providers = Collections.emptyList();protected MessageSourceAccessor messages = SpringSecurityMessageSource.getAccessor();
// 父类,使用父类授权private AuthenticationManager parent;private boolean eraseCredentialsAfterAuthentication = true;@Overridepublic Authentication authenticate(Authentication authentication) throws AuthenticationException {Class<? extends Authentication> toTest = authentication.getClass();AuthenticationException lastException = null;AuthenticationException parentException = null;Authentication result = null;Authentication parentResult = null;int currentPosition = 0;int size = this.providers.size();// 循环认证for (AuthenticationProvider provider : getProviders()) {if (!provider.supports(toTest)) {continue;}if (logger.isTraceEnabled()) {logger.trace(LogMessage.format("Authenticating request with %s (%d/%d)",provider.getClass().getSimpleName(), ++currentPosition, size));}try {result = provider.authenticate(authentication);if (result != null) {/**** 存放ip或者证书序列号*/// Object getDetails();copyDetails(authentication, result);break;}}catch (AccountStatusException | InternalAuthenticationServiceException ex) {prepareException(ex, authentication);throw ex;}catch (AuthenticationException ex) {lastException = ex;}}// 找不到对应的Authentication,则调用父类的授权if (result == null && this.parent != null) {try {parentResult = this.parent.authenticate(authentication);result = parentResult;}catch (ProviderNotFoundException ex) {}catch (AuthenticationException ex) {parentException = ex;lastException = ex;}}if (result != null) {// 擦除凭证信息if (this.eraseCredentialsAfterAuthentication && (result instanceof CredentialsContainer)) {((CredentialsContainer) result).eraseCredentials();}if (parentResult == null) {this.eventPublisher.publishAuthenticationSuccess(result);}return result;}if (lastException == null) {lastException = new ProviderNotFoundException(this.messages.getMessage("ProviderManager.providerNotFound",new Object[] { toTest.getName() }, "No AuthenticationProvider found for {0}"));}if (parentException == null) {prepareException(lastException, authentication);}throw lastException;}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/789676.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

学习笔记】java项目—苍穹外卖day05

文章目录 苍穹外卖-day05课程内容1. Redis入门1.1 Redis简介1.2 Redis下载与安装1.2.1 Redis下载1.2.2 Redis安装 1.3 Redis服务启动与停止1.3.1 服务启动命令1.3.2 客户端连接命令1.3.3 修改Redis配置文件1.3.4 Redis客户端图形工具 2. Redis数据类型2.1 五种常用数据类型介绍…

Spring 源码调试错误修复

Spring 源码调试错误修复 文章目录 Spring 源码调试错误修复1. fatal: not a git repository (or any of the parent directories): .git问题描述解决方案 2. fatal: Needed a single revision问题描述解决方案 1. fatal: not a git repository (or any of the parent director…

openGauss 函数及存储过程支持

函数及存储过程支持 可获得性 本特性自openGauss 1.1.0版本开始引入。 特性简介 函数和存储过程是数据库中的一种重要对象&#xff0c;主要功能将用户特定功能的SQL语句集进行封装&#xff0c;并方便调用。 客户价值 允许客户模块化程序设计&#xff0c;对SQL语句集进行封…

【ARM 嵌入式 C 头文件系列 22 -- 头文件 stdint.h 介绍】

请阅读【嵌入式开发学习必备专栏 】 文章目录 C 头文件 stdint.h定长整数类型最小宽度整数类型最快最小宽度整数类型整数指针类型最大整数类型 C 头文件 stdint.h 在 C 语言中&#xff0c;头文件 <stdint.h> 是 C99 标准的一部分&#xff0c;旨在提供一组明确的整数类型…

linux如何让alias自定义命令永久生效?

要让别名(alias)永久有效,您可以将它们添加到您的 bash 配置文件中。在大多数情况下,这个文件是 ~/.bashrc 或 ~/.bash_profile。 目录 1、打开终端或SSH连接到您的服务器。 2、编辑bash配置文件

Docker之ruoyi-vue项目部署

文章目录 创建自定义网络安装redis安装mysql发布若依项目--后端使用Dockerfile自定义镜像运行容器 nginx 创建自定义网络 #搭建net-ry局域网&#xff0c;用于部署若依项目 docker network create net-ry --subnet172.68.0.0/16 --gateway172.68.0.1 注意1&#xff1a;关闭宿主…

gateway应用(1)

1 简介 简单理解---业务服务的统一入口&#xff0c;方便实现&#xff0c;服务路由&#xff0c;安全&#xff0c;限流&#xff0c;过滤&#xff0c;黑白名单&#xff0c;证书加密解密&#xff0c;服务降级/熔断&#xff0c;灰度&#xff0c;等等 2 介绍 Predicate&#xff08…

AI技术创业有哪些机会?

AI技术创业有哪些机会&#xff1f; 目录 AI技术创业有哪些机会&#xff1f;1. 机器学习和数据分析平台&#xff1a;2. 智能客服和聊天机器人&#xff1a;3. 人脸识别和生物特征识别&#xff1a;4. 自动驾驶技术&#xff1a;5. 智能家居和物联网&#xff1a;6. 医疗诊断和健康管…

数据仓库——特殊类型的星型模式

数据仓库基础笔记思维导图已经整理完毕&#xff0c;完整连接为&#xff1a; 数据仓库基础知识笔记思维导图 特殊类型的星型模式 通过维度表示的事物通常可以按照类别或者类型细分。有时想要在维度表中记录的属性类型是多样的。 尽管类型相同&#xff0c;但是却存在很大差别。…

荣誉 | 人大金仓连续三年入选“金融信创优秀解决方案”

3月28日&#xff0c;由中国人民银行领导&#xff0c;中国金融电子化集团有限公司牵头组建的金融信创生态实验室发布“第三期金融信创优秀解决方案”&#xff0c;人大金仓新一代手机银行系统解决方案成功入选&#xff0c;这也是人大金仓金融行业解决方案连续第三年获得用户认可。…

LabVIEW齿轮箱噪声监测系统

LabVIEW齿轮箱噪声监测系统 齿轮箱作为机械设备的“心脏”&#xff0c;其健康状态对设备的性能有着重要的影响。传统的齿轮箱监测方法依赖于直接的振动信号分析&#xff0c;但这种方法不仅成本高昂&#xff0c;而且在安装和拆卸过程中可能对设备造成损害。针对这些问题&#x…

CMake解析

二 CMake解析 2.1 各种可用变量 CMake语法指定了许多变量,可用于帮助您在项目或源代码树中找到有用的目录。 其中一些包括: VariableInfoCMAKE_SOURCE_DIR根源代码目录,工程顶层目录。暂认为就是PROJECT_SOURCE_DIRCMAKE_CURRENT_SOURCE_DIR当前处理的 CMakeLists.txt 所在…

filetype: python中判断图像格式库imghdr替代库

引言 imghdr库是python中的一个内置库&#xff0c;用来判断图像原本格式的。自己一直有在用&#xff0c;不过近来看到这个库在python 3.13中会被移除。 自己感觉一直被python版本赶着走。这不找了好久&#xff0c;才找到一个替代库–filetype Python各个版本将要移除和可替代…

【Rust】——使用迭代器处理元素序列

&#x1f4bb;博主现有专栏&#xff1a; C51单片机&#xff08;STC89C516&#xff09;&#xff0c;c语言&#xff0c;c&#xff0c;离散数学&#xff0c;算法设计与分析&#xff0c;数据结构&#xff0c;Python&#xff0c;Java基础&#xff0c;MySQL&#xff0c;linux&#xf…

Kubernetes控制器(四)______StatefulSet

控制器介绍 StatefulSet&#xff1a; 是Kubernetes中用于管理有状态应用的控制器。与Deployment不同&#xff0c;StatefulSet用于部署和管理需要持久标识、有序部署和唯一网络标识的 Pod。典型的用例包括数据库、缓存和队列等有状态应用。&#xff08;有状态服务&#xff1a;单…

分享几个好用的电商API接口(可测试)

以下是一些好用的电商API接口&#xff0c;这些接口都可以用于获取电商平台的商品、订单、物流等相关信息&#xff0c;并提供了测试功能以确保接口的稳定性和可用性&#xff1a; 请求示例&#xff0c;API接口接入Anzexi58 淘宝开放平台API&#xff1a;淘宝开放平台提供了丰富的…

Keil 警告解决 : warning: #870-D: invalid multibyte character sequence

说明&#xff1a;在Keil项目编译时出现了几个 warning: #870-D: 的警告&#xff0c;接下来分析解决这个警告。 注意&#xff1a;在尝试解决问题前一定要将整个工程打包成压缩文件备份&#xff0c;以防更改失败变文件成乱码。 1.警告内容 warning: #870-D: warning: #870-…

2024.2.27力扣每日一题——统计树中的合法路径数目

2024.2.27 题目来源我的题解方法一 埃氏筛深度优先遍历 题目来源 力扣每日一题&#xff1b;题序&#xff1a;2867 我的题解 方法一 埃氏筛深度优先遍历 分别以质数节点为根&#xff0c;用「深度优先搜索」的方式&#xff0c;递归搜索所有的非质数的子树&#xff0c;并求出所…

Android Monkey自动化测试

monkey一般用于压力测试&#xff0c;用户模拟用户事件 monkey 基本用法 adb shell monkey [参数] [随机事件数]monkey常用命令 -v&#xff1a;用于指定反馈信息级别&#xff0c;总共分三个等级-v -v -vadb shell mokey -v -v -v 100-s&#xff1a;用于指定伪随机数生成器的种…

CentOS7安装flink1.17完全分布式

前提条件 准备三台CenOS7机器&#xff0c;主机名称&#xff0c;例如&#xff1a;node2&#xff0c;node3&#xff0c;node4 三台机器安装好jdk8&#xff0c;通常情况下&#xff0c;flink需要结合hadoop处理大数据问题&#xff0c;建议先安装hadoop&#xff0c;可参考 hadoop安…