I ran into a similar issue, and, while this is probably no longer an issue for you, I wanted to provide the work-around I used.
The issue is ownership of MyCustomRealm
. It is being created by shiro in the org.apache.shiro.web.env.EnvironmentLoaderListener
by reading the ini file which is outside the scope of the hk2 provider in the Jersey servlet.
Dependency injection is only done when the object is being provided by hk2's ServiceLocator--shiro has no knowledge of this locator and only constructs an instance of MyCustomRealm
with its default constructor.
I worked around this by implementing a org.glassfish.jersey.server.spi.ContainerLifecycleListener
that gets a handle to the ServiceLocator and shiro's SecurityManager (through the ServletContext
which is registered with the ServiceLocator
). It then manually injects the data into the realm created by shiro.
If you're interested, I can post the code as a gist.