title: How to stop authorization WebFilter from redirecting me to homepage every time I invoke a request from another page
body: <p>I am trying to build a simple Login/Signup Interface using <em>JSF</em>, <em>Hibernate</em> and <em>WildFly</em>. I have used the following AuthorizationFilter class so far in order to redirect to the login page if the session is not authenticated.
  I also implemented a simple User CRUD view called </p>
  
  <blockquote>
    <p>/admin.xhtml</p>
  </blockquote>
  
  <p>which manages user entries in the DB. Now my problem is that every time I click a button to CRUD a User entry in admin.xhtml I am automatically redirected to the login page. When I disable this WebFilter everything works perfectly fine with the CRUD Interface. 
  How can I prevent this WebFilter from redirecting me after I have logged in and created a session?</p>
  
  <pre><code>import java.io.IOException;
  import javax.servlet.Filter;
  import javax.servlet.FilterChain;
  import javax.servlet.FilterConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  import javax.servlet.annotation.WebFilter;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  @WebFilter(filterName = "AuthFilter", urlPatterns = { "*.xhtml" })
   public class AuthorizationFilter implements Filter {
  
  public AuthorizationFilter() {
  }
  
  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
  
  }
  
  @Override
  public void doFilter(ServletRequest request, ServletResponse response,
          FilterChain chain) throws IOException, ServletException {
      try {
  
          HttpServletRequest reqt = (HttpServletRequest) request;
          HttpServletResponse resp = (HttpServletResponse) response;
          HttpSession ses = reqt.getSession(false);
  
          String reqURI = reqt.getRequestURI();
          if (reqURI.contains("/login.xhtml")
                  || (ses != null &amp;&amp; ses.getAttribute("username") != null)
                  || reqURI.contains("/public/")
                  || reqURI.contains("javax.faces.resource"))
              chain.doFilter(request, response);
          else
              resp.sendRedirect(reqt.getContextPath() + "/faces/login.xhtml");
      } catch (Exception e) {
          System.out.println(e.getMessage());
      }
  }
  
  @Override
  public void destroy() {
  
  }
  }
  </code></pre>