ジャージーに AuthDynamicFilter を登録するときにオブジェクトを注入する方法を理解しようとしています。
public class CustomApplication extends Application<Configuration> {
public void run(Configuration configuration, Environment environment) throws Exception {
...
environment.jersey().register(new AuthDynamicFeature(CustomAuthFilter.class));
...
}
}
CustomAuthFilter
@PreMatching
public class CustomAuthFilter<P extends Principal> extends AuthFilter<String, P> {
private final Object identity;
@Context
private HttpServletRequest httpServletRequest;
@Context
private HttpServletResponse httpServletResponse;
public LcaAuthFilter(Identity identity) {
this.identity = identity;
}
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
...identity.process(httpServletRequest)
}
}
CustomAuthFilter の作成時に Identity オブジェクトを挿入する方法がないため、上記のコードはコンパイルされません。
あなたが行くなら:
environment.jersey().register(new AuthDynamicFeature(new CustomerAuthFilter(new Identity())));
この場合、httpServletRequest は null に設定されます。
これを回避する方法を理解できる唯一の方法は、AuthDynamicFeature を使用することさえせず、通常のフィルターを使用してその方法で注入することです。AuthDynamicFeature をどのように使用するのか疑問に思っています。
私はまだdropwizardとjerseyに慣れていないので、ご容赦ください. 私が混乱しているかもしれないいくつかの概念。
どんなアドバイスでも感謝します、ありがとう、デレク