Basically, it is assuming that because that was the use case I was
working with. I have added SHIRO-401
(https://issues.apache.org/jira/browse/SHIRO-401) to allow the passing
of a provider, which should enable your use case.
In the meantime, there are a couple of options.
1. Copy ShiroWebModule into your project and change it.
2. Write an implementation of the ServletContext interface that
deletages all of its calls to "provider.get()". Pass that
implementation
Neither is particularly attractive, I know. I've included my first
thoughts at implementing #2.
Thanks,
Jared
PS. Could you share how you are using Guice to create the Jetty server
with Shiro? I think this would be an interesting sample to add to the
project.
import com.google.inject.Provider;
import javax.servlet.ServletContext;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
public class ServletContextProxy implements InvocationHandler {
private final Provider<ServletContext> contextProvider;
public ServletContextProxy(Provider<ServletContext>
contextProvider) {
this.contextProvider = contextProvider;
}
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
return method.invoke(contextProvider.get(), args);
}
public static ServletContext
createInstance(Provider<ServletContext> contextProvider) {
return (ServletContext)
Proxy.newProxyInstance(contextProvider.getClass().getClassLoader(), new
Class[]{ServletContext.class}, new
ServletContextProxy(contextProvider));
}
}
On Wed 05 Dec 2012 08:00:39 AM CST, mircea wrote:
> Hello,
>
> I'm wondering why is SHIRO assuming that the Guice injector must be created
> after the server (in my case Jetty) is created.
>
> You can only use Shiro after the ServletContext is available. I think this
> is a wrong assumption because you can also use Guice to wire the entire
> application, including the server. This means the ServletContext is not
> available at the injector creation time. So, no out-of-the-box solution in
> this case.
>
> How could I solve this problem? How can I initialize Shiro in a web
> application which is using Guice for the server creation?
>
> Thanks,
>
>
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/Why-is-Shiro-assuming-that-you-already-have-a-server-running-tp7578017.html
> Sent from the Shiro User mailing list archive at Nabble.com.