简单记录一下从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) 之后,就能成功登录。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。