如何将Authenticator添加到dropwizard应用程序

时间:2014-05-13 21:59:11

标签: java dropwizard

我正在使用Dropwizard 0.7.0。 https://dropwizard.github.io/dropwizard/manual/auth.html#basic-authentication上的dropwizard文档告诉我以这种方式添加验证器:

@Override
public void run(ExampleConfiguration, Environment environment) {
    environment.addProvider(
        new BasicAuthProvider<User>(
            new ExampleAuthenticator(), "SUPER SECRET STUFF"));
}

我希望在我的Application#run中运行,但是当我尝试下面的操作时,我的环境中没有方法addProvider:

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"));
    }
}

我做错了什么?

1 个答案:

答案 0 :(得分:4)

如果您正在使用Dropwizard 0.7.0,请尝试:

environment.jersey().register(new BasicAuthProvider<Subject>(new BasicAuthenticator(), "MyAuth"));