首页IT科技spring升级springboot(从SpringBoot 2.6.0升级到3.0.1之后,无法成功登录系统的问题及解决方法)

spring升级springboot(从SpringBoot 2.6.0升级到3.0.1之后,无法成功登录系统的问题及解决方法)

时间2025-10-13 14:06:55分类IT科技浏览5875
导读:简单记录一下从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) 之后    ,就能成功登录。

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
launcher.exe什么意思(lao.exe是什么进程 有什么用 lao进程查询) 二类文章题目字数要求(类模板)