|
31 | 31 | import com.microsoft.azuretools.azurecommons.helpers.Nullable; |
32 | 32 | import com.microsoft.azuretools.service.ServiceManager; |
33 | 33 | import com.microsoft.tooling.msservices.components.DefaultLoader; |
| 34 | +import org.apache.commons.codec.binary.Base64; |
| 35 | +import org.apache.commons.lang3.StringUtils; |
34 | 36 | import org.apache.commons.lang3.exception.ExceptionUtils; |
35 | | -import org.apache.http.Header; |
36 | | -import org.apache.http.HttpEntity; |
37 | | -import org.apache.http.NameValuePair; |
38 | | -import org.apache.http.StatusLine; |
39 | | -import org.apache.http.auth.AuthScope; |
40 | | -import org.apache.http.auth.UsernamePasswordCredentials; |
| 37 | +import org.apache.http.*; |
41 | 38 | import org.apache.http.client.CookieStore; |
42 | | -import org.apache.http.client.CredentialsProvider; |
43 | 39 | import org.apache.http.client.config.AuthSchemes; |
44 | 40 | import org.apache.http.client.config.CookieSpecs; |
45 | 41 | import org.apache.http.client.config.RequestConfig; |
|
50 | 46 | import org.apache.http.conn.ssl.NoopHostnameVerifier; |
51 | 47 | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
52 | 48 | import org.apache.http.impl.client.BasicCookieStore; |
53 | | -import org.apache.http.impl.client.BasicCredentialsProvider; |
54 | 49 | import org.apache.http.impl.client.CloseableHttpClient; |
55 | 50 | import org.apache.http.impl.client.HttpClients; |
56 | 51 | import org.apache.http.message.BasicHeader; |
|
66 | 61 | import javax.net.ssl.SSLContext; |
67 | 62 | import java.io.IOException; |
68 | 63 | import java.net.UnknownServiceException; |
| 64 | +import java.nio.charset.StandardCharsets; |
69 | 65 | import java.security.KeyManagementException; |
70 | 66 | import java.security.KeyStoreException; |
71 | 67 | import java.security.NoSuchAlgorithmException; |
@@ -146,14 +142,16 @@ public HttpObservable() { |
146 | 142 | public HttpObservable(@NotNull final String username, @NotNull final String password) { |
147 | 143 | this(); |
148 | 144 |
|
149 | | - CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); |
150 | | - credentialsProvider.setCredentials( |
151 | | - new AuthScope(AuthScope.ANY), new UsernamePasswordCredentials(username, password)); |
| 145 | + if (StringUtils.isNotBlank(username)) { |
| 146 | + String auth = username + ":" + password; |
| 147 | + final byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)); |
| 148 | + setDefaultHeader(new BasicHeader( |
| 149 | + HttpHeaders.AUTHORIZATION, String.format("%s %s", "Basic", new String(encodedAuth)))); |
| 150 | + } |
152 | 151 |
|
153 | 152 | this.httpClient = HttpClients.custom() |
154 | 153 | .useSystemProperties() |
155 | 154 | .setDefaultCookieStore(getCookieStore()) |
156 | | - .setDefaultCredentialsProvider(credentialsProvider) |
157 | 155 | .setDefaultRequestConfig(getDefaultRequestConfig()) |
158 | 156 | .setSSLSocketFactory(createSSLSocketFactory()) |
159 | 157 | .build(); |
|
0 commit comments