Author: markt
Date: Wed Oct 19 18:17:27 2011
New Revision: 1186380

URL: http://svn.apache.org/viewvc?rev=1186380&view=rev
Log:
Code clean-up. No functional change.
Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    
tomcat/tc7.0.x/trunk/java/org/apache/catalina/authenticator/FormAuthenticator.java

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Oct 19 18:17:27 2011
@@ -1 +1 @@
-/tomcat/trunk:1156115,1156171,1156276,1156304,1156519,1156530,1156602,1157015,1157018,1157151,1157198,1157204,1157810,1157832,1157834,1157847,1157908,1157939,1158155,1158160,1158176,1158195,1158198-1158199,1158227,1158331,1158334-1158335,1158426,1160347,1160592,1160611,1160619,1160626,1160639,1160652,1160720-1160721,1160772,1160774,1160776,1161303,1161310,1161322,1161339,1161486,1161540,1161549,1161584,1162082,1162149,1162169,1162721,1162769,1162836,1162932,1163630,1164419,1164438,1164469,1164480,1164567,1165234,1165247-1165248,1165253,1165273,1165282,1165309,1165331,1165338,1165347,1165360-1165361,1165367-1165368,1165602,1165608,1165677,1165693,1165721,1165723,1165728,1165730,1165738,1165746,1165765,1165777,1165918,1165921,1166077,1166150-1166151,1166290,1166366,1166620,1166686,1166693,1166752,1166757,1167368,1167394,1169447,1170647,1171692,1172233-1172234,1172236,1172269,1172278,1172282,1172556,1172610,1172664,1172689,1172711,1173020-1173021,1173082,1173088,1173090,1173096
 
,1173241,1173256,1173288,1173333,1173342,1173461,1173614,1173630,1173659,1173722,1174061,1174239,1174322,1174325,1174329-1174330,1174337-1174339,1174343,1174353,1174799,1174882,1174884,1174983,1175155,1175158,1175167,1175182,1175190,1175201,1175272,1175275,1175283,1175582,1175589-1175590,1175594,1175602,1175613,1175633,1175690,1175713,1175889,1175896,1175907,1176584,1176590,1176799,1177050,1177060,1177125,1177152,1177160,1177245,1177850,1177862,1177978,1178209,1178228,1178233,1178449,1178542,1178681,1178684,1178721,1179268,1179274,1180261,1180865,1180891,1180894,1180907,1181028,1181123,1181125,1181136,1181291,1181743,1182796,1183078,1183105,1183142,1183328,1183339-1183340,1183492-1183494,1183605,1184917,1184919,1185018,1185020,1185200,1185588,1185626,1185756,1185758,1186011,1186042-1186045,1186104,1186123,1186137,1186153,1186254,1186257
+/tomcat/trunk:1156115,1156171,1156276,1156304,1156519,1156530,1156602,1157015,1157018,1157151,1157198,1157204,1157810,1157832,1157834,1157847,1157908,1157939,1158155,1158160,1158176,1158195,1158198-1158199,1158227,1158331,1158334-1158335,1158426,1160347,1160592,1160611,1160619,1160626,1160639,1160652,1160720-1160721,1160772,1160774,1160776,1161303,1161310,1161322,1161339,1161486,1161540,1161549,1161584,1162082,1162149,1162169,1162721,1162769,1162836,1162932,1163630,1164419,1164438,1164469,1164480,1164567,1165234,1165247-1165248,1165253,1165273,1165282,1165309,1165331,1165338,1165347,1165360-1165361,1165367-1165368,1165602,1165608,1165677,1165693,1165721,1165723,1165728,1165730,1165738,1165746,1165765,1165777,1165918,1165921,1166077,1166150-1166151,1166290,1166366,1166620,1166686,1166693,1166752,1166757,1167368,1167394,1169447,1170647,1171692,1172233-1172234,1172236,1172269,1172278,1172282,1172556,1172610,1172664,1172689,1172711,1173020-1173021,1173082,1173088,1173090,1173096
 
,1173241,1173256,1173288,1173333,1173342,1173461,1173614,1173630,1173659,1173722,1174061,1174239,1174322,1174325,1174329-1174330,1174337-1174339,1174343,1174353,1174799,1174882,1174884,1174983,1175155,1175158,1175167,1175182,1175190,1175201,1175272,1175275,1175283,1175582,1175589-1175590,1175594,1175602,1175613,1175633,1175690,1175713,1175889,1175896,1175907,1176584,1176590,1176799,1177050,1177060,1177125,1177152,1177160,1177245,1177850,1177862,1177978,1178209,1178228,1178233,1178449,1178542,1178681,1178684,1178721,1179268,1179274,1180261,1180865,1180891,1180894,1180907,1181028,1181123,1181125,1181136,1181291,1181743,1182796,1183078,1183105,1183142,1183328,1183339-1183340,1183492-1183494,1183605,1184917,1184919,1185018,1185020,1185200,1185588,1185626,1185756,1185758,1186011,1186042-1186045,1186104,1186123,1186137,1186153,1186254,1186257,1186377

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/authenticator/FormAuthenticator.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/authenticator/FormAuthenticator.java?rev=1186380&r1=1186379&r2=1186380&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/authenticator/FormAuthenticator.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/authenticator/FormAuthenticator.java
 Wed Oct 19 18:17:27 2011
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -55,7 +55,7 @@ import org.apache.tomcat.util.http.MimeH
 
 public class FormAuthenticator
     extends AuthenticatorBase {
-    
+
     private static final Log log = LogFactory.getLog(FormAuthenticator.class);
 
     // ----------------------------------------------------- Instance Variables
@@ -102,9 +102,9 @@ public class FormAuthenticator
         return characterEncoding;
     }
 
-    
+
     /**
-     * Set the character encoding to be used to read the username and 
password. 
+     * Set the character encoding to be used to read the username and password.
      */
     public void setCharacterEncoding(String encoding) {
         characterEncoding = encoding;
@@ -156,42 +156,48 @@ public class FormAuthenticator
         Principal principal = request.getUserPrincipal();
         String ssoId = (String) request.getNote(Constants.REQ_SSOID_NOTE);
         if (principal != null) {
-            if (log.isDebugEnabled())
+            if (log.isDebugEnabled()) {
                 log.debug("Already authenticated '" +
                     principal.getName() + "'");
+            }
             // Associate the session with any existing SSO session
-            if (ssoId != null)
+            if (ssoId != null) {
                 associate(ssoId, request.getSessionInternal(true));
+            }
             return (true);
         }
 
         // Is there an SSO session against which we can try to reauthenticate?
         if (ssoId != null) {
-            if (log.isDebugEnabled())
+            if (log.isDebugEnabled()) {
                 log.debug("SSO Id " + ssoId + " set; attempting " +
                           "reauthentication");
+            }
             // Try to reauthenticate using data cached by SSO.  If this fails,
             // either the original SSO logon was of DIGEST or SSL (which
             // we can't reauthenticate ourselves because there is no
             // cached username and password), or the realm denied
             // the user's reauthentication for some reason.
             // In either case we have to prompt the user for a logon */
-            if (reauthenticateFromSSO(ssoId, request))
+            if (reauthenticateFromSSO(ssoId, request)) {
                 return true;
+            }
         }
 
         // Have we authenticated this user before but have caching disabled?
         if (!cache) {
             session = request.getSessionInternal(true);
-            if (log.isDebugEnabled())
+            if (log.isDebugEnabled()) {
                 log.debug("Checking for reauthenticate in session " + session);
+            }
             String username =
                 (String) session.getNote(Constants.SESS_USERNAME_NOTE);
             String password =
                 (String) session.getNote(Constants.SESS_PASSWORD_NOTE);
             if ((username != null) && (password != null)) {
-                if (log.isDebugEnabled())
+                if (log.isDebugEnabled()) {
                     log.debug("Reauthenticating username '" + username + "'");
+                }
                 principal =
                     context.getRealm().authenticate(username, password);
                 if (principal != null) {
@@ -203,8 +209,9 @@ public class FormAuthenticator
                         return (true);
                     }
                 }
-                if (log.isDebugEnabled())
+                if (log.isDebugEnabled()) {
                     log.debug("Reauthentication failed, proceed normally");
+                }
             }
         }
 
@@ -212,10 +219,11 @@ public class FormAuthenticator
         // authentication?  If so, forward the *original* request instead.
         if (matchRequest(request)) {
             session = request.getSessionInternal(true);
-            if (log.isDebugEnabled())
+            if (log.isDebugEnabled()) {
                 log.debug("Restore request from session '"
-                          + session.getIdInternal() 
+                          + session.getIdInternal()
                           + "'");
+            }
             principal = (Principal)
                 session.getNote(Constants.FORM_PRINCIPAL_NOTE);
             register(request, response, principal, Constants.FORM_METHOD,
@@ -228,12 +236,14 @@ public class FormAuthenticator
                 session.removeNote(Constants.SESS_PASSWORD_NOTE);
             }
             if (restoreRequest(request, session)) {
-                if (log.isDebugEnabled())
+                if (log.isDebugEnabled()) {
                     log.debug("Proceed to restored request");
+                }
                 return (true);
             } else {
-                if (log.isDebugEnabled())
+                if (log.isDebugEnabled()) {
                     log.debug("Restore of original request failed");
+                }
                 response.sendError(HttpServletResponse.SC_BAD_REQUEST);
                 return (false);
             }
@@ -254,8 +264,9 @@ public class FormAuthenticator
         // No -- Save this request and redirect to the form login page
         if (!loginAction) {
             session = request.getSessionInternal(true);
-            if (log.isDebugEnabled())
+            if (log.isDebugEnabled()) {
                 log.debug("Save request in session '" + 
session.getIdInternal() + "'");
+            }
             try {
                 saveRequest(request, session);
             } catch (IOException ioe) {
@@ -277,23 +288,27 @@ public class FormAuthenticator
         }
         String username = request.getParameter(Constants.FORM_USERNAME);
         String password = request.getParameter(Constants.FORM_PASSWORD);
-        if (log.isDebugEnabled())
+        if (log.isDebugEnabled()) {
             log.debug("Authenticating username '" + username + "'");
+        }
         principal = realm.authenticate(username, password);
         if (principal == null) {
             forwardToErrorPage(request, response, config);
             return (false);
         }
 
-        if (log.isDebugEnabled())
+        if (log.isDebugEnabled()) {
             log.debug("Authentication of '" + username + "' was successful");
+        }
 
-        if (session == null)
+        if (session == null) {
             session = request.getSessionInternal(false);
+        }
         if (session == null) {
-            if (containerLog.isDebugEnabled())
+            if (containerLog.isDebugEnabled()) {
                 containerLog.debug
                     ("User took so long to log on the session expired");
+            }
             if (landingPage == null) {
                 response.sendError(HttpServletResponse.SC_REQUEST_TIMEOUT,
                         sm.getString("authenticator.sessionExpired"));
@@ -321,9 +336,10 @@ public class FormAuthenticator
         // Redirect the user to the original request URI (which will cause
         // the original request to be restored)
         requestURI = savedRequestURL(session);
-        if (log.isDebugEnabled())
+        if (log.isDebugEnabled()) {
             log.debug("Redirecting to original '" + requestURI + "'");
-        if (requestURI == null)
+        }
+        if (requestURI == null) {
             if (landingPage == null) {
                 response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                         sm.getString("authenticator.formlogin"));
@@ -337,8 +353,9 @@ public class FormAuthenticator
                 session.setNote(Constants.FORM_REQUEST_NOTE, saved);
                 response.sendRedirect(response.encodeRedirectURL(uri));
             }
-        else
+        } else {
             response.sendRedirect(response.encodeRedirectURL(requestURI));
+        }
         return (false);
 
     }
@@ -355,7 +372,7 @@ public class FormAuthenticator
 
     /**
      * Called to forward to the login page
-     * 
+     *
      * @param request Request we are processing
      * @param response Response we are populating
      * @param config    Login configuration describing how authentication
@@ -367,7 +384,7 @@ public class FormAuthenticator
     protected void forwardToLoginPage(Request request,
             HttpServletResponse response, LoginConfig config)
             throws IOException {
-        
+
         if (log.isDebugEnabled()) {
             log.debug(sm.getString("formAuthenticator.forwardLogin",
                     request.getRequestURI(), request.getMethod(),
@@ -386,7 +403,7 @@ public class FormAuthenticator
                     msg);
             return;
         }
-        
+
         RequestDispatcher disp =
             context.getServletContext().getRequestDispatcher(loginPage);
         try {
@@ -407,7 +424,7 @@ public class FormAuthenticator
 
     /**
      * Called to forward to the error page
-     * 
+     *
      * @param request Request we are processing
      * @param response Response we are populating
      * @param config    Login configuration describing how authentication
@@ -419,7 +436,7 @@ public class FormAuthenticator
     protected void forwardToErrorPage(Request request,
             HttpServletResponse response, LoginConfig config)
             throws IOException {
-        
+
         String errorPage = config.getErrorPage();
         if (errorPage == null || errorPage.length() == 0) {
             String msg = sm.getString("formAuthenticator.noErrorPage",
@@ -459,23 +476,27 @@ public class FormAuthenticator
 
       // Has a session been created?
       Session session = request.getSessionInternal(false);
-      if (session == null)
-          return (false);
+      if (session == null) {
+        return (false);
+    }
 
       // Is there a saved request?
       SavedRequest sreq = (SavedRequest)
           session.getNote(Constants.FORM_REQUEST_NOTE);
-      if (sreq == null)
-          return (false);
+      if (sreq == null) {
+        return (false);
+    }
 
       // Is there a saved principal?
-      if (session.getNote(Constants.FORM_PRINCIPAL_NOTE) == null)
-          return (false);
+      if (session.getNote(Constants.FORM_PRINCIPAL_NOTE) == null) {
+        return (false);
+    }
 
       // Does the request URI match?
       String requestURI = request.getRequestURI();
-      if (requestURI == null)
-          return (false);
+      if (requestURI == null) {
+        return (false);
+    }
       return (requestURI.equals(sreq.getRequestURI()));
 
     }
@@ -498,8 +519,9 @@ public class FormAuthenticator
             session.getNote(Constants.FORM_REQUEST_NOTE);
         session.removeNote(Constants.FORM_REQUEST_NOTE);
         session.removeNote(Constants.FORM_PRINCIPAL_NOTE);
-        if (saved == null)
+        if (saved == null) {
             return (false);
+        }
 
         // Modify our current request to reflect the original one
         request.clearCookies();
@@ -526,13 +548,13 @@ public class FormAuthenticator
                 }
             }
         }
-        
+
         request.clearLocales();
         Iterator<Locale> locales = saved.getLocales();
         while (locales.hasNext()) {
             request.addLocale(locales.next());
         }
-        
+
         request.getCoyoteRequest().getParameters().recycle();
         request.getCoyoteRequest().getParameters().setQueryStringEncoding(
                 request.getConnector().getURIEncoding());
@@ -543,17 +565,17 @@ public class FormAuthenticator
         while (is.read(buffer) >= 0) {
             // Ignore request body
         }
-        
+
         ByteChunk body = saved.getBody();
         String method = saved.getMethod();
-        
+
         if (body != null) {
             request.getCoyoteRequest().action
                 (ActionCode.REQ_SET_BODY_REPLAY, body);
 
             // Set content type
             MessageBytes contentType = MessageBytes.newInstance();
-            
+
             // If no content type specified, use default for POST
             String savedContentType = saved.getContentType();
             if (savedContentType == null && "POST".equalsIgnoreCase(method)) {
@@ -590,8 +612,9 @@ public class FormAuthenticator
         SavedRequest saved = new SavedRequest();
         Cookie cookies[] = request.getCookies();
         if (cookies != null) {
-            for (int i = 0; i < cookies.length; i++)
+            for (int i = 0; i < cookies.length; i++) {
                 saved.addCookie(cookies[i]);
+            }
         }
         Enumeration<String> names = request.getHeaderNames();
         while (names.hasMoreElements()) {
@@ -617,7 +640,7 @@ public class FormAuthenticator
         byte[] buffer = new byte[4096];
         int bytesRead;
         InputStream is = request.getInputStream();
-    
+
         while ( (bytesRead = is.read(buffer) ) >= 0) {
             body.append(buffer, 0, bytesRead);
         }
@@ -648,8 +671,9 @@ public class FormAuthenticator
 
         SavedRequest saved =
             (SavedRequest) session.getNote(Constants.FORM_REQUEST_NOTE);
-        if (saved == null)
+        if (saved == null) {
             return (null);
+        }
         StringBuilder sb = new StringBuilder(saved.getRequestURI());
         if (saved.getQueryString() != null) {
             sb.append('?');



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to