]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
SONARPLUGINS-2709 Send HTTP credentials
authorSimonBrandhof <simon.brandhof@gmail.com>
Mon, 8 Apr 2013 13:02:54 +0000 (15:02 +0200)
committerSimonBrandhof <simon.brandhof@gmail.com>
Mon, 8 Apr 2013 13:18:55 +0000 (15:18 +0200)
sonar-runner-impl/src/main/java/org/sonar/runner/impl/ServerConnection.java
sonar-runner-impl/src/test/java/org/sonar/runner/impl/ServerConnectionTest.java

index 3ea0f1b622effdab05c4395ea37dcdb656e4f79d..f1c0ff01af4454a218b016c6eef3cd831ac9a6b7 100644 (file)
@@ -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;
   }
 
index 378aed5941cdd691c572134e412bc99616ed5058..b0df3116cedb3a945ed6abbb97c2e95b6bcc7291 100644 (file)
@@ -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