knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kris...@apache.org
Subject knox git commit: KNOX-1647 - Identity Assertion should not modify order of query params
Date Tue, 18 Dec 2018 10:13:47 GMT
Repository: knox
Updated Branches:
  refs/heads/master fc1f085f3 -> 4d08dcac1


KNOX-1647 - Identity Assertion should not modify order of query params

Signed-off-by: Kevin Risden <krisden@apache.org>


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

Branch: refs/heads/master
Commit: 4d08dcac1c1b256281855c91fec1a5e9219e1e30
Parents: fc1f085
Author: Kevin Risden <krisden@apache.org>
Authored: Fri Nov 30 17:52:32 2018 -0500
Committer: Kevin Risden <krisden@apache.org>
Committed: Tue Dec 18 05:13:05 2018 -0500

----------------------------------------------------------------------
 .../IdentityAsserterHttpServletRequestWrapper.java    | 14 +++++++-------
 .../gateway/encrypturi/EncryptStepContextParams.java  |  4 ++--
 .../filter/rewrite/impl/UrlRewriteContextImpl.java    |  5 ++---
 .../java/org/apache/knox/gateway/util/HttpUtils.java  | 13 ++++++-------
 .../org/apache/knox/gateway/util/HttpUtilsTest.java   |  7 ++++---
 .../knox/gateway/util/urltemplate/Expander.java       |  4 ++--
 .../apache/knox/gateway/util/urltemplate/Matcher.java |  3 +--
 .../knox/gateway/util/urltemplate/MockParams.java     |  4 ++--
 .../knox/gateway/util/urltemplate/ExpanderTest.java   |  4 ++--
 .../knox/gateway/util/urltemplate/RewriterTest.java   |  2 +-
 10 files changed, 29 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/4d08dcac/gateway-provider-identity-assertion-common/src/main/java/org/apache/knox/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
----------------------------------------------------------------------
diff --git a/gateway-provider-identity-assertion-common/src/main/java/org/apache/knox/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
b/gateway-provider-identity-assertion-common/src/main/java/org/apache/knox/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
index ace4ad1..280dfc7 100644
--- a/gateway-provider-identity-assertion-common/src/main/java/org/apache/knox/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
+++ b/gateway-provider-identity-assertion-common/src/main/java/org/apache/knox/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
@@ -37,10 +37,10 @@ import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.security.Principal;
 import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Collections;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 
@@ -77,7 +77,7 @@ private static SpiGatewayMessages log = MessagesFactory.get( SpiGatewayMessages.
   }
 
   private Map<String, String[]> convertValuesToStringArrays() {
-    Map<String, String[]> arrayMap = new HashMap<>();
+    Map<String, String[]> arrayMap = new LinkedHashMap<>();
     String name;
     Enumeration<String> names = getParameterNames();
     while (names.hasMoreElements()) {
@@ -94,7 +94,7 @@ private static SpiGatewayMessages log = MessagesFactory.get( SpiGatewayMessages.
     try {
       params = getParams();
       if (params == null) {
-        params = new HashMap<>();
+        params = new LinkedHashMap<>();
       }
       e = Collections.enumeration(params.keySet());
     } catch (UnsupportedEncodingException e1) {
@@ -111,7 +111,7 @@ private static SpiGatewayMessages log = MessagesFactory.get( SpiGatewayMessages.
     try {
       params = getParams();
       if (params == null) {
-        params = new HashMap<>();
+        params = new LinkedHashMap<>();
       }
       p = params.get(name).toArray(p);
     } catch (UnsupportedEncodingException e) {
@@ -129,7 +129,7 @@ private static SpiGatewayMessages log = MessagesFactory.get( SpiGatewayMessages.
         params = HttpUtils.splitQuery( qString );
       }
       else {
-        params = new HashMap<>();
+        params = new LinkedHashMap<>();
       }
     }
     else {
@@ -155,7 +155,7 @@ private static SpiGatewayMessages log = MessagesFactory.get( SpiGatewayMessages.
     try {
       params = getParams();
       if (params == null) {
-        params = new HashMap<>();
+        params = new LinkedHashMap<>();
       }
       ArrayList<String> al = new ArrayList<>();
       al.add(username);
@@ -231,7 +231,7 @@ private static SpiGatewayMessages log = MessagesFactory.get( SpiGatewayMessages.
       String body = IOUtils.toString( super.getInputStream(), encoding );
       Map<String, List<String>> params = getParams( body );
       if (params == null) {
-        params = new HashMap<>();
+        params = new LinkedHashMap<>();
       }
       body = urlEncode( params, encoding );
       // ASCII is OK here because the urlEncode about should have already escaped

http://git-wip-us.apache.org/repos/asf/knox/blob/4d08dcac/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/knox/gateway/encrypturi/EncryptStepContextParams.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/knox/gateway/encrypturi/EncryptStepContextParams.java
b/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/knox/gateway/encrypturi/EncryptStepContextParams.java
index b6975b1..70043a8 100644
--- a/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/knox/gateway/encrypturi/EncryptStepContextParams.java
+++ b/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/knox/gateway/encrypturi/EncryptStepContextParams.java
@@ -17,7 +17,7 @@
  */
 package org.apache.knox.gateway.encrypturi;
 
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -25,7 +25,7 @@ import java.util.Set;
 import org.apache.knox.gateway.util.urltemplate.Params;
 
 public class EncryptStepContextParams implements Params {
-  Map<String, List<String>> params = new HashMap<>();
+  Map<String, List<String>> params = new LinkedHashMap<>();
 
   public EncryptStepContextParams() {
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/4d08dcac/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteContextImpl.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteContextImpl.java
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteContextImpl.java
index e5e4726..b8dc11f 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteContextImpl.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteContextImpl.java
@@ -28,7 +28,7 @@ import org.apache.knox.gateway.util.urltemplate.Params;
 import org.apache.knox.gateway.util.urltemplate.Resolver;
 import org.apache.knox.gateway.util.urltemplate.Template;
 
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -98,8 +98,7 @@ public class UrlRewriteContextImpl implements UrlRewriteContext {
   }
 
   private class ContextParameters implements Params {
-
-    Map<String,List<String>> map = new HashMap<>();
+    Map<String,List<String>> map = new LinkedHashMap<>();
 
     @Override
     public Set<String> getNames() {

http://git-wip-us.apache.org/repos/asf/knox/blob/4d08dcac/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java
b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java
index 511398c..c318854 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java
@@ -22,7 +22,7 @@ import java.net.URLDecoder;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
@@ -31,7 +31,7 @@ public class HttpUtils {
 
   public static Map<String, List<String>> splitQuery(String queryString)
       throws UnsupportedEncodingException {
-    final Map<String, List<String>> queryPairs = new HashMap<>();
+    final Map<String, List<String>> queryPairs = new LinkedHashMap<>();
     if (queryString == null || queryString.trim().isEmpty()) {
       return queryPairs;
     }
@@ -44,13 +44,13 @@ public class HttpUtils {
       }
       final String value = idx > 0 && pair.length() > idx + 1
           ? URLDecoder.decode(pair.substring(idx + 1), StandardCharsets.UTF_8.name()) : "";
-      queryPairs.get(key).add(value);
-    }
+        queryPairs.get(key).add(value);
+      }
     return queryPairs;
   }
 
   public static Map<String,String[]> parseQueryString( String queryString ) {
-    Map<String,String[]> map = new HashMap<>();
+    Map<String,String[]> map = new LinkedHashMap<>();
     if( queryString != null && !queryString.isEmpty() ) {
       StringTokenizer parser = new StringTokenizer( queryString, "&?;=", true );
       String name = null;
@@ -95,7 +95,7 @@ public class HttpUtils {
     return map;
   }
 
-  private static String urlDecodeUtf8( String s ) {
+  private static String urlDecodeUtf8(String s ) {
     if( s != null ) {
       try {
         s = URLDecoder.decode( s, StandardCharsets.UTF_8.name() );
@@ -118,5 +118,4 @@ public class HttpUtils {
     }
     map.put( name, values );
   }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/4d08dcac/gateway-util-common/src/test/java/org/apache/knox/gateway/util/HttpUtilsTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/test/java/org/apache/knox/gateway/util/HttpUtilsTest.java
b/gateway-util-common/src/test/java/org/apache/knox/gateway/util/HttpUtilsTest.java
index d805853..ad09ffa 100644
--- a/gateway-util-common/src/test/java/org/apache/knox/gateway/util/HttpUtilsTest.java
+++ b/gateway-util-common/src/test/java/org/apache/knox/gateway/util/HttpUtilsTest.java
@@ -19,6 +19,8 @@ package org.apache.knox.gateway.util;
 
 import org.junit.Test;
 
+import java.util.Arrays;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 
@@ -27,10 +29,8 @@ import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
 
 public class HttpUtilsTest {
-
   @Test
   public void testParseQueryString_BugKnox599() throws Exception {
-
     Map<String,List<String>> map;
 
     map = HttpUtils.splitQuery( null );
@@ -52,6 +52,7 @@ public class HttpUtilsTest {
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 2 ) );
     assertThat( map.containsKey( "test-name-one" ), is( true ) );
+    assertThat( map.keySet(), is(new LinkedHashSet<>(Arrays.asList("test-name-one",
"test-name-two"))));
     assertThat( map.get( "test-name-one" ).size(), is( 1 ) );
     assertThat( map.get( "test-name-one" ).get(0), is( "test-value-one" ) );
     assertThat( map.containsKey( "test-name-two" ), is( true ) );
@@ -170,6 +171,7 @@ public class HttpUtilsTest {
     map = HttpUtils.splitQuery( "&=" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 2 ) );
+    assertThat( map.keySet(), is(new LinkedHashSet<>(Arrays.asList("", "="))));
     assertThat( map.containsKey( "" ), is( true ) );
     assertThat( map.get( "" ).size(), is( 1 ) );
     assertThat( map.get( "" ).get(0), is( "" ) );
@@ -209,5 +211,4 @@ public class HttpUtilsTest {
     assertThat( map.get( "qry" ).size(), is( 1 ) );
     assertThat( map.get( "qry" ).get(0), is( "Hadoop:service=NameNode,name=NameNodeInfo"
) );
   }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/4d08dcac/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java
b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java
index d239b0a..32a79a7 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java
@@ -24,7 +24,7 @@ import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -51,7 +51,7 @@ public class Expander {
     if( params == null ) {
       params = EMPTY_PARAMS;
     }
-    Set<String> names = new HashSet<>( params.getNames() );
+    Set<String> names = new LinkedHashSet<>( params.getNames() );
     expandScheme( template, names, params, evaluator, builder );
     expandAuthority( template, names, params, evaluator, builder );
     expandPath( template, names, params, evaluator, builder );

http://git-wip-us.apache.org/repos/asf/knox/blob/4d08dcac/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Matcher.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Matcher.java
b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Matcher.java
index 5bd2e91..3b0af81 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Matcher.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Matcher.java
@@ -18,7 +18,6 @@
 package org.apache.knox.gateway.util.urltemplate;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
@@ -372,7 +371,7 @@ public class Matcher<V> {
 
   private class MatchParams implements Params {
 
-    private Map<String,List<String>> map = new HashMap<>();
+    private Map<String,List<String>> map = new LinkedHashMap<>();
 
     @Override
     public Set<String> getNames() {

http://git-wip-us.apache.org/repos/asf/knox/blob/4d08dcac/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/MockParams.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/MockParams.java
b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/MockParams.java
index dbc06ee..2685d32 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/MockParams.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/MockParams.java
@@ -18,14 +18,14 @@
 package org.apache.knox.gateway.util.urltemplate;
 
 import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 public class MockParams implements Params {
 
-  private Map<String,List<String>> map = new HashMap<>();
+  private Map<String,List<String>> map = new LinkedHashMap<>();
 
   @Override
   public Set<String> getNames() {

http://git-wip-us.apache.org/repos/asf/knox/blob/4d08dcac/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/ExpanderTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/ExpanderTest.java
b/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/ExpanderTest.java
index 59527da..4c27b4b 100644
--- a/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/ExpanderTest.java
+++ b/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/ExpanderTest.java
@@ -370,7 +370,7 @@ public class ExpanderTest {
     params.addValue( "name", "value" );
     params.addValue( "flag", "" );
     expanded = Expander.expand( template, params, null );
-    assertThat( expanded.toString(), equalTo( "http://hortonworks.com:8888/top/mid/bot/file?flag=&name=value"
) ) ;
+    assertThat( expanded.toString(), equalTo( "http://hortonworks.com:8888/top/mid/bot/file?name=value&flag="
) ) ;
 
     text = "{scheme}://{host}:{port}/{path=**}?{**}";
     template = Parser.parseTemplate( text );
@@ -385,7 +385,7 @@ public class ExpanderTest {
     params.addValue( "name", "value" );
     params.addValue( "flag", null );
     expanded = Expander.expand( template, params, null );
-    assertThat( expanded.toString(), equalTo( "http://hortonworks.com:8888/top/mid/bot/file?flag&name=value"
) ) ;
+    assertThat( expanded.toString(), equalTo( "http://hortonworks.com:8888/top/mid/bot/file?name=value&flag"
) ) ;
 
     text = "{scheme}://{host}:{port}/{path=**}?{name=*}&{**}";
     template = Parser.parseTemplate( text );

http://git-wip-us.apache.org/repos/asf/knox/blob/4d08dcac/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/RewriterTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/RewriterTest.java
b/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/RewriterTest.java
index 15db534..9ac2140 100644
--- a/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/RewriterTest.java
+++ b/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/RewriterTest.java
@@ -250,7 +250,7 @@ public class RewriterTest {
     assertThat( actualOutput, equalTo( expectOutput ) );
 
     actualInput = new URI( "/webhdfs/data/v1/test?user.name=hdfs&op=CREATE&overwrite=false&host=vm.home&port=50075"
);
-    expectOutput = new URI( "http://vm.home:50075/webhdfs/v1/test?op=CREATE&user.name=hdfs&overwrite=false"
);
+    expectOutput = new URI( "http://vm.home:50075/webhdfs/v1/test?user.name=hdfs&op=CREATE&overwrite=false"
);
     sourcePattern = Parser.parseTemplate( "/webhdfs/data/v1/{path=**}?{host}&{port}&{**}"
);
     targetPattern = Parser.parseTemplate( "http://{host}:{port}/webhdfs/v1/{path=**}?{**}"
);
     actualOutput = Rewriter.rewrite( actualInput, sourcePattern, targetPattern, new TestResolver(
config, request ), null );


Mime
View raw message