@@ -53,14 +53,15 @@ public class Realm {
53
53
private final Charset charset ;
54
54
private final boolean useAbsoluteURI ;
55
55
private final boolean omitQuery ;
56
+ private final boolean targetProxy ;
56
57
57
58
public enum AuthScheme {
58
59
DIGEST , BASIC , NTLM , SPNEGO , KERBEROS , NONE
59
60
}
60
61
61
62
private Realm (AuthScheme scheme , String principal , String password , String realmName , String nonce , String algorithm , String response ,
62
63
String qop , String nc , String cnonce , UriComponents uri , String method , boolean usePreemptiveAuth , String ntlmDomain , String enc ,
63
- String host , boolean messageType2Received , String opaque , boolean useAbsoluteURI , boolean omitQuery ) {
64
+ String host , boolean messageType2Received , String opaque , boolean useAbsoluteURI , boolean omitQuery , boolean targetProxy ) {
64
65
65
66
this .principal = principal ;
66
67
this .password = password ;
@@ -83,6 +84,7 @@ private Realm(AuthScheme scheme, String principal, String password, String realm
83
84
this .charset = enc != null ? Charset .forName (enc ) : null ;
84
85
this .useAbsoluteURI = useAbsoluteURI ;
85
86
this .omitQuery = omitQuery ;
87
+ this .targetProxy = targetProxy ;
86
88
}
87
89
88
90
public String getPrincipal () {
@@ -188,7 +190,11 @@ public boolean isUseAbsoluteURI() {
188
190
public boolean isOmitQuery () {
189
191
return omitQuery ;
190
192
}
191
-
193
+
194
+ public boolean isTargetProxy () {
195
+ return targetProxy ;
196
+ }
197
+
192
198
@ Override
193
199
public boolean equals (Object o ) {
194
200
if (this == o )
@@ -271,20 +277,21 @@ public static class RealmBuilder {
271
277
private String cnonce = "" ;
272
278
private UriComponents uri ;
273
279
private String methodName = "GET" ;
274
- private boolean usePreemptive = false ;
275
- private String domain = System .getProperty ("http.auth.ntlm.domain" , "" );
280
+ private boolean usePreemptive ;
281
+ private String ntlmDomain = System .getProperty ("http.auth.ntlm.domain" , "" );
276
282
private String enc = StandardCharsets .UTF_8 .name ();
277
283
private String host = "localhost" ;
278
- private boolean messageType2Received = false ;
284
+ private boolean messageType2Received ;
279
285
private boolean useAbsoluteURI = true ;
280
- private boolean omitQuery = false ;
286
+ private boolean omitQuery ;
287
+ private boolean targetProxy ;
281
288
282
289
public String getNtlmDomain () {
283
- return domain ;
290
+ return ntlmDomain ;
284
291
}
285
292
286
- public RealmBuilder setNtlmDomain (String domain ) {
287
- this .domain = domain ;
293
+ public RealmBuilder setNtlmDomain (String ntlmDomain ) {
294
+ this .ntlmDomain = ntlmDomain ;
288
295
return this ;
289
296
}
290
297
@@ -436,7 +443,16 @@ public RealmBuilder setOmitQuery(boolean omitQuery) {
436
443
this .omitQuery = omitQuery ;
437
444
return this ;
438
445
}
439
-
446
+
447
+ public boolean isTargetProxy () {
448
+ return targetProxy ;
449
+ }
450
+
451
+ public RealmBuilder setTargetProxy (boolean targetProxy ) {
452
+ this .targetProxy = targetProxy ;
453
+ return this ;
454
+ }
455
+
440
456
public RealmBuilder parseWWWAuthenticateHeader (String headerLine ) {
441
457
setRealmName (match (headerLine , "realm" ));
442
458
setNonce (match (headerLine , "nonce" ));
@@ -464,6 +480,7 @@ public RealmBuilder parseProxyAuthenticateHeader(String headerLine) {
464
480
} else {
465
481
setScheme (AuthScheme .BASIC );
466
482
}
483
+ setTargetProxy (true );
467
484
return this ;
468
485
}
469
486
@@ -484,6 +501,9 @@ public RealmBuilder clone(Realm clone) {
484
501
setNtlmDomain (clone .getNtlmDomain ());
485
502
setNtlmHost (clone .getNtlmHost ());
486
503
setNtlmMessageType2Received (clone .isNtlmMessageType2Received ());
504
+ setUseAbsoluteURI (clone .isUseAbsoluteURI ());
505
+ setOmitQuery (clone .isOmitQuery ());
506
+ setTargetProxy (clone .isTargetProxy ());
487
507
return this ;
488
508
}
489
509
@@ -511,8 +531,8 @@ private String match(String headerLine, String token) {
511
531
512
532
// = to skip
513
533
match += token .length () + 1 ;
514
- int traillingComa = headerLine .indexOf ("," , match );
515
- String value = headerLine .substring (match , traillingComa > 0 ? traillingComa : headerLine .length ());
534
+ int trailingComa = headerLine .indexOf ("," , match );
535
+ String value = headerLine .substring (match , trailingComa > 0 ? trailingComa : headerLine .length ());
516
536
value = value .length () > 0 && value .charAt (value .length () - 1 ) == '"' ? value .substring (0 , value .length () - 1 ) : value ;
517
537
return value .charAt (0 ) == '"' ? value .substring (1 ) : value ;
518
538
}
@@ -609,7 +629,7 @@ public Realm build() {
609
629
}
610
630
611
631
return new Realm (scheme , principal , password , realmName , nonce , algorithm , response , qop , nc , cnonce , uri , methodName ,
612
- usePreemptive , domain , enc , host , messageType2Received , opaque , useAbsoluteURI , omitQuery );
632
+ usePreemptive , ntlmDomain , enc , host , messageType2Received , opaque , useAbsoluteURI , omitQuery , targetProxy );
613
633
}
614
634
}
615
635
}
0 commit comments