]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8084 Support HTTP proxy authentication
authorJulien HENRY <julien.henry@sonarsource.com>
Wed, 14 Sep 2016 21:08:59 +0000 (23:08 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Wed, 14 Sep 2016 21:08:59 +0000 (23:08 +0200)
Tested by an IT in SQ Scanner API

sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchWsClientProvider.java

index 96bcb33ff781d240bc546afab56cb8999ee8907c..c40c1ddb761d4361643fe01d8cea9a47fd27cb57 100644 (file)
@@ -44,8 +44,6 @@ public class BatchWsClientProvider extends ProviderAdapter {
       String url = defaultIfBlank(settings.property("sonar.host.url"), CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE);
       HttpConnector.Builder connectorBuilder = HttpConnector.newBuilder();
 
-      // TODO proxy
-
       String timeoutSec = defaultIfBlank(settings.property(READ_TIMEOUT_SEC_PROPERTY), valueOf(DEFAULT_READ_TIMEOUT_SEC));
       String login = defaultIfBlank(settings.property(CoreProperties.LOGIN), null);
       connectorBuilder
@@ -55,6 +53,12 @@ public class BatchWsClientProvider extends ProviderAdapter {
         .url(url)
         .credentials(login, settings.property(CoreProperties.PASSWORD));
 
+      // OkHttp detect 'http.proxyHost' java property, but credentials should be filled
+      final String proxyUser = System.getProperty("http.proxyUser", "");
+      if (!System.getProperty("http.proxyHost", "").isEmpty() && !proxyUser.isEmpty()) {
+        connectorBuilder.proxyCredentials(proxyUser, System.getProperty("http.proxyPassword"));
+      }
+
       wsClient = new BatchWsClient(WsClientFactories.getDefault().newClient(connectorBuilder.build()), login != null);
     }
     return wsClient;