title: Context injected SecurityContext is null
body: <p>I have created a Javae EE app using JAX-RS 2.0 and JPA. I created a special provider of my User entity (using Qualifiers) to provide the current user (logged in) as entity from applications user database.
  To get current user i use</p>
  
  <pre><code>@Context
  private SecurityContext secContext;
  </code></pre>
  
  <p>The problem is that this is null. The security is setup fine (Wildfly 8.2) - the app asks for Authentication (basic) but <code>SecurityContext</code> is null. Here is the code:</p>
  
  <pre><code>@RequestScoped
  public class CurrentUserProducer implements Serializable {
  
      /**
       * Default
       */
      private static final long serialVersionUID = 1L;
  
      @Context
      private SecurityContext secContext;
  
      /**
       * Tries to find logged in user in user db (by name) and returns it. If not
       * found a new user with role {@link UserRole#USER} is created.
       * 
       * @return found user a new user with role user
       */
      @Produces
      @CurrentUser
      public User getCurrentUser() {
          if (secContext == null) {
              throw new IllegalStateException("Can't inject security context - security context is null.");
          //... code to retrieve or create new user
          return user;
      }
  
  }
  </code></pre>
  
  <p>As you see I check <code>secContext</code> for null and i see my exception as soon as i try to reach a resource that injects <code>@CurrentUser</code>.</p>
  
  <p>So how to fix this? Why is <code>SecurityContext</code> null.</p>