-
Search before asking
QuestionHello, with the change from #2082 we are no longer able to run our multi-threading model as before so that we could not adopt Shiro 2.0.4 or higher. Essentially our coding relies so far on the fact that we can obtain the principal using
also in child threads launched from a parent thread (typically an HTTP request). I tried following guidance from https://shiro.apache.org/subject.html#Subject-ThreadAssociation but without success. Even when associating the subject with the Runnable, I am receiving Is there any guidance / workaround how the user context can be made available to child threads? Regards, Eric |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
|
Hi, You are on the right track. In your child threads, you need to use something like the following: you may also do ThreadContext.bind(Subject) but that should already be taken care of as documented in https://shiro.apache.org/subject.html#Subject-ThreadAssociation Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
|
Hello, thanks for the reply, but I am not getting it yet (sorry if I am slow). Here is my basic coding (attempting to adopt the proposal above). Essentially it is not clear to me how to obtain / propagate the correct security manager in the child thread. Regards, Eric |
Beta Was this translation helpful? Give feedback.
-
|
Your code above looks like it should work correctly. |
Beta Was this translation helpful? Give feedback.
-
|
Also, have you tried just doing something like this: |
Beta Was this translation helpful? Give feedback.
-
|
Hello, ok, I did some further debugging and found one way which seems to work The problem was that Can you confirm that this is a valid approach to solve the challenge? Thanks, Eric |
Beta Was this translation helpful? Give feedback.
Hello,
ok, I did some further debugging and found one way which seems to work
The problem was that
subject.associateWith(task)did not ensure that the subject within the child thread is properly resolved as needed for obtaining the principal. Specifically, there was no session associated with the subject in the child thread.Can you confirm that this…