cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [2/2] cxf git commit: [CXF-6962] Optional use of ISO-8859-1 when processing BasicAuth
Date Fri, 27 Jan 2017 14:08:19 GMT
[CXF-6962] Optional use of ISO-8859-1 when processing BasicAuth


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

Branch: refs/heads/3.0.x-fixes
Commit: cb6447bffd517aeb3ea01de6b5484542ad5adb71
Parents: 206a1ed
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Jan 27 14:08:00 2017 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Jan 27 14:08:00 2017 +0000

----------------------------------------------------------------------
 .../cxf/transport/http/AbstractHTTPDestination.java  | 14 +++++++++++---
 .../http/auth/DefaultBasicAuthSupplier.java          | 15 ++++++++++++---
 2 files changed, 23 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/cb6447bf/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 bb63bd5..19c4374 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
@@ -22,10 +22,10 @@ package org.apache.cxf.transport.http;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
 import java.net.HttpURLConnection;
 import java.net.ServerSocket;
 import java.net.URL;
-import java.nio.charset.StandardCharsets;
 import java.security.Principal;
 import java.util.Arrays;
 import java.util.Collection;
@@ -173,8 +173,16 @@ public abstract class AbstractHTTPDestination
             try {
                 byte[] authBytes = Base64Utility.decode(authEncoded);
                 
-                String authDecoded = decodeBasicAuthWithIso8859 
-                    ? new String(authBytes, StandardCharsets.ISO_8859_1) : new String(authBytes);
+                String authDecoded = null;
+                if (decodeBasicAuthWithIso8859) {
+                    try {
+                        authDecoded = new String(authBytes, "ISO-8859-1");
+                    } catch (UnsupportedEncodingException ex) {
+                        authDecoded = new String(authBytes);
+                    }  
+                } else {
+                    authDecoded = new String(authBytes);
+                } 
                 
                 int idx = authDecoded.indexOf(':');
                 String username = null;

http://git-wip-us.apache.org/repos/asf/cxf/blob/cb6447bf/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/DefaultBasicAuthSupplier.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/DefaultBasicAuthSupplier.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/DefaultBasicAuthSupplier.java
index 8a9856f..26ad1d2 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/DefaultBasicAuthSupplier.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/DefaultBasicAuthSupplier.java
@@ -18,8 +18,8 @@
  */
 package org.apache.cxf.transport.http.auth;
 
+import java.io.UnsupportedEncodingException;
 import java.net.URI;
-import java.nio.charset.StandardCharsets;
 
 import org.apache.cxf.common.util.Base64Utility;
 import org.apache.cxf.common.util.PropertyUtils;
@@ -42,7 +42,16 @@ public final class DefaultBasicAuthSupplier implements HttpAuthSupplier
{
     
     public static String getBasicAuthHeader(String userName, String passwd, boolean useIso8859)
{
         String userAndPass = userName + ":" + passwd;
-        byte[] authBytes = useIso8859 ? userAndPass.getBytes(StandardCharsets.ISO_8859_1)
: userAndPass.getBytes();
+        byte[] authBytes = null;
+        if (useIso8859) {
+            try {
+                authBytes = userAndPass.getBytes("ISO-8859-1");
+            } catch (UnsupportedEncodingException ex) {
+                authBytes = userAndPass.getBytes();
+            }
+        } else {
+            authBytes = userAndPass.getBytes();
+        }
         return "Basic " + Base64Utility.encode(authBytes);
     }
 
@@ -61,4 +70,4 @@ public final class DefaultBasicAuthSupplier implements HttpAuthSupplier
{
         }
     }
 
-}
\ No newline at end of file
+}


Mime
View raw message