Hi,

I'm using Tomcat 4.0.x. I have a requirement to have a login box on the first page of 
my
site. This cannot be done in this version of Tomcat as we get "Invalid Reference to 
Login Page",
as the requestURI is set to null ( java realms require us to try and access a 
protected resource, then
get transferred to the login page ).

I came up with the solution to post the login details to a servlet. This would look 
a little like this:

http://localhost:8080/mysite/LoginProxy?j_username=administrator&j_password=midletsite&j_forward=/index.jsp

My program would then alter the Request object, changing the requestURI field with the 
j_forward parameter.
I couldn't get access to any setter properties of the request, so I subclasses 
HttpServletRequestWrapper
and overrode the getRequestURI method to return the j_forward parameter's value if the 
requestURI was
null. I then call dispatchRequest() with my HttpServletRequestWrapper object. 

However this does not work. I get the error The requested resource 
(/mysite/j_security_check) is not available.
However, if I simply put in http://localhost:8080/mysite/j_security_check, I do hit 
the login target.
I expect this has something to do with the way that the request comes to tomcat. Maybe 
it
checks for j_security_check when it checks whether my Proxy can be accessed. I'd hoped 
that it
was some kind of accessible virtual page that could be accessed.

Is my line of investigation doomed?



Here's the code exerpt....



   public void service ( HttpServletRequest a_Request, HttpServletResponse a_Response )
    throws java.io.IOException, ServletException
    /*
    -----------------------------------------------------------------------------
      20 July 03  Ben Jessel  Created.
    -----------------------------------------------------------------------------
    */
    {
        // Method Location
        final String ksLocation = "service ( HttpServletRequest a_Request, 
HttpServletResponse a_Response )";
    
        // Get the map of parameters from this request.
        Map paramMap = a_Request.getParameterMap();
        
        String sUserName        = a_Request.getParameter ( c_ksUserNameParam );
        String sPassword        = a_Request.getParameter ( c_ksPasswordParam );
        String sForward         = a_Request.getParameter ( c_ksForwardParam  );

        LoginRequest tst = new LoginRequest ( a_Request, sForward ) ;
       
        tst.setAttribute("j_username", sUserName );
        tst.setAttribute("j_password", sPassword );
        System.out.println(  tst.getContextPath() + "/j_security_check?j_username=" + 
sUserName + "&j_password=" + sPassword );
        
        // Get the RequestDispatcher
        RequestDispatcher rd = 
getServletConfig().getServletContext().getRequestDispatcher( tst.getContextPath() + 
"/j_security_check?j_username=" + sUserName + "&j_password=" + sPassword  );
       rd.forward(tst, a_Response);
    }
    

    
}
class LoginRequest extends HttpServletRequestWrapper
{
    String m_sForwardURI = "";
    String requestURI = "/midletsite/index.jsp";
    
    /**
         * @param arg0
         */
        public LoginRequest(HttpServletRequest arg0) {
                super(arg0);
                
    }

    /**
     * @param arg0
     */
    public LoginRequest(HttpServletRequest arg0, String a_sForwardURI ) {
        super(arg0);
        
        m_sForwardURI = a_sForwardURI;
        
    }
    
    public String getRequestURI()
    {
       return ( ( super.getRequestURI()==null ) || 
             ( getRequestURI().trim().length()==0 ) ) ? m_sForwardURI : 
              super.getRequestURI();
    }



__________________________________________________________________________
Join Freeserve http://www.freeserve.com/time/

Winner of the 2003 Internet Service Providers' Association awards for Best Unmetered 
ISP and Best Consumer Application.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to