提交 2cca3b07 编写于 作者: W weijun

6586707: NTLM authentication with proxy fails

Reviewed-by: chegar
上级 6fa6bcf1
/* /*
* Copyright 1995-2009 Sun Microsystems, Inc. All Rights Reserved. * Copyright 1995-2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1258,6 +1258,11 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -1258,6 +1258,11 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
doingNTLMp2ndStage = false; doingNTLMp2ndStage = false;
continue; continue;
} }
} else {
inNegotiateProxy = false;
doingNTLMp2ndStage = false;
if (!isUserProxyAuth)
requests.remove("Proxy-Authorization");
} }
// cache proxy authentication info // cache proxy authentication info
...@@ -1303,7 +1308,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -1303,7 +1308,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
serverAuthentication.getAuthScheme() != NTLM) { serverAuthentication.getAuthScheme() != NTLM) {
if (serverAuthentication.isAuthorizationStale (raw)) { if (serverAuthentication.isAuthorizationStale (raw)) {
/* we can retry with the current credentials */ /* we can retry with the current credentials */
disconnectInternal(); disconnectWeb();
redirects++; redirects++;
requests.set(serverAuthentication.getHeaderName(), requests.set(serverAuthentication.getHeaderName(),
serverAuthentication.getHeaderValue(url, method)); serverAuthentication.getHeaderValue(url, method));
...@@ -1318,7 +1323,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -1318,7 +1323,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
currentServerCredentials = serverAuthentication; currentServerCredentials = serverAuthentication;
if (serverAuthentication != null) { if (serverAuthentication != null) {
disconnectInternal(); disconnectWeb();
redirects++; // don't let things loop ad nauseum redirects++; // don't let things loop ad nauseum
setCookieHeader(); setCookieHeader();
continue; continue;
...@@ -1327,7 +1332,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -1327,7 +1332,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
reset (); reset ();
/* header not used for ntlm */ /* header not used for ntlm */
if (!serverAuthentication.setHeaders(this, null, raw)) { if (!serverAuthentication.setHeaders(this, null, raw)) {
disconnectInternal(); disconnectWeb();
throw new IOException ("Authentication failure"); throw new IOException ("Authentication failure");
} }
doingNTLM2ndStage = false; doingNTLM2ndStage = false;
...@@ -2319,6 +2324,22 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -2319,6 +2324,22 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
connected = false; connected = false;
} }
/**
* Disconnect from the web server at the first 401 error. Do not
* disconnect when using a proxy, a good proxy should have already
* closed the connection to the web server.
*/
private void disconnectWeb() throws IOException {
if (usingProxy()) {
responseCode = -1;
// clean up, particularly, skip the content part
// of a 401 error response
reset();
} else {
disconnectInternal();
}
}
/** /**
* Disconnect from the server (for internal use) * Disconnect from the server (for internal use)
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册