title: Injection to ContainerRequestFilter in a java REST API
body: <p>I guess I am dealing with a bug in Glassfish 4; but I am not sure. Basically I am trying to inject a service into a ContainerRequestFilter; but I am getting an exception while trying. I can do injection in resources where I make rest calls, but I can't use injection for filters. There is a filed bug in glassfish jira: <a href="https://java.net/jira/browse/GLASSFISH-20597" rel="noreferrer">https://java.net/jira/browse/GLASSFISH-20597</a>. I tried the workaround mentioned in there but it didn't solve my problem.</p>
  
  <p>Here is the exception I get:</p>
  
  <pre><code>org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at Injectee&amp;#40;requiredType=Authenticator,parent=SecurityInterceptor,qualifiers
  </code></pre>
  
  <p>Here is the code that I am working with, do you have any idea what I am missing here?</p>
  
  <pre><code>@Provider
  @PreMatching
  public class SecurityInterceptor implements ContainerRequestFilter {
  
  @Inject
  private Authenticator authenticator; // can't inject this service here, but I can inject this to RequestScoped Resources
  private static final Logger LOG = Logger.getLogger(SecurityInterceptor.class.getName());
  
  @Override
  public void filter(ContainerRequestContext requestContext) throws IOException {
      if (!requestContext.getMethod().equals("OPTIONS")) {
          String path = OyumBuFunctions.normalizeString(requestContext.getUriInfo().getPath());
              String authToken = requestContext.getHeaderString(OyumbuRestHeaders.AUTH_TOKEN_HEADER);
              if (!authenticator.isAuthTokenValid(authToken)) {
                  requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
              }
              else{
                  LOG.log(Level.INFO, "authenticated");
              }
      }        
    }
  }
  </code></pre>