mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
added support for proxy servers with authentication
This commit is contained in:
@@ -47,6 +47,8 @@ import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.core.util.Base64;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
@@ -69,6 +71,9 @@ import java.util.Map;
|
||||
public class URLHttpClient implements HttpClient
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String CREDENTIAL_SEPARATOR = ":";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENCODING = "UTF-8";
|
||||
|
||||
@@ -78,6 +83,9 @@ public class URLHttpClient implements HttpClient
|
||||
/** Field description */
|
||||
public static final String HEADER_ACCEPT_ENCODING_VALUE = "gzip";
|
||||
|
||||
/** Field description */
|
||||
public static final String HEADER_PROXY_AUTHORIZATION = "Proxy-Authorization";
|
||||
|
||||
/** Field description */
|
||||
public static final String HEADER_USERAGENT = "User-Agent";
|
||||
|
||||
@@ -87,6 +95,9 @@ public class URLHttpClient implements HttpClient
|
||||
/** Field description */
|
||||
public static final String METHOD_POST = "POST";
|
||||
|
||||
/** Field description */
|
||||
public static final String PREFIX_BASIC_AUTHENTICATION = "Basic ";
|
||||
|
||||
/** Field description */
|
||||
public static final int TIMEOUT_CONNECTION = 30000;
|
||||
|
||||
@@ -353,6 +364,25 @@ public class URLHttpClient implements HttpClient
|
||||
connection.setRequestProperty(
|
||||
HEADER_USERAGENT, HEADER_USERAGENT_VALUE.concat(context.getVersion()));
|
||||
|
||||
String username = configuration.getProxyUser();
|
||||
String password = configuration.getProxyPassword();
|
||||
|
||||
if (Util.isNotEmpty(username) || Util.isNotEmpty(password))
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("enable proxy authentication for user '{}'",
|
||||
Util.nonNull(username));
|
||||
}
|
||||
|
||||
String auth = Util.nonNull(username).concat(CREDENTIAL_SEPARATOR).concat(
|
||||
Util.nonNull(password));
|
||||
|
||||
auth = PREFIX_BASIC_AUTHENTICATION.concat(
|
||||
new String(Base64.encode(auth.getBytes())));
|
||||
connection.setRequestProperty(HEADER_PROXY_AUTHORIZATION, auth);
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user