title: Using CDI Injection in a Servlet
body: <p>I am attempting to <code>@Inject</code> a <code>@SessionScoped</code> bean into a Filter</p>
  
  <pre><code>@WebFilter("/*")
  public class IdentityFilter implements Filter, Serializable {
  
      @Inject
      private LoginUser loginUser;
  ...
  </code></pre>
  
  <p>where <code>LoginUser</code> is <code>@SessionScoped</code></p>
  
  <p>The intention is for loginUser to represent the logged in user for the session.</p>
  
  <p>The problem is it appears that I am not always getting the <code>loginUser</code> from the current session, I am getting 'leakage' between sessions as one session's LoginUser object is being shared with another session. Obviously this isn't good.</p>
  
  <p>I am wondering if this is because the <code>Filter</code> object is a singleton, or at least reused between requests and sessions by the container (glassfish). (Right?)</p>
  
  <p>Is there a better way to obtain the <code>LoginUser</code> object for the current session without using a property on the Filter?</p>