From 27fc190123382625c14fd2e4922c1fee1870a94e Mon Sep 17 00:00:00 2001 From: SimonBrandhof Date: Mon, 8 Apr 2013 15:02:54 +0200 Subject: [PATCH] SONARPLUGINS-2709 Send HTTP credentials --- .../org/sonar/runner/impl/ServerConnection.java | 15 +++++++++++---- .../sonar/runner/impl/ServerConnectionTest.java | 3 +-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sonar-runner-impl/src/main/java/org/sonar/runner/impl/ServerConnection.java b/sonar-runner-impl/src/main/java/org/sonar/runner/impl/ServerConnection.java index 3ea0f1b..f1c0ff0 100644 --- a/sonar-runner-impl/src/main/java/org/sonar/runner/impl/ServerConnection.java +++ b/sonar-runner-impl/src/main/java/org/sonar/runner/impl/ServerConnection.java @@ -39,17 +39,23 @@ class ServerConnection { private final String serverUrl; private final String userAgent; + private final String login; + private final String password; - private ServerConnection(String serverUrl, String app, String appVersion) { + private ServerConnection(String serverUrl, String app, String appVersion, String login, String password) { this.serverUrl = serverUrl; this.userAgent = app + "/" + appVersion; + this.login = login; + this.password = password; } static ServerConnection create(Properties properties) { String serverUrl = properties.getProperty("sonar.host.url"); String app = properties.getProperty(InternalProperties.RUNNER_APP); String appVersion = properties.getProperty(InternalProperties.RUNNER_APP_VERSION); - return new ServerConnection(serverUrl, app, appVersion); + String login = properties.getProperty("sonar.login"); + String password = properties.getProperty("sonar.password"); + return new ServerConnection(serverUrl, app, appVersion, login, password); } void download(String path, File toFile) { @@ -102,8 +108,9 @@ class ServerConnection { request.acceptGzipEncoding().uncompress(true); request.connectTimeout(CONNECT_TIMEOUT_MILLISECONDS).readTimeout(READ_TIMEOUT_MILLISECONDS); request.userAgent(userAgent); - - // TODO send credentials + if (login != null) { + request.basic(login, password!=null ? password : ""); + } return request; } diff --git a/sonar-runner-impl/src/test/java/org/sonar/runner/impl/ServerConnectionTest.java b/sonar-runner-impl/src/test/java/org/sonar/runner/impl/ServerConnectionTest.java index 378aed5..b0df311 100644 --- a/sonar-runner-impl/src/test/java/org/sonar/runner/impl/ServerConnectionTest.java +++ b/sonar-runner-impl/src/test/java/org/sonar/runner/impl/ServerConnectionTest.java @@ -84,9 +84,8 @@ public class ServerConnectionTest { props.setProperty("sonar.host.url", "http://localhost:" + NetworkUtil.getNextAvailablePort()); ServerConnection connection = ServerConnection.create(props); - File toFile = temp.newFile(); try { - connection.download("/batch/index.txt", toFile); + connection.downloadString("/batch/index.txt"); fail(); } catch (Exception e) { // success -- 2.39.5