1 Reply Latest reply on Dec 5, 2006 8:03 AM by lost traveller

    Forcing redirection to a specific page with j_security_check

    Laurent Duperval Newbie

      Hi,

      We are using form-based authentication with our application. Credential information is stored in a database and everything works fine.

      My problem is that whenever a user is presented with a login page, I want to redirect him/her to a specific page (a Struts action, actually) after a successful login.

      What currently happens is that if a user is on page B and her session times out, but then clicks on a link to access page C, the login page is shown.

      After the login page has been shown, and successful login information has been provided, the user is then directed to page C. This causes problems in our application.

      I need to force the redirection to go to page A, under all circumstances. How can I configure this?

      Thanks,

      L

        • 1. Re: Forcing redirection to a specific page with j_security_c
          lost traveller Newbie

          I needed this too and after searching the forums it appears lots of people ask this question, the answer is that there is no neat solution, your best solution is to write a javax.servlet.Filter for every page that sets some session attribute when the user is logged in, e.g.

           public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
           throws IOException, ServletException
           {
          
           HttpSession session = ((HttpServletRequest)request).getSession();
           if(session.getAttribute("login_flag") == null)
           {
           session.setAttribute("login_flag", "1");
           servletContext.getRequestDispatcher(welcomePage).forward(request, response);
           }
           else
           {
           chain.doFilter(request, response);
           }
          
           }
          

          Its not nice but it works.