From cb5b4ae2bbb04d49f763e8348c89e16345046179 Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Mon, 11 Nov 2002 07:21:19 +0000 Subject: [PATCH] added user/password support in the proxy, though I cant test it myself. Also added removal of http host in cleanup routine. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273530 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/taskdefs/optional/net/SetProxy.java | 75 +++++++++++++++---- 1 file changed, 60 insertions(+), 15 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/SetProxy.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/SetProxy.java index 4c53e4eeb..2236645c2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/net/SetProxy.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/SetProxy.java @@ -66,9 +66,9 @@ import org.apache.tools.ant.util.JavaEnvUtils; * Sets Java's web proxy properties, so that tasks and code run in * the same JVM can have through-the-firewall access to remote web sites, * and remote ftp sites. - * You can nominate an http and ftp proxy, or a socks server, reset the server + * You can nominate an http and ftp proxy, or a socks server, reset the server * settings, or do nothing at all. - *

+ *

* Examples *

<setproxy/>
* do nothing @@ -82,14 +82,16 @@ import org.apache.tools.ant.util.JavaEnvUtils; * use socks via socksy:1080 *
<setproxy socksproxyhost=""/>
* stop using the socks server - - - + * You can set a username and password for http with the proxyHost + * and proxyPassword attributes. On Java1.4 and above these can also be + * used against SOCKS5 servers. + + * @see * java 1.4 network property list * @author Steve Loughran *@since Ant 1.5 - * @ant.task + * @ant.task category="network" */ public class SetProxy extends Task { @@ -107,7 +109,7 @@ public class SetProxy extends Task { * socks host. */ private String socksProxyHost = null; - + /** * Socks proxy port. Default is 1080. */ @@ -116,9 +118,19 @@ public class SetProxy extends Task { /** * list of non proxy hosts - */ + */ private String nonProxyHosts = null; + /** + * user for http only + */ + private String proxyUser=null; + + /** + * password for http only + */ + private String proxyPassword=null; + /** * the HTTP/ftp proxy host. Set this to "" for the http proxy * option to be disabled @@ -159,23 +171,40 @@ public class SetProxy extends Task { this.socksProxyPort = port; } + /** * A list of hosts to bypass the proxy on. These should be separated * with the vertical bar character '|'. Only in Java 1.4 does ftp use * this list. * e.g. fozbot.corp.sun.com|*.eng.sun.com * @param nonProxyHosts lists of hosts to talk direct to - */ + */ public void setNonProxyHosts(String nonProxyHosts) { this.nonProxyHosts = nonProxyHosts; } + /** + * set the proxy user. Probably requires a password to accompany this + * setting. Default="" + * @param proxyUser + */ + public void setProxyUser(String proxyUser) { + this.proxyUser = proxyUser; + } + + /** + * set the password for the proxy. used only if the proxyUser is set + * @param proxyPassword + */ + public void setProxyPassword(String proxyPassword) { + this.proxyPassword = proxyPassword; + } + /** * if the proxy port and host settings are not null, then the settings * get applied these settings last beyond the life of the object and * apply to all network connections * Relevant docs: buglist #4183340 - * @return true if the settings were applied */ public void applyWebProxySettings() { @@ -196,11 +225,19 @@ public class SetProxy extends Task { sysprops.put("ftp.proxyPort", portString); if (nonProxyHosts != null) { sysprops.put("http.nonProxyHosts", nonProxyHosts); + sysprops.put("https.nonProxyHosts", nonProxyHosts); sysprops.put("ftp.nonProxyHosts", nonProxyHosts); - } + } + if(proxyUser!=null) { + sysprops.put("http.proxyUser", proxyUser); + sysprops.put("http.proxyPassword", proxyPassword); + } } else { log("resetting http proxy", Project.MSG_VERBOSE); + sysprops.remove("http.proxyHost"); sysprops.remove("http.proxyPort"); + sysprops.remove("http.proxyUser"); + sysprops.remove("http.proxyPassword"); sysprops.remove("https.proxyHost"); sysprops.remove("https.proxyPort"); sysprops.remove("ftp.proxyHost"); @@ -215,13 +252,21 @@ public class SetProxy extends Task { enablingProxy = true; sysprops.put("socksProxyHost", socksProxyHost); sysprops.put("socksProxyPort", Integer.toString(socksProxyPort)); + if (proxyUser != null) { + //this may be a java1.4 thingy only + sysprops.put("java.net.socks.username", proxyUser); + sysprops.put("java.net.socks.password", proxyPassword); + } + } else { log("resetting socks proxy", Project.MSG_VERBOSE); sysprops.remove("socksProxyHost"); sysprops.remove("socksProxyPort"); + sysprops.remove("java.net.socks.username"); + sysprops.remove("java.net.socks.password"); } } - + //for Java1.1 we need to tell the system that the settings are new if (settingsChanged && @@ -232,10 +277,10 @@ public class SetProxy extends Task { /** * list out what is going on - */ + */ private void traceSettingInfo() { - log("Setting proxy to " - + (proxyHost != null ? proxyHost : "''") + log("Setting proxy to " + + (proxyHost != null ? proxyHost : "''") + ":" + proxyPort, Project.MSG_VERBOSE); }