I'm trying to figure out how to inject an object when registering a AuthDynamicFilter in jersey.
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)
}
}
The above code won't compile because there is no way to inject the Identity Object when creating the CustomAuthFilter.
If you go with:
environment.jersey().register(new AuthDynamicFeature(new CustomerAuthFilter(new Identity())));
In this case, httpServletRequest will be set to null.
The only way I could figure out how to get around this is to not even use AuthDynamicFeature and just go with a normal Filter and inject it that way which is fine. I'm wondering how would you do it with a AuthDynamicFeature.
I'm still new to dropwizard and jersey so please bear with me. Some concepts that I might be messing.
Any Advice Appreciated, Thanks, Derek