dropwizard-guice
dropwizard-guice copied to clipboard
Dealing with an AuthProvider that takes an injected constructor parameter
I have an AuthProvider as follows:
import com.google.inject.Inject; import com.google.inject.Singleton; import com.google.inject.name.Named; import com.mycompanyname.server.User; import io.dropwizard.auth.Authenticator; import io.dropwizard.auth.basic.BasicAuthProvider; import io.dropwizard.auth.basic.BasicCredentials;
@Singleton @javax.ws.rs.ext.Provider public class StormpathAuthProvider extends BasicAuthProvider<User> { @Inject public StormpathAuthProvider(Authenticator<BasicCredentials, User> authenticator, @Named("realm") String realm) { super(authenticator, realm); } }
(this is the only way I found of binding a BasicAuthProvider<User> while using dropwizard-guice
And I simply bind it as:
bind(StormpathAuthProvider.class);
I also bind:
bind(new TypeLiteral<io.dropwizard.auth.Authenticator<BasicCredentials,User>>(){}).to(StormpathAuthenticator.class);
However, my StormpathAuthenticator takes a constructor parameter that is provided by a @Provides method in my guice Module. This can only be run after the bootstrap stage has finished, and leads to:
- The dropwizard environment has not yet been set. This is likely caused by trying to access the dropwizard environment during the bootstrap phase.
Any ideas?
@EmberAle Your issue might be related to #19 -- what Stage are you using for your GuiceBundle? (GuiceBundle.Builder currently defaults to PRODUCTION
)
Could you let me know if switching to DEVELOPMENT
improves anything?
Changing to [DEVELOPMENT] didn't seem to make a difference.
I have a similar issue still trying to resolve it, I did find this note on another bundle: Be aware of the jersey-guice binding life-cycle: https://github.com/fizmo/dropwizard-bundle-guice#be-aware-of-the-jersey-guice-binding-life-cycle
Could this be related?