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

  本篇文章为你整理了从SpringBoot 2.6.0升级到3.0.1之后,无法成功登录系统的问题及解决方法()的详细内容,包含有 从SpringBoot 2.6.0升级到3.0.1之后,无法成功登录系统的问题及解决方法,希望能帮助你了解 从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) 之后,就能成功登录。

  以上就是从SpringBoot 2.6.0升级到3.0.1之后,无法成功登录系统的问题及解决方法()的详细内容,想要了解更多 从SpringBoot 2.6.0升级到3.0.1之后,无法成功登录系统的问题及解决方法的内容,请持续关注盛行IT软件开发工作室。

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: