The ThreadContext is really an internal support class for Shiro and
not really intended to be used by end-users.
The ideal scenario is I think this:
1. Based on the incoming message/request/whatever, use the
Subject.Builder to build your subject instance.
2. Call subject.execute and call whatever method is at the 'root' of
your chain., e.g.
subject.execute(new Runnable() {
public void run() {
myRootMethod();
}
});
from myRootMethod() and anywhere below it in the call stack,
SecurityUtils.getSubject() will work correctly. When subject.execute
returns, the thread's state will be as it was before calling execute -
it performs automatic cleanup.
This is exactly what the ShiroFilter and the
SecureRemoteInvocationExecutor do to ensure thread association and
automatic cleanup.
Is this not possible in your scenario Jack?
Cheers,
Les