Skip to content

Commit 8bbfcae

Browse files
author
Melony QIN
authored
Merge pull request #7 from saurabh500/fixRdnsIssue
Turn off reverse DNS lookup
2 parents 7caf957 + 6bb293d commit 8bbfcae

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

  • samples/features/sql-big-data-cluster/connectivity/webhdfs-java-client/src/main/java/com/microsoft/mssql

samples/features/sql-big-data-cluster/connectivity/webhdfs-java-client/src/main/java/com/microsoft/mssql/App.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,28 @@
33
*/
44
package com.microsoft.mssql;
55

6-
import java.security.Principal;
76
import java.io.File;
7+
import java.security.Principal;
88

99
import org.apache.http.HttpEntity;
10+
import org.apache.http.auth.AuthSchemeProvider;
1011
import org.apache.http.auth.AuthScope;
1112
import org.apache.http.auth.Credentials;
1213
import org.apache.http.client.CredentialsProvider;
14+
import org.apache.http.client.config.AuthSchemes;
1315
import org.apache.http.client.methods.CloseableHttpResponse;
14-
import org.apache.http.client.methods.HttpGet;
1516
import org.apache.http.client.methods.HttpPut;
1617
import org.apache.http.client.methods.HttpUriRequest;
1718
import org.apache.http.client.methods.RequestBuilder;
18-
import org.apache.http.impl.client.CloseableHttpClient;
19+
import org.apache.http.config.Registry;
20+
import org.apache.http.config.RegistryBuilder;
1921
import org.apache.http.entity.mime.MultipartEntityBuilder;
22+
import org.apache.http.impl.auth.BasicSchemeFactory;
23+
import org.apache.http.impl.auth.DigestSchemeFactory;
24+
import org.apache.http.impl.auth.KerberosSchemeFactory;
25+
import org.apache.http.impl.auth.NTLMSchemeFactory;
26+
import org.apache.http.impl.auth.SPNegoSchemeFactory;
27+
import org.apache.http.impl.client.CloseableHttpClient;
2028
import org.apache.http.impl.client.HttpClients;
2129
import org.apache.http.util.EntityUtils;
2230

@@ -65,9 +73,23 @@ public void clear() {
6573

6674
private static void uploadResource(String inputFilePath, String outputFilePath){
6775
System.out.println("Entering create resource");
76+
77+
// Create a custom auth scheme registry to prevent reverse DNS lookup on the Http Endpoints
78+
// For BDC, the same IP address can be associated with multiple service endpoints. Hence control.aris.local and knox.aris.local
79+
// can resolve to the same IP during reverse lookup. As a result of this kerberos auth may fail.
80+
// To fix the problem, we should prevent reverse lookup by turning off Hostname Canonicalization in HTTP client and
81+
// recommend that the user use the FQDN of knox endpoint to connect to knox.
82+
Registry<AuthSchemeProvider> authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeProvider>create()
83+
.register(AuthSchemes.BASIC, new BasicSchemeFactory())
84+
.register(AuthSchemes.DIGEST, new DigestSchemeFactory())
85+
.register(AuthSchemes.NTLM, new NTLMSchemeFactory())
86+
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, false))
87+
.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory(true, false))
88+
.build();
89+
6890
// Construct Knox endpoint
6991
String createOperationEndpoint = GW_ENDPOINT + outputFilePath + "?op=CREATE&overwrite=true";
70-
try (CloseableHttpClient client2 = HttpClients.custom().setDefaultCredentialsProvider(provider).build()) {
92+
try (CloseableHttpClient client2 = HttpClients.custom().setDefaultCredentialsProvider(provider).setDefaultAuthSchemeRegistry(authSchemeRegistryCopy).build()) {
7193
HttpUriRequest request = new HttpPut(createOperationEndpoint);
7294
// First request to get the location in data nodes
7395
try (CloseableHttpResponse response = client2.execute(request)) {

0 commit comments

Comments
 (0)