Forward port of https://github.com/spring-projects/spring-security/issues/17797 to 6.5.x

Comment From: jzheaux

Closed in 9d64880ea9df4ea38ebb24c889ae25f57a4ec474