When I try to obtain the principal from the security context in a parallel stream, it always returns null when isn't in the main thread.
The following piece of code fails when the user is authenticated:
listOfSomething.parallelStream()
.foreach(el -> {
if (SecurityContextHolder.getContext().getAuthentication().getPrincipal() == null){
throw new RuntimeException();
}});
The documentation says:
Interface defining the minimum security information associated with the current thread of execution.
But, is there any way to do it? It starts in main thread and use ForkJoinPool
Thank you!