You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by pt...@apache.org on 2017/11/20 19:01:34 UTC

[48/50] [abbrv] storm git commit: [STORM-2815] UI HTTP server should return 403 if the user is unauthorized (1.x)

[STORM-2815] UI HTTP server should return 403 if the user is unauthorized (1.x)


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/ad13f457
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/ad13f457
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/ad13f457

Branch: refs/heads/metrics_v2
Commit: ad13f457bf465f14e34133c013da1b18088036dd
Parents: 818ed16
Author: Ethan Li <et...@gmail.com>
Authored: Thu Nov 16 08:29:54 2017 -0600
Committer: Ethan Li <et...@gmail.com>
Committed: Thu Nov 16 08:35:34 2017 -0600

----------------------------------------------------------------------
 .../src/clj/org/apache/storm/daemon/logviewer.clj    | 10 +++++-----
 storm-core/src/clj/org/apache/storm/ui/core.clj      |  3 ++-
 storm-core/src/clj/org/apache/storm/ui/helpers.clj   | 15 ++++++++-------
 3 files changed, 15 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/ad13f457/storm-core/src/clj/org/apache/storm/daemon/logviewer.clj
----------------------------------------------------------------------
diff --git a/storm-core/src/clj/org/apache/storm/daemon/logviewer.clj b/storm-core/src/clj/org/apache/storm/daemon/logviewer.clj
index a59cbb9..17bea01 100644
--- a/storm-core/src/clj/org/apache/storm/daemon/logviewer.clj
+++ b/storm-core/src/clj/org/apache/storm/daemon/logviewer.clj
@@ -848,7 +848,7 @@
                   (str "Search substring must be between 1 and 1024 UTF-8 "
                     "bytes in size (inclusive)"))))
             (catch Exception ex
-              (json-response (exception->json ex) callback :status 500))))
+              (json-response (exception->json ex 500) callback :status 500))))
         (json-response (unauthorized-user-json user) callback :status 403))
       (json-response {"error" "Not Found"
                       "errorMessage" "The file was not found on this node."}
@@ -1121,7 +1121,7 @@
           (.getHeader servlet-request "Origin")))
       (catch InvalidRequestException ex
         (log-error ex)
-        (json-response (exception->json ex) (:callback m) :status 400))))
+        (json-response (exception->json ex 400) (:callback m) :status 400))))
   (GET "/deepSearch/:topo-id" [:as {:keys [servlet-request servlet-response log-root]} topo-id & m]
     ;; We do not use servlet-response here, but do not remove it from the
     ;; :keys list, or this rule could stop working when an authentication
@@ -1141,7 +1141,7 @@
           (.getHeader servlet-request "Origin")))
       (catch InvalidRequestException ex
         (log-error ex)
-        (json-response (exception->json ex) (:callback m) :status 400))))
+        (json-response (exception->json ex 400) (:callback m) :status 400))))
   (GET "/searchLogs" [:as req & m]
     (try
       (let [servlet-request (:servlet-request req)
@@ -1154,7 +1154,7 @@
           (.getHeader servlet-request "Origin")))
       (catch InvalidRequestException ex
         (log-error ex)
-        (json-response (exception->json ex) (:callback m) :status 400))))
+        (json-response (exception->json ex 400) (:callback m) :status 400))))
   (GET "/listLogs" [:as req & m]
     (try
       (mark! logviewer:num-list-logs-http-requests)
@@ -1168,7 +1168,7 @@
           (.getHeader servlet-request "Origin")))
       (catch InvalidRequestException ex
         (log-error ex)
-        (json-response (exception->json ex) (:callback m) :status 400))))
+        (json-response (exception->json ex 400) (:callback m) :status 400))))
   (route/resources "/")
   (route/not-found "Page not found"))
 

http://git-wip-us.apache.org/repos/asf/storm/blob/ad13f457/storm-core/src/clj/org/apache/storm/ui/core.clj
----------------------------------------------------------------------
diff --git a/storm-core/src/clj/org/apache/storm/ui/core.clj b/storm-core/src/clj/org/apache/storm/ui/core.clj
index 4365f27..2c73520 100644
--- a/storm-core/src/clj/org/apache/storm/ui/core.clj
+++ b/storm-core/src/clj/org/apache/storm/ui/core.clj
@@ -1427,7 +1427,8 @@
     (try
       (handler request)
       (catch Exception ex
-        (json-response (exception->json ex) ((:query-params request) "callback") :status 500)))))
+        (let [status-code (if (instance? AuthorizationException ex) 403 500)]
+          (json-response (exception->json ex status-code) ((:query-params request) "callback") :status status-code))))))
 
 (def app
   (handler/site (-> main-routes

http://git-wip-us.apache.org/repos/asf/storm/blob/ad13f457/storm-core/src/clj/org/apache/storm/ui/helpers.clj
----------------------------------------------------------------------
diff --git a/storm-core/src/clj/org/apache/storm/ui/helpers.clj b/storm-core/src/clj/org/apache/storm/ui/helpers.clj
index 78c78be..1a98287 100644
--- a/storm-core/src/clj/org/apache/storm/ui/helpers.clj
+++ b/storm-core/src/clj/org/apache/storm/ui/helpers.clj
@@ -29,9 +29,10 @@
            [org.eclipse.jetty.server.nio SelectChannelConnector]
            [org.eclipse.jetty.server.ssl SslSocketConnector]
            [org.eclipse.jetty.servlet ServletHolder FilterMapping]
-	   [org.eclipse.jetty.util.ssl SslContextFactory]
+           [org.eclipse.jetty.util.ssl SslContextFactory]
            [org.eclipse.jetty.server DispatcherType]
-           [org.eclipse.jetty.servlets CrossOriginFilter])
+           [org.eclipse.jetty.servlets CrossOriginFilter]
+           (org.eclipse.jetty.http HttpStatus))
   (:require [ring.util servlet]
             [ring.util.response :as response])
   (:require [compojure.route :as route]
@@ -269,9 +270,9 @@
            (serialize-fn data))})
 
 (defn exception->json
-  [ex]
-  {"error" "Internal Server Error"
+  [ex status-code]
+  {"error" (str status-code " " (HttpStatus/getMessage status-code))
    "errorMessage"
-   (let [sw (java.io.StringWriter.)]
-     (.printStackTrace ex (java.io.PrintWriter. sw))
-     (.toString sw))})
+           (let [sw (java.io.StringWriter.)]
+             (.printStackTrace ex (java.io.PrintWriter. sw))
+             (.toString sw))})