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

Comment From: jzheaux

Closed in 857ca9c412e220e382de38c49c6a4828e868f45a