我想在 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/