hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1500274 - in /httpcomponents/httpclient/branches/4.2.x/httpclient/src: main/java/org/apache/http/impl/auth/NTLMEngineImpl.java test/java/org/apache/http/impl/client/TestClientAuthenticationFakeNTLM.java
Date Sat, 06 Jul 2013 14:12:17 GMT
Author: olegk
Date: Sat Jul  6 14:12:16 2013
New Revision: 1500274

URL: http://svn.apache.org/r1500274
Log:
HTTPCLIENT-1381: tolerate null NT domain and host

Modified:
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthenticationFakeNTLM.java

Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java?rev=1500274&r1=1500273&r2=1500274&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
(original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
Sat Jul  6 14:12:16 2013
@@ -26,6 +26,7 @@
 
 package org.apache.http.impl.auth;
 
+import java.io.UnsupportedEncodingException;
 import java.security.Key;
 import java.security.MessageDigest;
 import java.util.Arrays;
@@ -183,6 +184,9 @@ final class NTLMEngineImpl implements NT
 
     /** Strip dot suffix from a name */
     private static String stripDotSuffix(String value) {
+        if (value == null) {
+            return null;
+        }
         int index = value.indexOf(".");
         if (index != -1)
             return value.substring(0, index);
@@ -938,6 +942,9 @@ final class NTLMEngineImpl implements NT
          *            the bytes to add.
          */
         protected void addBytes(byte[] bytes) {
+            if (bytes == null) {
+                return;
+            }
             for (byte b : bytes) {
                 messageContents[currentOutputPosition] = b;
                 currentOutputPosition++;
@@ -994,8 +1001,9 @@ final class NTLMEngineImpl implements NT
                 // Use only the base domain name!
                 String unqualifiedDomain = convertDomain(domain);
 
-                hostBytes = unqualifiedHost.getBytes("ASCII");
-                domainBytes = unqualifiedDomain.toUpperCase(Locale.US).getBytes("ASCII");
+                hostBytes = unqualifiedHost != null? unqualifiedHost.getBytes("ASCII") :
null;
+                domainBytes = unqualifiedDomain != null ? unqualifiedDomain
+                        .toUpperCase(Locale.US).getBytes("ASCII") : null;
             } catch (java.io.UnsupportedEncodingException e) {
                 throw new NTLMEngineException("Unicode unsupported: " + e.getMessage(), e);
             }
@@ -1242,10 +1250,12 @@ final class NTLMEngineImpl implements NT
             }
 
             try {
-                domainBytes = unqualifiedDomain.toUpperCase(Locale.US).getBytes("UnicodeLittleUnmarked");
-                hostBytes = unqualifiedHost.getBytes("UnicodeLittleUnmarked");
+                hostBytes = unqualifiedHost != null ? unqualifiedHost
+                        .getBytes("UnicodeLittleUnmarked") : null;
+                domainBytes = unqualifiedDomain != null ? unqualifiedDomain
+                        .toUpperCase(Locale.US).getBytes("UnicodeLittleUnmarked") : null;
                 userBytes = user.getBytes("UnicodeLittleUnmarked");
-            } catch (java.io.UnsupportedEncodingException e) {
+            } catch (UnsupportedEncodingException e) {
                 throw new NTLMEngineException("Unicode not supported: " + e.getMessage(),
e);
             }
         }
@@ -1256,8 +1266,8 @@ final class NTLMEngineImpl implements NT
             int ntRespLen = ntResp.length;
             int lmRespLen = lmResp.length;
 
-            int domainLen = domainBytes.length;
-            int hostLen = hostBytes.length;
+            int domainLen = domainBytes != null ? domainBytes.length : 0;
+            int hostLen = hostBytes != null ? hostBytes.length: 0;
             int userLen = userBytes.length;
             int sessionKeyLen;
             if (sessionKey != null)

Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthenticationFakeNTLM.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthenticationFakeNTLM.java?rev=1500274&r1=1500273&r2=1500274&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthenticationFakeNTLM.java
(original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthenticationFakeNTLM.java
Sat Jul  6 14:12:16 2013
@@ -81,7 +81,7 @@ public class TestClientAuthenticationFak
 
         BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
         credsProvider.setCredentials(AuthScope.ANY,
-                new NTCredentials("test", "test", "", ""));
+                new NTCredentials("test", "test", null, null));
 
         this.httpclient.setCredentialsProvider(credsProvider);
 
@@ -124,7 +124,7 @@ public class TestClientAuthenticationFak
 
         BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
         credsProvider.setCredentials(AuthScope.ANY,
-                new NTCredentials("test", "test", "", ""));
+                new NTCredentials("test", "test", null, null));
 
         this.httpclient.setCredentialsProvider(credsProvider);
 



Mime
View raw message