@@ -49,19 +49,21 @@ public class ServerConnection {
4949 private String restApiBaseUrl ;
5050 private String userAgent ;
5151 @ Nullable
52- private String credentials ;
52+ private String token ;
53+ @ Nullable
54+ private String login ;
55+ @ Nullable
56+ private String password ;
5357 private OkHttpClient httpClient ;
5458
5559 public void init (Map <String , String > bootstrapProperties , Path sonarUserHome ) {
5660 webApiBaseUrl = removeTrailingSlash (bootstrapProperties .get (ScannerProperties .HOST_URL ));
5761 restApiBaseUrl = removeTrailingSlash (bootstrapProperties .get (ScannerProperties .API_BASE_URL ));
5862 userAgent = format ("%s/%s" , bootstrapProperties .get (InternalProperties .SCANNER_APP ),
5963 bootstrapProperties .get (InternalProperties .SCANNER_APP_VERSION ));
60- String token = bootstrapProperties .get (ScannerProperties .SONAR_TOKEN );
61- String login = bootstrapProperties .getOrDefault (ScannerProperties .SONAR_LOGIN , token );
62- if (login != null ) {
63- credentials = Credentials .basic (login , bootstrapProperties .getOrDefault (ScannerProperties .SONAR_PASSWORD , "" ));
64- }
64+ this .token = bootstrapProperties .get (ScannerProperties .SONAR_TOKEN );
65+ this .login = bootstrapProperties .get (ScannerProperties .SONAR_LOGIN );
66+ this .password = bootstrapProperties .get (ScannerProperties .SONAR_PASSWORD );
6567 httpClient = OkHttpClientFactory .create (bootstrapProperties , sonarUserHome );
6668 }
6769
@@ -158,8 +160,12 @@ private ResponseBody callUrl(String url, boolean authentication, @Nullable Strin
158160 .get ()
159161 .url (url )
160162 .addHeader ("User-Agent" , userAgent );
161- if (authentication && credentials != null ) {
162- requestBuilder .header ("Authorization" , credentials );
163+ if (authentication ) {
164+ if (token != null ) {
165+ requestBuilder .header ("Authorization" , "Bearer " + token );
166+ } else if (login != null ) {
167+ requestBuilder .header ("Authorization" , Credentials .basic (login , password != null ? password : "" ));
168+ }
163169 }
164170 if (acceptHeader != null ) {
165171 requestBuilder .header ("Accept" , acceptHeader );
0 commit comments