remm        2005/08/29 04:02:06

  Modified:    catalina/src/share/org/apache/catalina/authenticator
                        FormAuthenticator.java
  Log:
  - 36136: Refactor the login and error page forward to protected methods,
    which indeed enables easier extending (the authenticate method being too
    large).
  - Submitted by Scott Stark.
  
  Revision  Changes    Path
  1.24      +47 -22    
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/authenticator/FormAuthenticator.java
  
  Index: FormAuthenticator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/authenticator/FormAuthenticator.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- FormAuthenticator.java    22 May 2005 17:18:28 -0000      1.23
  +++ FormAuthenticator.java    29 Aug 2005 11:02:06 -0000      1.24
  @@ -53,10 +53,9 @@
   
   public class FormAuthenticator
       extends AuthenticatorBase {
  +    
       private static Log log = LogFactory.getLog(FormAuthenticator.class);
   
  -
  -
       // ----------------------------------------------------- Instance 
Variables
   
   
  @@ -240,15 +239,7 @@
                           sm.getString("authenticator.requestBodyTooBig"));
                   return (false);
               }
  -            RequestDispatcher disp =
  -                context.getServletContext().getRequestDispatcher
  -                (config.getLoginPage());
  -            try {
  -                disp.forward(request.getRequest(), response.getResponse());
  -                response.finishResponse();
  -            } catch (Throwable t) {
  -                log.warn("Unexpected error forwarding to login page", t);
  -            }
  +            forwardToLoginPage(request, response, config);
               return (false);
           }
   
  @@ -264,14 +255,7 @@
               log.debug("Authenticating username '" + username + "'");
           principal = realm.authenticate(username, password);
           if (principal == null) {
  -            RequestDispatcher disp =
  -                context.getServletContext().getRequestDispatcher
  -                (config.getErrorPage());
  -            try {
  -                disp.forward(request.getRequest(), response.getResponse());
  -            } catch (Throwable t) {
  -                log.warn("Unexpected error forwarding to error page", t);
  -            }
  +            forwardToErrorPage(request, response, config);
               return (false);
           }
   
  @@ -315,6 +299,47 @@
   
   
       /**
  +     * Called to forward to the login page
  +     * 
  +     * @param request Request we are processing
  +     * @param response Response we are creating
  +     * @param config    Login configuration describing how authentication
  +     *              should be performed
  +     */
  +    protected void forwardToLoginPage(Request request, Response response, 
LoginConfig config) {
  +        RequestDispatcher disp =
  +            context.getServletContext().getRequestDispatcher
  +            (config.getLoginPage());
  +        try {
  +            disp.forward(request.getRequest(), response.getResponse());
  +            response.finishResponse();
  +        } catch (Throwable t) {
  +            log.warn("Unexpected error forwarding to login page", t);
  +        }
  +    }
  +
  +
  +    /**
  +     * Called to forward to the error page
  +     * 
  +     * @param request Request we are processing
  +     * @param response Response we are creating
  +     * @param config    Login configuration describing how authentication
  +     *              should be performed
  +     */
  +    protected void forwardToErrorPage(Request request, Response response, 
LoginConfig config) {
  +        RequestDispatcher disp =
  +            context.getServletContext().getRequestDispatcher
  +            (config.getErrorPage());
  +        try {
  +            disp.forward(request.getRequest(), response.getResponse());
  +        } catch (Throwable t) {
  +            log.warn("Unexpected error forwarding to error page", t);
  +        }
  +    }
  +
  +
  +    /**
        * Does this request match the saved one (so that it must be the redirect
        * we signalled after successful authentication?
        *
  @@ -423,7 +448,7 @@
        * @param session The session to contain the saved information
        * @throws IOException
        */
  -    private void saveRequest(Request request, Session session)
  +    protected void saveRequest(Request request, Session session)
           throws IOException {
   
           // Create and populate a SavedRequest object for this request
  @@ -478,7 +503,7 @@
        *
        * @param session Our current session
        */
  -    private String savedRequestURL(Session session) {
  +    protected String savedRequestURL(Session session) {
   
           SavedRequest saved =
               (SavedRequest) session.getNote(Constants.FORM_REQUEST_NOTE);
  
  
  

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

Reply via email to