从SpringBoot 2.6.0升级到3.0.1之后,无法成功登录系统的问题及解决方法
简单记录一下从SpringBoot 2.6.0升级到3.0.1之后,无法成功登录系统的问题。
目前的解决方法:
在SecurityConfiguration配置中添加 httpSecurity.securityContext().requireExplicitSave(false);
,然后就能正常登录了。
但是没法解释的是,直接使用系统中默认的UsernamePasswordFilter时,是不用添加这一句也能正常登录的。等过两天再研究吧。
相关的链接:
SwitchUserFilter not working in Spring Security 6
https://github.com/spring-projects/spring-security/issues/12504
After upgrade to spring boot 3.0.0-M5, TestingAuthenticationToken and UsernamePasswordAuthenticationToken not work the same as spring boot 2.7.3 #11977
https://github.com/spring-projects/spring-security/issues/11977
Spring security does not redirect to success login after authentication success #4479
https://github.com/spring-projects/spring-security/issues/4479
写给自己看的:
系统中有多个自定义的AuthenticationFilter和对应的自定义AuthenticationProvider。升级到3.0.1之后,无法成功登录。
Debug的时候,发现在自定义的AuthenticationProvider中是能成功返回authentication的,但是之后却不能成功重定向到首页。如下面链接中有提到的,认证信息被清除了。
后来又找到了几个相关的关键词 requireExplicitSave
SecurityContextHolderFilter
SecurityContextPersistenceFilter
之前是默认会自动存认证信息,现在需要显式存储。不过还是搞不清楚具体是什么意思。
测试项目中的几种情况:
1,自定义authentication provider,不用自定义的authentication filter,可以成功登录。
2,自定义authentication provider,用了自定义的authentication filter,不能成功登录。但是在配置中添加 httpSecurity.securityContext().requireExplicitSave(false) 之后,就能成功登录。
相关文章
- 深入探讨Java中的异常与错误处理
- 研究学习Kotlin的一些方法
- 数据显示Java热度持续下落,日子屈指可数?
- 2017年5月编程语言排行榜:Java与C语言优势正开始缩小
- Java多线程之内置锁与显示锁
- Java线程池的理论与实践
- 白话阿里巴巴Java开发手册(编程规约)
- 关于Java你不知道的十件事
- Java服务化系统线上应急和技术攻关,你必须掌握的Linux命令
- Java实现高斯模糊和图像的空间卷积
- Java阻塞队列实现原理分析
- NPM使用技巧
- Node.js对Java开发者而言是什么?
- Java反射机制应用实践
- 理解RxJava中的Single和Completable
- 2017年你不能错过的Java类库
- 大规模集群下的Hadoop NameNode
- 从源码解密Spark内存管理
- 2017年3月编程语言排行榜:Swift首次进入前十
- JVM热点技术:Java类的加载机制