dropwizard - Dropwizard 中的多个 AuthFactory

标签 dropwizard

我想在 dropwizard 中使用两个不同的 authfactory,Basic 和 OAuth。像这样:-

BasicAuthFactory authFactory = new BasicAuthFactory(new IngestionConsoleAuthenticator(),"SUPER SECRET STUFF", UserA.class);

OAuthFactory authFactory2 = new OAuthFactory(new PSVAppAuthenticator(), "Secret", UserB.class);

环境.jersey().register(AuthFactory.binder(authFactory));
环境.jersey().register(AuthFactory.binder(authFactory2));

使用 @Auth UserA 的资源工作正常,但使用 @Auth UserB 则无需任何身份验证即可访问。我怎样才能让两者同时工作?

最佳答案

http://www.dropwizard.io/manual/auth.html#chained-factories

@Override
public void run(ExampleConfiguration configuration,
                Environment environment) {
    ChainedAuthFactory<User> chainedFactory = new ChainedAuthFactory<>(
            new BasicAuthFactory<>(new ExampleBasicAuthenticator(), "SUPER SECRET STUFF", User.class),
            new OAuthFactory<>(new ExampleOAuthAuthenticator(), "SUPER SECRET STUFF", User.class));
    environment.jersey().register(AuthFactory.binder(chainedFactory));
}

For this to work properly, all chained factories must produce the same type of principal, here User.

关于dropwizard - Dropwizard 中的多个 AuthFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31580611/

相关文章:

testing - DropWizard JAR 签名漏洞

java - Gradle jetty使用DropWizard运行set webappsource目录

cache-control - 在 Dropwizard 中设置静态 Assets 的缓存控制 header

java - 如何使用 Dropwizard 接受自定义命令行参数

java - Dropwizard 默认使用什么指标核心?

java - 使用 Bean 验证时防止内部服务器错误

java - 如何在 Drop Wizard 中的每次 API 调用之前运行自定义 ServletRequestListener

java - 在 Eclipse 中调试简单的 Dropwizard 应用程序

java - 如何将 JSON 反序列化为具有已知必填字段但可以具有多个未知字段的 Java 类?

java - @Produces 和@Consumes 的 Jersey (dropwizard)默认媒体类型