|
2 | 2 |
|
3 | 3 | import java.io.PrintStream; |
4 | 4 | import java.net.URISyntaxException; |
| 5 | +import java.util.List; |
5 | 6 |
|
| 7 | +import org.apache.hc.client5.http.auth.AuthSchemeFactory; |
| 8 | +import org.apache.hc.client5.http.auth.StandardAuthScheme; |
6 | 9 | import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; |
| 10 | +import org.apache.hc.client5.http.config.RequestConfig; |
7 | 11 | import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider; |
8 | 12 | import org.apache.hc.client5.http.auth.AuthScope; |
9 | 13 | import org.apache.hc.client5.http.auth.NTCredentials; |
| 14 | +import org.apache.hc.client5.http.impl.auth.NTLMSchemeFactory; |
10 | 15 | import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; |
11 | 16 | import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; |
12 | 17 | import org.apache.hc.client5.http.protocol.HttpClientContext; |
| 18 | +import org.apache.hc.core5.http.config.Lookup; |
| 19 | +import org.apache.hc.core5.http.config.RegistryBuilder; |
13 | 20 |
|
14 | 21 | import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials; |
15 | 22 |
|
@@ -59,8 +66,21 @@ static CloseableHttpClient auth(HttpClientBuilder clientBuilder, HttpClientConte |
59 | 66 | new AuthScope(requestBase.getUri().getHost(), requestBase.getUri().getPort()), |
60 | 67 | new NTCredentials(username, password.toCharArray(), requestBase.getUri().getHost(), domain)); |
61 | 68 |
|
62 | | - clientBuilder.setDefaultCredentialsProvider(provider); |
| 69 | + // register NTLM authentication support explicitly |
| 70 | + Lookup<AuthSchemeFactory> authRegistry = RegistryBuilder.<AuthSchemeFactory>create() |
| 71 | + .register(StandardAuthScheme.NTLM, NTLMSchemeFactory.INSTANCE) |
| 72 | + .build(); |
| 73 | + RequestConfig config = RequestConfig.custom().setTargetPreferredAuthSchemes(List.of(StandardAuthScheme.NTLM)) |
| 74 | + .build(); |
| 75 | + |
| 76 | + clientBuilder |
| 77 | + .setDefaultRequestConfig(config) |
| 78 | + .setDefaultCredentialsProvider(provider) |
| 79 | + .setDefaultAuthSchemeRegistry(authRegistry); |
| 80 | + |
| 81 | + context.setRequestConfig(config); |
63 | 82 | context.setCredentialsProvider(provider); |
| 83 | + context.setAuthSchemeRegistry(authRegistry); |
64 | 84 |
|
65 | 85 | return clientBuilder.build(); |
66 | 86 | } catch (URISyntaxException ex) { |
|
0 commit comments