Browse Source

<setproxy> fails to provide password authentication on some JDKs.

The patch provided in the bug report looked very similar to something
I once had to do in production code, when Ant's original code wasn't
enough.  I forgot about it when we switched to commons-httpclient
shortly thereafter.

PR: 32667


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277255 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 20 years ago
parent
commit
813c7581a8
2 changed files with 28 additions and 0 deletions
  1. +3
    -0
      WHATSNEW
  2. +25
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/net/SetProxy.java

+ 3
- 0
WHATSNEW View File

@@ -218,6 +218,9 @@ Fixed bugs:
* <scp> using <fileset> didn't work with OpenSSH 3.9 and later.
Bugzilla report 31939

* <setproxy> failed to set user/password on some JDKs.
Bugzilla report 32667

Changes from Ant 1.6.1 to Ant 1.6.2
===================================



+ 25
- 0
src/main/org/apache/tools/ant/taskdefs/optional/net/SetProxy.java View File

@@ -18,6 +18,8 @@ package org.apache.tools.ant.taskdefs.optional.net;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.Properties;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
@@ -229,6 +231,15 @@ public class SetProxy extends Task {
sysprops.remove("java.net.socks.password");
}
}

if (proxyUser != null) {
if (enablingProxy) {
Authenticator.setDefault(new ProxyAuth(proxyUser,
proxyPassword));
} else if (settingsChanged) {
Authenticator.setDefault(new ProxyAuth("", ""));
}
}
}

/**
@@ -250,5 +261,19 @@ public class SetProxy extends Task {
applyWebProxySettings();
}

/**
* @since 1.6.3
*/
private static final class ProxyAuth extends Authenticator {
private PasswordAuthentication auth;

private ProxyAuth(String user, String pass) {
auth = new PasswordAuthentication(user, pass.toCharArray());
}

protected PasswordAuthentication getPasswordAuthentication() {
return auth;
}
}
}


Loading…
Cancel
Save