hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From whe...@apache.org
Subject hadoop git commit: HADOOP-10703. HttpServer2 creates multiple authentication filters. Contributed by Benoy Antony.
Date Thu, 19 Mar 2015 05:32:22 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 b02f77540 -> b36fc6bc9


HADOOP-10703. HttpServer2 creates multiple authentication filters. Contributed by Benoy Antony.


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

Branch: refs/heads/branch-2
Commit: b36fc6bc9ca318fee5a03f7c9d5f5dc27d9131d4
Parents: b02f775
Author: Haohui Mai <wheat9@apache.org>
Authored: Wed Mar 18 22:31:59 2015 -0700
Committer: Haohui Mai <wheat9@apache.org>
Committed: Wed Mar 18 22:32:19 2015 -0700

----------------------------------------------------------------------
 hadoop-common-project/hadoop-common/CHANGES.txt |  3 ++
 .../org/apache/hadoop/http/HttpServer2.java     | 43 +++++++++++++++-----
 2 files changed, 36 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/b36fc6bc/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index 42cb2b2..18c7e4b 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -710,6 +710,9 @@ Release 2.7.0 - UNRELEASED
     ZKDelegationTokenSecretManager go down when old token cannot be deleted.
     (Arun Suresh via atm)
 
+    HADOOP-10703. HttpServer2 creates multiple authentication filters.
+    (Benoy Antony via wheat9)
+
 Release 2.6.1 - UNRELEASED
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/hadoop/blob/b36fc6bc/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java
index ae21505..945aba8 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java
@@ -626,15 +626,18 @@ public final class HttpServer2 implements FilterContainer {
   public void addFilter(String name, String classname,
       Map<String, String> parameters) {
 
+    FilterHolder filterHolder = getFilterHolder(name, classname, parameters);
     final String[] USER_FACING_URLS = { "*.html", "*.jsp" };
-    defineFilter(webAppContext, name, classname, parameters, USER_FACING_URLS);
+    FilterMapping fmap = getFilterMapping(name, USER_FACING_URLS);
+    defineFilter(webAppContext, filterHolder, fmap);
     LOG.info(
         "Added filter " + name + " (class=" + classname + ") to context " + webAppContext.getDisplayName());
     final String[] ALL_URLS = { "/*" };
+    fmap = getFilterMapping(name, ALL_URLS);
     for (Map.Entry<Context, Boolean> e : defaultContexts.entrySet()) {
       if (e.getValue()) {
         Context ctx = e.getKey();
-        defineFilter(ctx, name, classname, parameters, ALL_URLS);
+        defineFilter(ctx, filterHolder, fmap);
         LOG.info("Added filter " + name + " (class=" + classname
             + ") to context " + ctx.getDisplayName());
       }
@@ -646,9 +649,11 @@ public final class HttpServer2 implements FilterContainer {
   public void addGlobalFilter(String name, String classname,
       Map<String, String> parameters) {
     final String[] ALL_URLS = { "/*" };
-    defineFilter(webAppContext, name, classname, parameters, ALL_URLS);
+    FilterHolder filterHolder = getFilterHolder(name, classname, parameters);
+    FilterMapping fmap = getFilterMapping(name, ALL_URLS);
+    defineFilter(webAppContext, filterHolder, fmap);
     for (Context ctx : defaultContexts.keySet()) {
-      defineFilter(ctx, name, classname, parameters, ALL_URLS);
+      defineFilter(ctx, filterHolder, fmap);
     }
     LOG.info("Added global filter '" + name + "' (class=" + classname + ")");
   }
@@ -658,17 +663,35 @@ public final class HttpServer2 implements FilterContainer {
    */
   public static void defineFilter(Context ctx, String name,
       String classname, Map<String,String> parameters, String[] urls) {
+    FilterHolder filterHolder = getFilterHolder(name, classname, parameters);
+    FilterMapping fmap = getFilterMapping(name, urls);
+    defineFilter(ctx, filterHolder, fmap);
+  }
 
-    FilterHolder holder = new FilterHolder();
-    holder.setName(name);
-    holder.setClassName(classname);
-    holder.setInitParameters(parameters);
+  /**
+   * Define a filter for a context and set up default url mappings.
+   */
+  private static void defineFilter(Context ctx, FilterHolder holder,
+      FilterMapping fmap) {
+    ServletHandler handler = ctx.getServletHandler();
+    handler.addFilter(holder, fmap);
+  }
+
+  private static FilterMapping getFilterMapping(String name, String[] urls) {
     FilterMapping fmap = new FilterMapping();
     fmap.setPathSpecs(urls);
     fmap.setDispatches(Handler.ALL);
     fmap.setFilterName(name);
-    ServletHandler handler = ctx.getServletHandler();
-    handler.addFilter(holder, fmap);
+    return fmap;
+  }
+
+  private static FilterHolder getFilterHolder(String name, String classname,
+      Map<String, String> parameters) {
+    FilterHolder holder = new FilterHolder();
+    holder.setName(name);
+    holder.setClassName(classname);
+    holder.setInitParameters(parameters);
+    return holder;
   }
 
   /**


Mime
View raw message