Forward port of https://github.com/spring-projects/spring-security/pull/17532

Comment From: jzheaux

Closed in a411fb7b8d6ba8223ea48903fe66a8dd96c5779a