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