The main way that I understand Shiro SecurityUtils.getSubject()
to work is that it returns the object associated with the current executable thread. However, this simply contradicts a servlet container such as Tomcat, which uses a thread pool to serve requests.
If Tomcat uses ThreadA to process requests, any calls to SecurityUtils.getSubject()
should work fine. But, once ThreadB is selected, the user is lost, getSubject
returns null, and isAuthenticated is now false. This is even though the user is still registered.
I confirmed this in my application. I use Shiro Core 1.2 and notice that my user is miraculously not authenticated when I view my application. If I look at the logs, the problem occurs as soon as another thread is used to service the request.
So, did I get Syro wrong? It seems that the "current user" should be tied to something longer than the current thread. I expect it to be session based. I know that Shiro has session control, but in all the examples I found, he says to get the current user by calling getSubject
, which looks at ThreadContext. Did I miss something?
source share