title: how to make a filter to avoid accessing a page if not logged?
body: <p>So I´m writing an interceptor so when a user tryies to access a page without being logged he gets send back to the login
  The thing is that my filter is that the condition that checks if a user is logged is always true and whats worst; it also intercept resources (css, images, js)
  So how should I change my filter so it works??
  Here is my code:</p>
  
  <pre><code>@Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 
          throws IOException, ServletException {
       try {
          // check whether session variable is set
          HttpServletRequest req = (HttpServletRequest) request;
          HttpServletResponse res = (HttpServletResponse) response;
          boolean estaLoggeado = false;
          if (req.getSession().getAttribute("estaLoggeado") != null) {
              estaLoggeado = new Boolean("" + req.getSession().getAttribute("estaLoggeado"));
          }
          //  allow user to proccede if url is login.xhtml or user logged in or user is accessing any page in //public folder
          String reqURI = req.getRequestURI();
          System.out.println(reqURI);
          System.out.println("index: " + reqURI.indexOf("/index.xhtml"));
          System.out.println("pages: " + reqURI.indexOf("/pages/"));
          System.out.println("resources: " + reqURI.contains("javax.faces.resource"));
          System.out.println("log: " + estaLoggeado);
          if ((reqURI.indexOf("/index.xhtml") &gt;= 0 || reqURI.indexOf("/pages/") &gt;= 0 || reqURI.contains("javax.faces.resource"))) {
              System.out.println("Si");
              chain.doFilter(request, response);
          } else {   // user didn't log in but asking for a page that is not allowed so take user to login page
              System.out.println("No");
              res.sendRedirect(req.getContextPath() + "/pages/index.xhtml");  // Anonymous user. Redirect to login page
          }
       } catch(Throwable t) {
          System.out.println(t.getMessage());
      }
  } //doFilter
  </code></pre>
  
  <p>Thanks in advance!!</p>