Authentication dropwizard中不同资源的多个身份验证程序

Authentication dropwizard中不同资源的多个身份验证程序,authentication,dropwizard,Authentication,Dropwizard,假设我有两个资源,/authenticate和/protected\u resource。Authenticate验证通过基本http身份验证提供的用户/密码,如果成功,则生成jwt令牌/受保护的_资源希望在传入请求标头中提供令牌,就像在oauth中一样。 我是否可以安装两个不同的验证器/过滤器,“basic”和“jwt”,并指出基本验证器/过滤器用于/验证,jwt过滤器用于/受保护的\u资源?可以 我还没有具体尝试过,但看看源代码,根据我与AuthProviders一起玩的经验,它应该可以工作

假设我有两个资源,/authenticate和/protected\u resource。Authenticate验证通过基本http身份验证提供的用户/密码,如果成功,则生成jwt令牌/受保护的_资源希望在传入请求标头中提供令牌,就像在oauth中一样。 我是否可以安装两个不同的验证器/过滤器,“basic”和“jwt”,并指出基本验证器/过滤器用于/验证,jwt过滤器用于/受保护的\u资源?

可以

我还没有具体尝试过,但看看源代码,根据我与AuthProviders一起玩的经验,它应该可以工作

只需确保这些验证器返回不同的类

environment.jersey().register(AuthFactory.binder(new BasicAuthFactory<User>(new UserAuthenticator(), "User authentication", User.class)));

environment.jersey().register(AuthFactory.binder(new OAuthFactory<Token>(new JwtAuthenticator(), "Jwt authentication", Token.class)));

这个解决方案实际上不起作用。在注册第二个AuthFactory时,
ComponentBag.java
method
private boolean registerModel
的内部返回false
@Path("/authenticate")
public String authenticate(@Auth User user){
   return jwtToken;
}

@Path("/protected_resource")
public FooDto getFoo(@Auth Token token){
   // do stuff
}