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

Comment From: jzheaux

Closed in 452d311a9be7093ba9009a34dd0522dcffc0f603