dropwizard-guice icon indicating copy to clipboard operation
dropwizard-guice copied to clipboard

Dealing with an AuthProvider that takes an injected constructor parameter

Open EmberAle opened this issue 10 years ago • 3 comments

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:

  1. 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 avatar Mar 10 '14 01:03 EmberAle

@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?

tpetr avatar Mar 10 '14 21:03 tpetr

Changing to [DEVELOPMENT] didn't seem to make a difference.

EmberAle avatar Mar 11 '14 01:03 EmberAle

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?

chdietz avatar Mar 13 '14 21:03 chdietz