Class SecurityContextPropagatingExecutor
- All Implemented Interfaces:
Executor
Executor decorator that carries the submitting thread's Spring
Security SecurityContext over to whatever thread actually runs the
submitted task.
com.fayupable.logged.spring.aspect.FlowContextPropagatingExecutor
solves the equivalent problem for this library's own call-chain tracking.
That class deliberately does not also propagate SecurityContext,
so that it stays usable in applications with no Spring Security on the
classpath at all. This class fills that specific gap for applications
that do have Spring Security: without it, a nested @Logged call
made from inside work submitted through a plain, unwrapped executor loses
the authenticated user entirely on the executor thread, and this
library's caller identity resolution silently falls back to an IP address
or "unknown" for that nested call — losing *who* made the call,
not just a secondary detail.
Wrap once, alongside FlowContextPropagatingExecutor if both are
needed, by nesting decorators around the same delegate:
Executor propagating = new FlowContextPropagatingExecutor(
new SecurityContextPropagatingExecutor(realExecutor));
This class is deliberately not wired in automatically anywhere in this
library's auto-configuration: a consuming application decides which
executor should carry the current authenticated user across a thread
hand-off, the same way it decides which methods get @Logged in
the first place.
-
Constructor Summary
ConstructorsConstructorDescriptionSecurityContextPropagatingExecutor(Executor delegate) Wrapsdelegateso that every task submitted through this executor carries the submitting thread'sSecurityContextinto whichever threaddelegateactually runs it on. -
Method Summary
Modifier and TypeMethodDescriptionvoidCaptures the calling thread's currentSecurityContextand submits a wrapped task to the delegate executor that restores it before runningcommandand restores the executor thread's own previous security context again afterward, regardless of whethercommandcompletes normally or throws.
-
Constructor Details
-
SecurityContextPropagatingExecutor
Wrapsdelegateso that every task submitted through this executor carries the submitting thread'sSecurityContextinto whichever threaddelegateactually runs it on.- Parameters:
delegate- the executor that will actually run submitted tasks
-
-
Method Details
-
execute
Captures the calling thread's currentSecurityContextand submits a wrapped task to the delegate executor that restores it before runningcommandand restores the executor thread's own previous security context again afterward, regardless of whethercommandcompletes normally or throws.
-