A really strange situation is observed in our application (Spring Boot 1.5.6 with all-default BOM dependencies): you can perfectly log in (with AbstractPreAuthenticatedProcessingFilter
), but this still leaves Principal
in request null
! I.e. request.getUserPrincipal()
is null
while SecurityContextHolder.getContext().getAuthentication()
is not!
This in turn affects the ability of our health endpoint to be sensitive: it uses Principal
(see HealthMvcEndpoint.exposeHealthDetails(HttpServletRequest, Principal)) which is injected by ServletRequestMethodArgumentResolver
, which in turn takes it from the request...
Looks like I'm missing something simple, but still can't find it :(
So, after creating a new Spring Boot application and debugging it to its guts, I've found out that nobody actually sets Principal
into the request. It's Spring who wraps it into another one that uses Spring's SecurityContext
for the above (and some other methods). And this wrapping is done by the SecurityContextHolderAwareRequestFilter
, which is there by default (see HttpSecurity.servletApi()
)...
But somebody has disabled the default Spring Security configuration for our project, so the filter was not there!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With