Skip to content

Commit e6061f2

Browse files
committed
Fix fail to launch Livy interactive console for HDInsight and Aris cluster issue
1 parent 4a093f7 commit e6061f2

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/sdk/common/HttpObservable.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,11 @@
3131
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
3232
import com.microsoft.azuretools.service.ServiceManager;
3333
import com.microsoft.tooling.msservices.components.DefaultLoader;
34+
import org.apache.commons.codec.binary.Base64;
35+
import org.apache.commons.lang3.StringUtils;
3436
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.*;
4138
import org.apache.http.client.CookieStore;
42-
import org.apache.http.client.CredentialsProvider;
4339
import org.apache.http.client.config.AuthSchemes;
4440
import org.apache.http.client.config.CookieSpecs;
4541
import org.apache.http.client.config.RequestConfig;
@@ -50,7 +46,6 @@
5046
import org.apache.http.conn.ssl.NoopHostnameVerifier;
5147
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
5248
import org.apache.http.impl.client.BasicCookieStore;
53-
import org.apache.http.impl.client.BasicCredentialsProvider;
5449
import org.apache.http.impl.client.CloseableHttpClient;
5550
import org.apache.http.impl.client.HttpClients;
5651
import org.apache.http.message.BasicHeader;
@@ -66,6 +61,7 @@
6661
import javax.net.ssl.SSLContext;
6762
import java.io.IOException;
6863
import java.net.UnknownServiceException;
64+
import java.nio.charset.StandardCharsets;
6965
import java.security.KeyManagementException;
7066
import java.security.KeyStoreException;
7167
import java.security.NoSuchAlgorithmException;
@@ -146,14 +142,16 @@ public HttpObservable() {
146142
public HttpObservable(@NotNull final String username, @NotNull final String password) {
147143
this();
148144

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+
}
152151

153152
this.httpClient = HttpClients.custom()
154153
.useSystemProperties()
155154
.setDefaultCookieStore(getCookieStore())
156-
.setDefaultCredentialsProvider(credentialsProvider)
157155
.setDefaultRequestConfig(getDefaultRequestConfig())
158156
.setSSLSocketFactory(createSSLSocketFactory())
159157
.build();

0 commit comments

Comments
 (0)