Skip to content

Commit e9271cf

Browse files
committed
Improve NTLM support by supporting JDK property
1 parent 42ea80d commit e9271cf

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/main/java/com/ning/http/client/Realm.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717
package com.ning.http.client;
1818

19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
1922
import java.io.UnsupportedEncodingException;
2023
import java.security.MessageDigest;
2124
import java.security.NoSuchAlgorithmException;
@@ -243,6 +246,8 @@ public int hashCode() {
243246
*/
244247
public static class RealmBuilder {
245248

249+
private static final Logger logger = LoggerFactory.getLogger(RealmBuilder.class);
250+
246251
//
247252
// Portions of code (newCnonce, newResponse) are highly inspired be Jetty 6 BasicAuthentication.java class.
248253
// This code is already Apache licenced.
@@ -555,6 +560,14 @@ public Realm build() {
555560
}
556561
}
557562

563+
if (scheme.equals(AuthScheme.NTLM) && domain.equalsIgnoreCase("")){
564+
logger.info("NTLM domain is not set, trying to read it from system property -Dhttp.auth.ntlm.domain");
565+
String tmp = System.getProperty("http.auth.ntlm.domain");
566+
if (tmp != null) {
567+
domain = tmp;
568+
}
569+
}
570+
558571
return new Realm(scheme,
559572
principal,
560573
password,

src/main/java/com/ning/http/client/providers/jdk/JDKAsyncHttpProvider.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,14 @@ private void configure(URI uri, HttpURLConnection urlConnection, Request request
499499

500500
if (proxyServer.getProtocol().equals(ProxyServer.Protocol.NTLM)) {
501501

502-
if (proxyServer.getNtlmDomain() == null) throw new IllegalStateException("NTLM Domain cannot be null");
503-
504502
jdkNtlmDomain = System.getProperty(NTLM_DOMAIN);
503+
if (proxyServer.getNtlmDomain() == null) {
504+
logger.info("NTLM domain is not set, trying to read it from system property -D{}", NTLM_DOMAIN);
505+
if (jdkNtlmDomain != null) {
506+
proxyServer.setNtlmDomain(jdkNtlmDomain);
507+
}
508+
}
509+
505510
System.setProperty(NTLM_DOMAIN, proxyServer.getNtlmDomain());
506511
}
507512
}
@@ -525,7 +530,11 @@ private void configure(URI uri, HttpURLConnection urlConnection, Request request
525530
break;
526531
case NTLM:
527532
jdkNtlmDomain = System.getProperty(NTLM_DOMAIN);
528-
System.setProperty(NTLM_DOMAIN, realm.getDomain());
533+
if (realm.getNtlmDomain() == null) {
534+
logger.info("NTLM domain is not set, trying to read it from system property -D{}", NTLM_DOMAIN);
535+
} else {
536+
System.setProperty(NTLM_DOMAIN, realm.getNtlmDomain());
537+
}
529538
break;
530539
default:
531540
throw new IllegalStateException(String.format("Invalid Authentication %s", realm.toString()));

0 commit comments

Comments
 (0)