title: JSF 2.0 user session
body: <p>I asked my problem earlier but I was not clear. So I ask my question again hoping that one understands me.
  I would like to create a user session for my application. Thus, the user must log in to access my homepage. For this I create a Bean and a filter. I used the answer to this question <a href="https://stackoverflow.com/questions/3841361/jsf-http-session-login">JSF HTTP Session Login</a> to be able to do it. But the <code>userManager</code> in the Filter is always null. I don't know how to put in this line the value of the user who is connected. </p>
  
  <pre><code>UserManager userManager = (UserManager) req.getSession().getAttribute("userManager");
  </code></pre>
  
  <p>Here is the filter.</p>
  
  <pre><code>public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
  
  HttpServletRequest req = (HttpServletRequest) request;
  HttpServletResponse res = (HttpServletResponse) response;
  UserManager userManager = (UserManager) req.getSession().getAttribute("userManager");       
  String loginURL = req.getContextPath() + "/index.jsf";
  
  if (userManager == null &amp;&amp; !userManager.isLoggedIn() &amp;&amp; !req.getRequestURI().equals(loginURL)) {
  
      res.sendRedirect(loginURL);
  
  } else {
  
      res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
      res.setHeader("Pragma", "no-cache"); // HTTP 1.0.
      res.setDateHeader("Expires", 0); // Proxies.
  
      chain.doFilter(request, response);
  
  }
  </code></pre>
  
  <p>When I put this condition in the if <code>!userManager.isLoggedIn()</code>, I have a marker that says:</p>
  
  <p><strong>Null pointer access: The variable userManager can only be null at this location, 1 quick fix available, Add @SuppressWarnings 'null' to 'doFilter()'</strong></p>
  
  <p>I tried to add it and I executed but I got an error <code>java.lang.NullPointerException</code>.
  I'm beginner in JSF. Please, I need your help.</p>
  
  <pre><code> ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/jsf-formulaire].[Faces Servlet]] "Servlet.service()" pour la servlet Faces Servlet a généré une exception: java.lang.NullPointerException
  at com.citech.pointage.fe.bean.filters.SessionFilter.doFilter(SessionFilter.java:61) [:]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
  at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0.Final]
  at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
  at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
  at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0.Final]
  at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
  at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
  at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]
  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
  at java.lang.Thread.run(Unknown Source) [:1.6.0_03]
  </code></pre>