提交 22b729ff 编写于 作者: M mindless

Add authentication support in hudson.Main (if username/password are included in

HUDSON_HOME URL, then include Authorization header in Hudson http requests).

Also moved Functions.isUnitTest to Main.isUnitTest, to remove dependency on
winstone.jar for running hudson.Main (Main uses EnvVars which checks isUnitTest
flag.. in Functions which uses servlet classes).

Updated http://wiki.hudson-ci.org/display/HUDSON/Monitoring+external+jobs
with info about required jars and authentication.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@21479 71c3de6d-444a-0410-be80-ed276b4c234a
上级 5eaec18e
......@@ -203,7 +203,7 @@ public class EnvVars extends TreeMap<String,String> {
private static EnvVars initMaster() {
EnvVars vars = new EnvVars(System.getenv());
vars.platform = Platform.current();
if(Functions.isUnitTest)
if(Main.isUnitTest)
// if unit test is launched with maven debug switch,
// we need to prevent forked Maven processes from seeing it, or else
// they'll hang
......
......@@ -1161,7 +1161,9 @@ public class Functions {
private static final Pattern SCHEME = Pattern.compile("[a-z]+://.+");
/**
* Set to true if we are running unit tests.
* Returns true if we are running unit tests.
*/
public static boolean isUnitTest = false;
public static boolean getIsUnitTest() {
return Main.isUnitTest;
}
}
......@@ -25,6 +25,7 @@ package hudson;
import hudson.util.DualOutputStream;
import hudson.util.EncodingStream;
import com.thoughtworks.xstream.core.util.Base64Encoder;
import java.io.File;
import java.io.FileInputStream;
......@@ -80,8 +81,13 @@ public class Main {
String home = getHudsonHome();
if(!home.endsWith("/")) home = home + '/'; // make sure it ends with '/'
// check for authentication info
String auth = new URL(home).getUserInfo();
if(auth != null) auth = "Basic " + new Base64Encoder().encode(auth.getBytes("UTF-8"));
{// check if the home is set correctly
HttpURLConnection con = (HttpURLConnection)new URL(home).openConnection();
if (auth != null) con.setRequestProperty("Authorization", auth);
con.connect();
if(con.getResponseCode()!=200
|| con.getHeaderField("X-Hudson")==null) {
......@@ -94,6 +100,7 @@ public class Main {
{// check if the job name is correct
HttpURLConnection con = (HttpURLConnection)new URL(home+"job/"+projectNameEnc+"/acceptBuildResult").openConnection();
if (auth != null) con.setRequestProperty("Authorization", auth);
con.connect();
if(con.getResponseCode()!=200) {
System.err.println(projectName+" is not a valid job name on "+home+" ("+con.getResponseMessage()+")");
......@@ -130,6 +137,7 @@ public class Main {
try {
// start a remote connection
HttpURLConnection con = (HttpURLConnection) new URL(location).openConnection();
if (auth != null) con.setRequestProperty("Authorization", auth);
con.setDoOutput(true);
// this tells HttpURLConnection not to buffer the whole thing
con.setFixedLengthStreamingMode((int)tmpFile.length());
......@@ -155,4 +163,9 @@ public class Main {
}
}
}
/**
* Set to true if we are running unit tests.
*/
public static boolean isUnitTest = false;
}
......@@ -26,6 +26,7 @@ package org.jvnet.hudson.test;
import hudson.CloseProofOutputStream;
import hudson.FilePath;
import hudson.Functions;
import hudson.Main;
import hudson.WebAppMain;
import hudson.EnvVars;
import hudson.ExtensionList;
......@@ -1107,7 +1108,7 @@ public abstract class HudsonTestCase extends TestCase {
Logger.getLogger("org.springframework").setLevel(Level.WARNING);
// hudson-behavior.js relies on this to decide whether it's running unit tests.
Functions.isUnitTest = true;
Main.isUnitTest = true;
// prototype.js calls this method all the time, so ignore this warning.
XML_HTTP_REQUEST_LOGGER.setFilter(new Filter() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册