--- a/src/share/classes/sun/net/www/MessageHeader.java Wed Nov 21 21:10:25 2012 -0800
+++ b/src/share/classes/sun/net/www/MessageHeader.java Tue Nov 27 16:30:23 2012 -0800
@@ -136,6 +136,43 @@ class MessageHeader {
else if (values[i] == v)
foundV = true;
return null;
+ }
+
+ /**
+ * Removes bare Negotiate and Kerberos headers when an "NTLM ..."
+ * appears. All Performed on headers with key being k.
+ * @return true if there is a change
+ */
+ public boolean filterNTLMResponses(String k) {
+ boolean found = false;
+ for (int i=0; i<nkeys; i++) {
+ if (k.equalsIgnoreCase(keys[i])
+ && values[i] != null && values[i].length() > 5
+ && values[i].substring(0, 5).equalsIgnoreCase("NTLM ")) {
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ int j = 0;
+ for (int i=0; i<nkeys; i++) {
+ if (k.equalsIgnoreCase(keys[i]) && (
+ "Negotiate".equalsIgnoreCase(values[i]) ||
+ "Kerberos".equalsIgnoreCase(values[i]))) {
+ continue;
+ }
+ if (i != j) {
+ keys[j] = keys[i];
+ values[j] = values[i];
+ }
+ j++;
+ }
+ if (j != nkeys) {
+ nkeys = j;
+ return true;
+ }
+ }
+ return false;
}
class HeaderIterator implements Iterator<String> {
--- a/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java Wed Nov 21 21:10:25 2012 -0800
+++ b/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java Tue Nov 27 16:30:23 2012 -0800
@@ -1323,6 +1323,16 @@ public class HttpURLConnection extends j
if (logger.isLoggable(PlatformLogger.FINE)) {
logger.fine(responses.toString());
}
+
+ boolean b1 = responses.filterNTLMResponses("WWW-Authenticate");
+ boolean b2 = responses.filterNTLMResponses("Proxy-Authenticate");
+ if (b1 || b2) {
+ if (logger.isLoggable(PlatformLogger.FINE)) {
+ logger.fine(">>>> Headers are filtered");
+ logger.fine(responses.toString());
+ }
+ }
+
inputStream = http.getInputStream();
respCode = getResponseCode();
@@ -1782,6 +1792,13 @@ public class HttpURLConnection extends j
logger.fine(responses.toString());
}
+ if (responses.filterNTLMResponses("Proxy-Authenticate")) {
+ if (logger.isLoggable(PlatformLogger.FINE)) {
+ logger.fine(">>>> Headers are filtered");
+ logger.fine(responses.toString());
+ }
+ }
+
statusLine = responses.getValue(0);
StringTokenizer st = new StringTokenizer(statusLine);
st.nextToken();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/net/www/messageheader/0 Tue Nov 27 16:30:23 2012 -0800
@@ -0,0 +1,4 @@
+HTTP/1.1 200 Ok
+Foo: bar
+Bar: foo
+WWW-Authenticate: NTLM sdsds
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/net/www/messageheader/1 Tue Nov 27 16:30:23 2012 -0800
@@ -0,0 +1,4 @@
+HTTP/1.1 200 Ok
+Foo: bar
+Bar: foo
+WWW-Authenticate:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/net/www/messageheader/2 Tue Nov 27 16:30:23 2012 -0800
@@ -0,0 +1,5 @@
+HTTP/1.1 200 Ok
+Foo: bar
+Bar: foo
+WWW-Authenticate: NTLM sdsds
+WWW-Authenticate: Negotiate
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/net/www/messageheader/3 Tue Nov 27 16:30:23 2012 -0800
@@ -0,0 +1,6 @@
+HTTP/1.1 200 Ok
+Foo: bar
+Bar: foo
+WWW-Authenticate: NTLM sdsds
+WWW-Authenticate: Negotiate
+WWW-Authenticate: Kerberos
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/net/www/messageheader/4 Tue Nov 27 16:30:23 2012 -0800
@@ -0,0 +1,7 @@
+HTTP/1.1 200 Ok
+WWW-Authenticate: Negotiate
+Foo: bar
+Bar: foo
+WWW-Authenticate: NTLM sdsds
+Bar: foo
+WWW-Authenticate: Kerberos
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/net/www/messageheader/5 Tue Nov 27 16:30:23 2012 -0800
@@ -0,0 +1,7 @@
+HTTP/1.1 200 Ok
+WWW-Authenticate: Negotiate
+Foo: bar
+Bar: foo
+WWW-Authenticate: NTLM
+Bar: foo
+WWW-Authenticate: Kerberos
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/net/www/messageheader/6 Tue Nov 27 16:30:23 2012 -0800
@@ -0,0 +1,5 @@
+HTTP/1.1 200 Ok
+Foo: foo
+Bar:
+WWW-Authenticate: NTLM blob
+Bar: foo blob
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/net/www/messageheader/HTest.java Tue Nov 27 16:30:23 2012 -0800
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8003948
+ * @run main HTest
+ */
+import java.io.*;
+import sun.net.www.MessageHeader;
+
+public class HTest {
+ public static void main (String[] args) throws Exception {
+ String prefix = System.getProperty("test.src");
+ System.out.println ("TEST.SRC = " + prefix);
+ for (int i=0; i<7; i++) {
+ File f = new File(prefix, Integer.toString(i));
+ FileInputStream fis = new FileInputStream(f);
+ MessageHeader h = new MessageHeader(fis);
+ String before = h.toString();
+ before = before.substring(before.indexOf('{'));
+ System.out.println ("Before");
+ System.out.println (before);
+ boolean result = h.filterNTLMResponses("WWW-Authenticate");
+ String after = h.toString();
+ after = after.substring(after.indexOf('{'));
+ System.out.println ("After");
+ System.out.println (after);
+ System.out.println ("Expected");
+ System.out.println (expected[i]);
+ if (!expected[i].equals(after)) {
+ throw new RuntimeException(Integer.toString(i) + " expected != after");
+ }
+ if (result != expectedResult[i]) {
+ throw new RuntimeException(Integer.toString(i) + " result != expectedResult");
+ }
+ }
+ }
+
+ static String expected[] = {
+ "{null: HTTP/1.1 200 Ok}{Foo: bar}{Bar: foo}{WWW-Authenticate: NTLM sdsds}",
+ "{null: HTTP/1.1 200 Ok}{Foo: bar}{Bar: foo}{WWW-Authenticate: }",
+ "{null: HTTP/1.1 200 Ok}{Foo: bar}{Bar: foo}{WWW-Authenticate: NTLM sdsds}",
+ "{null: HTTP/1.1 200 Ok}{Foo: bar}{Bar: foo}{WWW-Authenticate: NTLM sdsds}",
+ "{null: HTTP/1.1 200 Ok}{Foo: bar}{Bar: foo}{WWW-Authenticate: NTLM sdsds}{Bar: foo}",
+ "{null: HTTP/1.1 200 Ok}{WWW-Authenticate: Negotiate}{Foo: bar}{Bar: foo}{WWW-Authenticate: NTLM}{Bar: foo}{WWW-Authenticate: Kerberos}",
+ "{null: HTTP/1.1 200 Ok}{Foo: foo}{Bar: }{WWW-Authenticate: NTLM blob}{Bar: foo blob}"
+ };
+
+ static boolean[] expectedResult = {
+ false, false, true, true, true, false, false
+ };
+}