hc-commits mailing list archives

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

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

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFakeNTLM.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java?rev=1500276&r1=1500275&r2=1500276&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
Sat Jul  6 14:12:55 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(final String value) {
+        if (value == null) {
+            return null;
+        }
         final int index = value.indexOf(".");
         if (index != -1)
             return value.substring(0, index);
@@ -917,6 +921,9 @@ final class NTLMEngineImpl implements NT
          *            the bytes to add.
          */
         protected void addBytes(final byte[] bytes) {
+            if (bytes == null) {
+                return;
+            }
             for (final byte b : bytes) {
                 messageContents[currentOutputPosition] = b;
                 currentOutputPosition++;
@@ -971,8 +978,9 @@ final class NTLMEngineImpl implements NT
                 // Use only the base domain name!
                 final 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);
             }
@@ -1219,10 +1227,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);
             }
         }
@@ -1233,8 +1243,8 @@ final class NTLMEngineImpl implements NT
             final int ntRespLen = ntResp.length;
             final int lmRespLen = lmResp.length;
 
-            final int domainLen = domainBytes.length;
-            final int hostLen = hostBytes.length;
+            final int domainLen = domainBytes != null ? domainBytes.length : 0;
+            final int hostLen = hostBytes != null ? hostBytes.length: 0;
             final int userLen = userBytes.length;
             final int sessionKeyLen;
             if (sessionKey != null)

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFakeNTLM.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFakeNTLM.java?rev=1500276&r1=1500275&r2=1500276&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFakeNTLM.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFakeNTLM.java
Sat Jul  6 14:12:55 2013
@@ -82,7 +82,7 @@ public class TestClientAuthenticationFak
 
         final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
         credsProvider.setCredentials(AuthScope.ANY,
-                new NTCredentials("test", "test", "", ""));
+                new NTCredentials("test", "test", null, null));
 
         this.httpclient = HttpClients.custom()
                 .setDefaultCredentialsProvider(credsProvider)
@@ -127,7 +127,7 @@ public class TestClientAuthenticationFak
 
         final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
         credsProvider.setCredentials(AuthScope.ANY,
-                new NTCredentials("test", "test", "", ""));
+                new NTCredentials("test", "test", null, null));
 
         this.httpclient = HttpClients.custom()
                 .setDefaultCredentialsProvider(credsProvider)



Mime
View raw message