|
3 | 3 | */ |
4 | 4 | package com.microsoft.mssql; |
5 | 5 |
|
6 | | -import java.security.Principal; |
7 | 6 | import java.io.File; |
| 7 | +import java.security.Principal; |
8 | 8 |
|
9 | 9 | import org.apache.http.HttpEntity; |
| 10 | +import org.apache.http.auth.AuthSchemeProvider; |
10 | 11 | import org.apache.http.auth.AuthScope; |
11 | 12 | import org.apache.http.auth.Credentials; |
12 | 13 | import org.apache.http.client.CredentialsProvider; |
| 14 | +import org.apache.http.client.config.AuthSchemes; |
13 | 15 | import org.apache.http.client.methods.CloseableHttpResponse; |
14 | | -import org.apache.http.client.methods.HttpGet; |
15 | 16 | import org.apache.http.client.methods.HttpPut; |
16 | 17 | import org.apache.http.client.methods.HttpUriRequest; |
17 | 18 | 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; |
19 | 21 | 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; |
20 | 28 | import org.apache.http.impl.client.HttpClients; |
21 | 29 | import org.apache.http.util.EntityUtils; |
22 | 30 |
|
@@ -65,9 +73,23 @@ public void clear() { |
65 | 73 |
|
66 | 74 | private static void uploadResource(String inputFilePath, String outputFilePath){ |
67 | 75 | 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 | + |
68 | 90 | // Construct Knox endpoint |
69 | 91 | 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()) { |
71 | 93 | HttpUriRequest request = new HttpPut(createOperationEndpoint); |
72 | 94 | // First request to get the location in data nodes |
73 | 95 | try (CloseableHttpResponse response = client2.execute(request)) { |
|
0 commit comments