KNOX-1344 - Atlas HA dispatch mishandling SSO redirection
authorPhil Zampino <pzampino@apache.org>
Thu, 7 Jun 2018 14:37:31 +0000 (10:37 -0400)
committerPhil Zampino <pzampino@apache.org>
Thu, 7 Jun 2018 14:37:31 +0000 (10:37 -0400)
gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/AtlasHaDispatch.java

index 36208e0..77eb21d 100644 (file)
@@ -57,18 +57,23 @@ public class AtlasHaDispatch extends DefaultHaDispatch {
     }
 
     @Override
-    protected void executeRequest(HttpUriRequest outboundRequest, HttpServletRequest inboundRequest, HttpServletResponse outboundResponse) throws IOException {
+    protected void executeRequest(HttpUriRequest      outboundRequest,
+                                  HttpServletRequest  inboundRequest,
+                                  HttpServletResponse outboundResponse) throws IOException {
         HttpResponse inboundResponse = null;
         try {
             inboundResponse = executeOutboundRequest(outboundRequest);
 
-            int statusCode = inboundResponse.getStatusLine().getStatusCode();
-            Header originalLocationHeader = inboundResponse.getFirstHeader("Location");
-
-            if((statusCode == HttpServletResponse.SC_MOVED_TEMPORARILY || statusCode == HttpServletResponse.SC_TEMPORARY_REDIRECT)
-                    && originalLocationHeader != null &&  !originalLocationHeader.getValue().endsWith("login.jsp")){
-                inboundResponse.removeHeaders("Location");
-                failoverRequest(outboundRequest, inboundRequest, outboundResponse, inboundResponse, new Exception("Atlas HA redirection"));
+            int sc = inboundResponse.getStatusLine().getStatusCode();
+            if(sc == HttpServletResponse.SC_MOVED_TEMPORARILY || sc == HttpServletResponse.SC_TEMPORARY_REDIRECT) {
+                if(!isLoginRedirect(inboundResponse.getFirstHeader("Location"))) {
+                    inboundResponse.removeHeaders("Location");
+                    failoverRequest(outboundRequest,
+                                    inboundRequest,
+                                    outboundResponse,
+                                    inboundResponse,
+                                    new Exception("Atlas HA redirection"));
+                }
             }
 
             writeOutboundResponse(outboundRequest, inboundRequest, outboundResponse, inboundResponse);
@@ -79,4 +84,13 @@ public class AtlasHaDispatch extends DefaultHaDispatch {
         }
     }
 
+    private boolean isLoginRedirect(Header locationHeader) {
+        boolean result = false;
+        if (locationHeader != null) {
+            String value = locationHeader.getValue();
+            result = (value.endsWith("login.jsp") || value.contains("originalUrl"));
+        }
+        return result;
+    }
+
 }