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

Comment From: jzheaux

Closed in a9fcec8b46a12b14f35d417b093e49fd79c580ca