Author: maartenc
Date: Tue Sep 28 22:01:22 2010
New Revision: 1002371
URL: http://svn.apache.org/viewvc?rev=1002371&view=rev
Log:
FIX: Couldn't authenticate against sites having the same address as the proxy
server (IVY-1234)
Modified:
ant/ivy/core/trunk/CHANGES.txt
ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/IvyAuthenticator.java
Modified: ant/ivy/core/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=1002371&r1=1002370&r2=1002371&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Tue Sep 28 22:01:22 2010
@@ -129,6 +129,7 @@ for detailed view of each issue, please
- IMPROVEMENT: ivy:makepom now accepts a list of configurations to include
(IVY-1005) (thanks to Jesper Pedersen)
- IMPROVEMENT: ivy:makepom can generate a <description> element in the pom
(IVY-1215) (thanks to Jesper Pedersen)
+- FIX: Couldn't authenticate against sites having the same address as the
proxy server (IVY-1234)
- FIX: ApacheURLLister doesn't handle some truncated linknames properly
(IVY-1232) (thanks to John Tinetti)
- FIX: Ivy cannot handle Maven pom with parents depending back on theirselfs
(IVY-1225)
- FIX: OutOfMemoryError when uploading large files using commons-httpclient
(IVY-1197) (thanks to Torkild U. Resheim)
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/IvyAuthenticator.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/IvyAuthenticator.java?rev=1002371&r1=1002370&r2=1002371&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/IvyAuthenticator.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/IvyAuthenticator.java
Tue Sep 28 22:01:22 2010
@@ -18,6 +18,7 @@
package org.apache.ivy.util.url;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
@@ -79,8 +80,7 @@ public final class IvyAuthenticator exte
protected PasswordAuthentication getPasswordAuthentication() {
PasswordAuthentication result = null;
- String proxyHost = System.getProperty("http.proxyHost");
- if (getRequestingHost().equals(proxyHost)) {
+ if (isProxyAuthentication()) {
String proxyUser = System.getProperty("http.proxyUser");
if ((proxyUser != null) && (proxyUser.trim().length() > 0)) {
String proxyPass = System.getProperty("http.proxyPassword",
"");
@@ -111,5 +111,46 @@ public final class IvyAuthenticator exte
return result;
}
+
+ /**
+ * Checks if the current authentication request is for the proxy server.
+ * This functionality is not availaible in JDK1.4, so we check this in a
+ * very dirty way which is probably not very portable, but will work for
+ * the SUN 1.4 JDKs.
+ *
+ * @return
+ */
+ private boolean isProxyAuthentication() {
+ try {
+ // we first try to invoke the getRequestorType() method which is a
JDK1.5+ method
+ Method m =
Authenticator.class.getDeclaredMethod("getRequestorType", null);
+ Object result = m.invoke(this, null);
+ return "PROXY".equals(String.valueOf(result));
+ } catch (NoSuchMethodException e) {
+ // do nothing, this is a JDK1.5+ method
+ } catch (Throwable t) {
+ Message.debug("Error occurred while checking if the authentication
request is for the proxy server: " + t.getMessage());
+ }
+
+ // now we will do something very dirty and analyse the stack trace to
see
+ // if this method is called from within the
'getHttpProxyAuthentication' method
+ // or the 'getServerAuthentication' method which are both part of the
+ // sun.net.www.protocol.http.HttpURLConnection class.
+ // This might not work on other 1.4 JVM's!
+ // This code should be removed when Ivy requires JDK1.5+
+ StackTraceElement[] stackTrace = (new Exception()).getStackTrace();
+ for (int i = 0; i < stackTrace.length; i++) {
+ if
("getHttpProxyAuthentication".equals(stackTrace[i].getMethodName())) {
+ return true;
+ }
+ if
("getServerAuthentication".equals(stackTrace[i].getMethodName())) {
+ return false;
+ }
+ }
+
+ // fallback to the Ivy 2.2.0 behavior
+ String proxyHost = System.getProperty("http.proxyHost");
+ return getRequestingHost().equals(proxyHost);
+ }
}