title: JBoss / Resteasy how to prepopulate objects using a filter before the exposed API?
body: <p>Environment: JBoss AS 7, RestEasy 3.0.5.</p>
  
  <p>I would like to use a preprocess filter in my application to authenticate a particular user and add this authenticated user to the <strong>request scope</strong>. I tried the following:</p>
  
  <pre><code>@Provider
  public class SecurityFilter implements ContainerRequestFilter {
  
      @Override
      public void filter(ContainerRequestContext requestContext) {
          // authenticate, lookup user code etc...
          requestContext.setProperty("User", new User("test"));
      }
  }
  </code></pre>
  
  <p>And then access it at the bean level using:</p>
  
  <pre><code>@Stateless
  public class TestBean {
  
      @Context HttpServletRequest servletRequest;
  
      @GET
      @Path("/hello")
      public String hello() {
          return "Hello " + servletRequest.getAttribute("User");
      }
  
  }
  </code></pre>
  
  <p>However the Context elements are not injected when the bean is annotated as stateless (stateless is required for EJB logic) due to a <a href="https://issues.jboss.org/browse/RESTEASY-532" rel="nofollow">2 year old RestEasy bug</a>.</p>
  
  <ol>
  <li>Can anyone think of a solution to this issue?</li>
  <li>Alternatively, is there a more typical solution that prepopulating these objects using a filter?</li>
  </ol>
  
  <p>Kind thanks for reading.</p>