If you're using Dropwizard 0.7.0 try:
environment.jersey().register(new BasicAuthProvider<Subject>(new BasicAuthenticator(), "MyAuth"));
Question
I'm using Dropwizard 0.7.0. The dropwizard documentation at https://dropwizard.github.io/dropwizard/manual/auth.html#basic-authentication tells me to add an authenticator in this way:
@Override
public void run(ExampleConfiguration, Environment environment) {
environment.addProvider(
new BasicAuthProvider<User>(
new ExampleAuthenticator(), "SUPER SECRET STUFF"));
}
I expect that to be in my Application#run, but when I try the below, there is no method addProvider on my environment:
public class MyApplication extends Application<ExampleConfiguration> {
@Override
public void run(ExampleConfiguration config, Environment environment) throws Exception {
UserController userController = injector.getInstance(UserController.class);
environment.addProvider(new BasicAuthProvider<User>(new BasicAuthAuthenticator(userController), "aksdkaksdwj012934"));
}
}
What am I doing wrong?
Solution
If you're using Dropwizard 0.7.0 try:
environment.jersey().register(new BasicAuthProvider<Subject>(new BasicAuthenticator(), "MyAuth"));