title: JSF 2.0 redirect home page if already logged
body: <p>How to redirect user to home page if user is already logged. I use Filter class for login page but it doesn't work properly. my code is:</p>
  
  <pre><code>@WebFilter(filterName = "loginFilter",
  urlPatterns ={"/login.xhtml"})
  public class LoginFilter implements Filter{
  
      private FilterConfig filterconfig;
      @Override
      public void init(FilterConfig filterConfig) throws ServletException {
          this.filterconfig = filterconfig;
      }
  
      @Override
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
  
          HttpServletRequest httprequest =(HttpServletRequest) request;
          HttpServletResponse httpresponse =(HttpServletResponse) response;
          try{
          if(httprequest.getUserPrincipal() != null){
  
              System.out.printf("User authenticated with " + httprequest.getRemoteUser() + " username conected.");
              httprequest.getRequestDispatcher("/home.xhtml").forward(request, response);
          } else{
              chain.doFilter(request, response);
          }
          }catch(Exception){
              //do something
          }
  
      }
  
      @Override
      public void destroy() {
          System.out.print("Existing from loginFilter");
      }
  
  }
  </code></pre>
  
  <p>Here is my problem: user logged to web and do some navigation and things and back to login page using browser's back button without logout and again enter username password then press login button. Then it throws exception
  IndexOutofBoundsException. I just need to check when user navigate to login page using either link or browser's back button, and redirect to home page. any suggestion? </p>