I need to do access to the current user (previously set up by a ContainerRequestFilter
) in a static way, to avoid the passage of the @Context SecurityContext
in every method of every controller.
I want to achieve something that, in Spring, I would do with
SecurityContextHolder.getContext().getAuthentication();
Is there any way to do it, besides using Spring Security in Quarkus?
The solution is to use this dependency
Then you can manipulate the instance of
SecurityIdentity
to "make it static"}
@StartUp
does instantiate the bean on application start (instead of lazily).You can then access to the Principal statically using
UserUtilsService.getCustomUser();