Backport of https://github.com/spring-projects/spring-security/pull/10805

Comment From: eleftherias

Fixed via 304ef2302c4b8a49c23c51a0b3f2234b84a25ed9