Forward port of issue #12274 to 5.7.x.

Comment From: marcusdacoregio

Fixed via https://github.com/spring-projects/spring-security/issues/12285