3939import org .sonarsource .scanner .lib .internal .cache .Logger ;
4040
4141import static java .lang .String .format ;
42- import static java .nio .charset .StandardCharsets .UTF_8 ;
4342
4443public class ServerConnection {
4544
4645 private final String baseUrlWithoutTrailingSlash ;
4746 private final String userAgent ;
4847 private final OkHttpClient httpClient ;
4948
50- private final String token ;
49+ @ Nullable
50+ private final String credentials ;
5151 private final Logger logger ;
5252
53- ServerConnection (String baseUrl , String userAgent , @ Nullable String token , Logger logger , Map <String , String > bootstrapProperties , SonarUserHome sonarUserHome ) {
54- this .token = token ;
53+ ServerConnection (String baseUrl , String userAgent , @ Nullable String credentials , Logger logger , Map <String , String > bootstrapProperties , SonarUserHome sonarUserHome ) {
54+ this .credentials = credentials ;
5555 this .logger = logger ;
5656 this .baseUrlWithoutTrailingSlash = removeTrailingSlash (baseUrl );
5757 this .userAgent = userAgent ;
@@ -66,7 +66,12 @@ public static ServerConnection create(Map<String, String> bootstrapProperties, L
6666 String serverUrl = bootstrapProperties .get ("sonar.host.url" );
6767 String userAgent = format ("%s/%s" , bootstrapProperties .get (InternalProperties .SCANNER_APP ), bootstrapProperties .get (InternalProperties .SCANNER_APP_VERSION ));
6868 String token = bootstrapProperties .get (ScannerProperties .SONAR_TOKEN );
69- return new ServerConnection (serverUrl , userAgent , token , logger , bootstrapProperties , sonarUserHome );
69+ String login = bootstrapProperties .getOrDefault (ScannerProperties .SONAR_LOGIN , token );
70+ String credentials = null ;
71+ if (login != null ) {
72+ credentials = Credentials .basic (login , bootstrapProperties .getOrDefault (ScannerProperties .SONAR_PASSWORD , "" ));
73+ }
74+ return new ServerConnection (serverUrl , userAgent , credentials , logger , bootstrapProperties , sonarUserHome );
7075 }
7176
7277 /**
@@ -118,8 +123,8 @@ private ResponseBody callUrl(String url) throws IOException {
118123 .get ()
119124 .url (url )
120125 .addHeader ("User-Agent" , userAgent );
121- if (token != null ) {
122- requestBuilder .header ("Authorization" , Credentials . basic ( token , "" , UTF_8 ) );
126+ if (credentials != null ) {
127+ requestBuilder .header ("Authorization" , credentials );
123128 }
124129 Request request = requestBuilder .build ();
125130 Response response = httpClient .newCall (request ).execute ();
0 commit comments