title: Jersey custom SecurityContext on EJB jax-rs resource
body: <p>I am trying to implement my own <code>ContainerRequestFilter</code> and configure <code>SecurityContext</code>. It works well on jax-rs resources but EJB jax-rs throws <code>javax.ejb.AccessLocalException</code> </p>
  
  <p>Only relevant thing I found is 4 years old and the workaround doesn't seem pretty.
  <a href="https://java.net/projects/jersey/lists/users/archive/2010-05/message/265" rel="nofollow">https://java.net/projects/jersey/lists/users/archive/2010-05/message/265</a></p>
  
  <p><strong>My custom SecurityContext:</strong></p>
  
  <pre><code>@Provider
  @PreMatching
  public class SecurityFilter implements ContainerRequestFilter {
  
      @Override
      public void filter(ContainerRequestContext filterContext) throws IOException {
          filterContext.setSecurityContext(new Authorizer());
      }
  
      public class Authorizer implements SecurityContext {
  
      public Principal getUserPrincipal() {
          return null;
      }
  
      public boolean isUserInRole(String role) {
          return true;
      }
  
      public boolean isSecure() {
          return false;
      }
  
      public String getAuthenticationScheme() {
          return null;
      }
  }
  </code></pre>
  
  <p><strong>Tested resource</strong> (works without @Stateless)</p>
  
  <pre><code>@Path("test")
  @Stateless
  public class TestSecureResource {
  
      @GET
      @RolesAllowed("admin")
      @Path("admin")
      public Response secureTest() {
          return Response.status(200).entity("admin").build();
      }
  
  }
  </code></pre>
  
  <p>Does someone know how to make this work?</p>