UsernamePasswordAuthenticationToken(位于org.springframework.security.authentication包下) 通过类名可以的看出来,用户名密码方式进行认证。就是我们见的最多的认证方式通过用户名密码进行登录。咱们话不多说看看具体实现:

public class UsernamePasswordAuthenticationToken extends AbstractAuthenticationToken {// 序列化idprivate static final long serialVersionUID = 530L;// 一般指的是用户名private final Object principal;// 一般指的是密码private Object credentials;// 构造器// principal  一般指的是用户名// credentials  一般指的是密码public UsernamePasswordAuthenticationToken(Object principal, Object credentials) {// 初始化父类构造 权限集合为空super((Collection)null);this.principal = principal;this.credentials = credentials;// 设置是否已认证 默认为falsethis.setAuthenticated(false);}// 构造器// principal  一般指的是用户名// credentials  一般指的是密码// authorities 权限public UsernamePasswordAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {// // 初始化父类构造 权限集合super(authorities);this.principal = principal;this.credentials = credentials;// 设置父类方法表示已经认证super.setAuthenticated(true);}// 获取密码public Object getCredentials() {return this.credentials;}// 获取用户名public Object getPrincipal() {return this.principal;}// 设置是否已认证 默认为falsepublic void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {// 如果为true// 抛出非法参数异常if (isAuthenticated) {throw new IllegalArgumentException("Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");} else {// 设置父类是否已认证super.setAuthenticated(false);}}// 擦除凭证public void eraseCredentials() {  // 调用父类方法super.eraseCredentials();// 将密码设置为空this.credentials = null;}
}

UsernamePasswordAuthenticationToken相关推荐

  1. Spring源码分析【9】-SpringSecurity密码Remove原理

    很明显代码已经说了认证完成移除credentials和其他某些安全数据 // Authentication is complete. Remove credentials and other secr ...

  2. SpringBoot+SpringSecurity前后端分离+Jwt的权限认证(改造记录)

    欢迎关注方志朋的博客,回复"666"获面试宝典 来源:blog.csdn.net/zzzgd_666/article/details/96444829 前言 一般来说,我们用Spr ...

  3. Spring Boot 整合 Spring Security 示例

    点击关注公众号,Java干货及时送达 一.说明 SpringSecurity是一个用于Java 企业级应用程序的安全框架,主要包含用户认证和用户授权两个方面.相比较Shiro而言,Security功能 ...

  4. Spring Cloud 随笔:记录在使用 OAuth2 遇到的巨坑

    点击上方"方志朋",选择"置顶或者星标" 你的关注意义重大! 本文转载文章,原文链接 https://www.shangyang.me/2017/06/01/s ...

  5. springboot 集成jwt设置过期时间_传说中的jwt,我们来征服一下

    原创:猿逻辑,欢迎分享,转载请保留出处. 本文的完整示例代码,见github仓库.小q只在文中介绍最关键的代码块. https://github.com/yuanluoji/purestart-spr ...

  6. 实战篇:Security+JWT组合拳 | 附源码

    简介 先赘述一下身份认证和用户授权: 用户认证(Authentication):系统通过校验用户提供的用户名和密码来验证该用户是否为系统中的合法主体,即是否可以访问该系统: 用户授权(Authoriz ...

  7. SpringSecurity实战:基于mysql自定义SpringSecurity权限认证规则

    上文<Spring Security 源码分析:Spring Security 授权过程>已经详细分析了Spring Security 授权过程,接下来通过上文的授权过程我们可以自定义授权 ...

  8. Spring Security 源码分析:Spring Security 授权过程

    Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架.它提供了一组可以在Spring应用上下文中配置的Bean,充分利用了Spring I ...

  9. SpringBoot 2 + Spring Security 5 + JWT 的单页应用 Restful 解决方案

    此前我已经写过一篇类似的教程,但那时候使用了投机的方法,没有尊重 Spring Security 的官方设计,自己并不感到满意.这段时间比较空,故重新研究了一遍. 特性 使用 JWT 进行鉴权,支持 ...

最新文章

  1. 线性回归和logistic回归
  2. Android IOS WebRTC 音视频开发总结(十一)-- stunturn部署
  3. Python 中让你相见恨晚的 20 个骚操作
  4. python当用户输入的不是整数_当用户输入字符串而不是整数时,如何保护我的python代码?...
  5. HyperLPR车牌识别库代码分析(11)
  6. 如何在数字化领域脱颖而出?TOGAF®认证为你的职业成长赋能
  7. android view分析工具,Android 性能分析工具之TraceView
  8. WSO2 ESB 5.0.0 的一些控制台显示配置
  9. MOCTF-WRITE-UP(二)
  10. 英语3500词(20/20)dream主题(2022.4.30)
  11. 入门pandas—数据透视与交叉表
  12. java交通调度,java毕业设计_springboot框架的的车辆调度管理系统
  13. 算数操作符与移位操作符
  14. 【尚医通】手机登录功能
  15. 192.168.8.1手机登陆_192.168.8.1手机登陆路由器设置教程
  16. 用计算机怎么管理小米路由器,怎样用手机设定小米路由器
  17. 靠追热点出圈,网易传媒打造“爆款制造机2.0”
  18. JS 正则表达式获取匹配内容
  19. 贫民窟里的WPF系列讲座(二)
  20. iOS之UI--通讯录的实例关键知识技术点积累

热门文章

  1. 【Unity】大世界实现方案
  2. 收集整理网络协议类型
  3. Typora工具免费版下载
  4. C++快慢指针理解与应用
  5. 前端:Tomcat服务器部署Web项目
  6. Perl CGI重构原则
  7. 从软件工程师到IT猎头:我的一点经历和感触
  8. error C2059: 语法错误:“,”
  9. 将大写字母转化为小写字母
  10. 小红书品牌投放监测之竞品对比