cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6492] Support for Basic scheme with more than a single space between it and the encoded user/password
Date Wed, 24 Feb 2016 13:01:23 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 3e5241a77 -> a3936f026


[CXF-6492] Support for Basic scheme with more than a single space between it and the encoded
user/password


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

Branch: refs/heads/master
Commit: a3936f02652fbb4c64fce2d5e5b3b4c4de42c3c4
Parents: 3e5241a
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Feb 24 13:01:08 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Wed Feb 24 13:01:08 2016 +0000

----------------------------------------------------------------------
 .../org/apache/cxf/common/util/StringUtils.java   |  4 ++--
 .../apache/cxf/common/util/StringUtilsTest.java   | 18 ++++++++++++++++++
 .../transport/http/AbstractHTTPDestination.java   |  9 +++++----
 3 files changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a3936f02/core/src/main/java/org/apache/cxf/common/util/StringUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/common/util/StringUtils.java b/core/src/main/java/org/apache/cxf/common/util/StringUtils.java
index b90c078..aa0edba 100644
--- a/core/src/main/java/org/apache/cxf/common/util/StringUtils.java
+++ b/core/src/main/java/org/apache/cxf/common/util/StringUtils.java
@@ -91,8 +91,8 @@ public final class StringUtils {
     }
     
     public static List<String> getParts(String str, String separator) {
-        List<String> ret = new ArrayList<String>();
-        List<String> parts = Arrays.asList(split(str, separator));
+        String[] parts = split(str, separator);
+        List<String> ret = new ArrayList<String>(parts.length);
         for (String part : parts) {
             if (!isEmpty(part)) {
                 ret.add(part);

http://git-wip-us.apache.org/repos/asf/cxf/blob/a3936f02/core/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java b/core/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
index 1e38c3a..7480135 100644
--- a/core/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
+++ b/core/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
@@ -53,6 +53,24 @@ public class StringUtilsTest extends Assert {
     }
     
     @Test
+    public void testGetPartsWithSingleSpace() throws Exception {
+        String str = "a b";
+        List<String> parts = StringUtils.getParts(str, " ");
+        assertEquals(2, parts.size());
+        assertEquals("a", parts.get(0));
+        assertEquals("b", parts.get(1));
+    }
+    
+    @Test
+    public void testGetPartsWithManySpaces() throws Exception {
+        String str = "a  b";
+        List<String> parts = StringUtils.getParts(str, " ");
+        assertEquals(2, parts.size());
+        assertEquals("a", parts.get(0));
+        assertEquals("b", parts.get(1));
+    }
+    
+    @Test
     public void testSplitWithDot() throws Exception {
         String str = "a.b.c";
         String[] parts = StringUtils.split(str, "\\.", -1);

http://git-wip-us.apache.org/repos/asf/cxf/blob/a3936f02/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
index 882cb63..722356c 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
@@ -28,6 +28,7 @@ import java.net.URL;
 import java.security.Principal;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -161,10 +162,10 @@ public abstract class AbstractHTTPDestination
         if (credentials == null || StringUtils.isEmpty(credentials.trim())) {
             return null;
         }
-        String creds[] = StringUtils.split(credentials, " ");
-        String authType = creds[0];
-        if ("Basic".equals(authType)) {
-            String authEncoded = creds[1];
+        List<String> creds = StringUtils.getParts(credentials, " ");
+        String authType = creds.get(0);
+        if ("Basic".equals(authType) && creds.size() == 2) {
+            String authEncoded = creds.get(1);
             try {
                 String authDecoded = new String(Base64Utility.decode(authEncoded));
                 int idx = authDecoded.indexOf(':');


Mime
View raw message