Skip to content

Commit 353e448

Browse files
Register NTLM authentication support explicitly
1 parent d5f8832 commit 353e448

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/main/java/jenkins/plugins/http_request/auth/CredentialNtlmAuthentication.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22

33
import java.io.PrintStream;
44
import java.net.URISyntaxException;
5+
import java.util.List;
56

7+
import org.apache.hc.client5.http.auth.AuthSchemeFactory;
8+
import org.apache.hc.client5.http.auth.StandardAuthScheme;
69
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
10+
import org.apache.hc.client5.http.config.RequestConfig;
711
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
812
import org.apache.hc.client5.http.auth.AuthScope;
913
import org.apache.hc.client5.http.auth.NTCredentials;
14+
import org.apache.hc.client5.http.impl.auth.NTLMSchemeFactory;
1015
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
1116
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
1217
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;
1320

1421
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
1522

@@ -59,8 +66,21 @@ static CloseableHttpClient auth(HttpClientBuilder clientBuilder, HttpClientConte
5966
new AuthScope(requestBase.getUri().getHost(), requestBase.getUri().getPort()),
6067
new NTCredentials(username, password.toCharArray(), requestBase.getUri().getHost(), domain));
6168

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);
6382
context.setCredentialsProvider(provider);
83+
context.setAuthSchemeRegistry(authRegistry);
6484

6585
return clientBuilder.build();
6686
} catch (URISyntaxException ex) {

0 commit comments

Comments
 (0)