Search code examples
jakarta-eejbossjaas

How to forward to j_security_check?


I'm using form based authentication (JBOSS/JAAS) but my form is sending the data to my Servlet so I can perform some checks before trying to login.

Now I need to forward to j_security_check but what I tried didn't work (404 error)...

How can I redirect/forward to the j_security_check (please note the application is running over https / sssl) ?

I can make it work with a redirect and the params go in the URL, but that is not safe (as the user/pass stays in the browser history, etc)...

Any ideas?


Solution

  • I see this is an old post, but I wanted to share an answer.

    If the original request is POST, you can simply forward to j_security_check after you do some processing.

    ...
    request.getParameterMap().put( "j_username", new String[]{ userId } );
    request.getParameterMap().put( "j_password", new String[]{ password } );
    
    try 
    {
        request.getRequestDispatcher("/j_security_check").forward( request , response );
        return null;
    } 
    catch (ServletException e) 
    {
        logger.error( e );
    } 
    catch (IOException e)
    {
        logger.error( e );
    }