There's not really anything built-in to do this, but there are things that
you can do.  The object that you're going to want to inject is Subject -
you can access the session through that.

My recommendation would be to use a @Provides method on your Shiro module
to return the result of SecurityUtils.getSubject().  I would recommend
injecting Provider<Subject>.  If you really want to inject a native Subject
(rather than the provider), then I would write an implementation of Subject
that just always calls SecurityUtils.getSubject() and delegates to the
result of that call.  Of course, it would need to throw an exception if
there is no current subject.


On Sat, Oct 19, 2013 at 1:11 PM, Josh Berry <[email protected]> wrote:

> I'm building a small project with a backend of Shiro, Guice, and Jersey.
> One of the things I want to be able to do is inject the current user into
> many of my classes.  Is there a more or less official way of accomplishing
> this?  Should I instead inject the Session?  (Does this even make sense?)
>
> Thanks!
>
> -josh
>

Reply via email to