title: Checking Principal-user by Injected SecurityContext inside the constructor of a web resource
body: <p>I'm relatively new to Jersey and JAX-RS, but I can't find my way in the documentation about the use of the SecurityContext inside the constructor of a Resource. </p>
  
  <p>Our OAUTH implementation is currently such that all requests on the REST API are intercepted by an implementation of the ResourceFilter. So the resource filter sets a user Principal by calling:</p>
  
  <pre><code>containerRequest.setSecurityContext(new MySecurityContext(user));
  </code></pre>
  
  <p>... inside the ContainerRequest.filter() method, wWith a concrete class MySecurityContext, as:</p>
  
  <pre><code>public class MySecurityContext implements SecurityContext {
  
      private final User principal;
  
      public MySecurityContext(final User user) {
          this.principal = user;
      }
  
      @Override
      public String getAuthenticationScheme() {
          return SecurityContext.FORM_AUTH;
      }
  
      @Override
      public Principal getUserPrincipal() {
          return principal;
      }
  
      @Override
      public boolean isSecure() {
          return false;
  
      }
  
      @Override
      public boolean isUserInRole(String role) {
          return principal.getRoles().contains(role);
      }
  }
  </code></pre>
  
  <p>Now I want to use that user principal in the constructor of the webresource before any @GET/@POST/@DELETE method is called. I've tried injecting </p>
  
  <pre><code>@Context SecurityContext
  </code></pre>
  
  <p>..into the constructor argument list but a call to getUserPrincipal() just yields null.</p>
  
  <p>Is there a way to check the Principal user in the constructor of a Webresource?</p>
  
  <p>thanks!</p>