diff --git a/core/src/main/java/hudson/PluginManager.java b/core/src/main/java/hudson/PluginManager.java index f3892c6b71b48116b24720cd35192af228b9fbeb..8cedec604123bba043caf94eaf9acbc28e14e2f4 100644 --- a/core/src/main/java/hudson/PluginManager.java +++ b/core/src/main/java/hudson/PluginManager.java @@ -218,7 +218,12 @@ public final class PluginManager extends AbstractModelObject { rsp.sendRedirect("../updateCenter/"); } - public void doProxyConfigure(@QueryParameter("proxy.server") String server, @QueryParameter("proxy.port") String port, StaplerResponse rsp) throws IOException { + public void doProxyConfigure( + @QueryParameter("proxy.server") String server, + @QueryParameter("proxy.port") String port, + @QueryParameter("proxy.userName") String userName, + @QueryParameter("proxy.password") String password, + StaplerResponse rsp) throws IOException { Hudson.getInstance().checkPermission(Hudson.ADMINISTER); Hudson hudson = Hudson.getInstance(); @@ -227,7 +232,8 @@ public final class PluginManager extends AbstractModelObject { hudson.proxy = null; ProxyConfiguration.getXmlFile().delete(); } else { - hudson.proxy = new ProxyConfiguration(server,Integer.parseInt(Util.fixEmptyAndTrim(port))); + hudson.proxy = new ProxyConfiguration(server,Integer.parseInt(Util.fixEmptyAndTrim(port)), + Util.fixEmptyAndTrim(userName),Util.fixEmptyAndTrim(password)); hudson.proxy.save(); } rsp.sendRedirect("./advanced"); diff --git a/core/src/main/java/hudson/ProxyConfiguration.java b/core/src/main/java/hudson/ProxyConfiguration.java index 2c575819413d72af0b1ef99bbcc53dcc35b4073e..ed9f4d03c569904b786459a8ccf552c557f10785 100644 --- a/core/src/main/java/hudson/ProxyConfiguration.java +++ b/core/src/main/java/hudson/ProxyConfiguration.java @@ -3,24 +3,50 @@ package hudson; import com.thoughtworks.xstream.XStream; import hudson.model.Hudson; import hudson.util.XStream2; +import hudson.util.Scrambler; import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Proxy; +import java.net.URLConnection; +import java.net.URL; /** * HTTP proxy configuration. * + *
+ * Use {@link #open(URL)} to open a connection with the proxy setting.
+ *
* @see Hudson#proxy
*/
public final class ProxyConfiguration {
public final String name;
public final int port;
+ /**
+ * Possibly null proxy user name and password.
+ * Password is base64 scrambled since this is persisted to disk.
+ */
+ private final String userName,password;
+
public ProxyConfiguration(String name, int port) {
+ this(name,port,null,null);
+ }
+
+ public ProxyConfiguration(String name, int port, String userName, String password) {
this.name = name;
this.port = port;
+ this.userName = userName;
+ this.password = Scrambler.scramble(password);
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public String getPassword() {
+ return Scrambler.descramble(password);
}
public Proxy createProxy() {
@@ -43,6 +69,19 @@ public final class ProxyConfiguration {
return null;
}
+ public static URLConnection open(URL url) throws IOException {
+ ProxyConfiguration p = Hudson.getInstance().proxy;
+ if(p==null)
+ return url.openConnection();
+
+ URLConnection con = url.openConnection(p.createProxy());
+ if(p.getUserName()!=null) {
+ con.setRequestProperty("Proxy-Authorization","Basic "+
+ Scrambler.scramble(p.getUserName()+':'+p.getPassword()));
+ }
+ return con;
+ }
+
private static final XStream XSTREAM = new XStream2();
static {
diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java
index 40216a5c93e2028f187c58b5b7f3f879cb768858..fc21ee03dbc8ccfcff15762d5ffa0afa44b56d1b 100644
--- a/core/src/main/java/hudson/model/Hudson.java
+++ b/core/src/main/java/hudson/model/Hudson.java
@@ -383,16 +383,6 @@ public final class Hudson extends View implements ItemGroup${%HTTP Proxy Configuration}