19
19
import org .asynchttpclient .spnego .SpnegoEngine ;
20
20
import org .asynchttpclient .spnego .SpnegoEngineException ;
21
21
import org .asynchttpclient .uri .Uri ;
22
+ import org .jetbrains .annotations .Nullable ;
22
23
23
24
import java .nio .charset .Charset ;
24
25
import java .nio .charset .StandardCharsets ;
@@ -38,7 +39,7 @@ private AuthenticatorUtils() {
38
39
// Prevent outside initialization
39
40
}
40
41
41
- public static String getHeaderWithPrefix (List <String > authenticateHeaders , String prefix ) {
42
+ public static @ Nullable String getHeaderWithPrefix (@ Nullable List <String > authenticateHeaders , String prefix ) {
42
43
if (authenticateHeaders != null ) {
43
44
for (String authenticateHeader : authenticateHeaders ) {
44
45
if (authenticateHeader .regionMatches (true , 0 , prefix , 0 , prefix .length ())) {
@@ -50,11 +51,11 @@ public static String getHeaderWithPrefix(List<String> authenticateHeaders, Strin
50
51
return null ;
51
52
}
52
53
53
- private static String computeBasicAuthentication (Realm realm ) {
54
+ private static @ Nullable String computeBasicAuthentication (@ Nullable Realm realm ) {
54
55
return realm != null ? computeBasicAuthentication (realm .getPrincipal (), realm .getPassword (), realm .getCharset ()) : null ;
55
56
}
56
57
57
- private static String computeBasicAuthentication (String principal , String password , Charset charset ) {
58
+ private static String computeBasicAuthentication (@ Nullable String principal , @ Nullable String password , Charset charset ) {
58
59
String s = principal + ':' + password ;
59
60
return "Basic " + Base64 .getEncoder ().encodeToString (s .getBytes (charset ));
60
61
}
@@ -68,9 +69,9 @@ public static String computeRealmURI(Uri uri, boolean useAbsoluteURI, boolean om
68
69
}
69
70
}
70
71
71
- private static String computeDigestAuthentication (Realm realm ) {
72
+ private static String computeDigestAuthentication (Realm realm , Uri uri ) {
72
73
73
- String realmUri = computeRealmURI (realm . getUri () , realm .isUseAbsoluteURI (), realm .isOmitQuery ());
74
+ String realmUri = computeRealmURI (uri , realm .isUseAbsoluteURI (), realm .isOmitQuery ());
74
75
75
76
StringBuilder builder = new StringBuilder ().append ("Digest " );
76
77
append (builder , "username" , realm .getPrincipal (), true );
@@ -99,7 +100,7 @@ private static String computeDigestAuthentication(Realm realm) {
99
100
return new String (StringUtils .charSequence2Bytes (builder , ISO_8859_1 ), StandardCharsets .UTF_8 );
100
101
}
101
102
102
- private static void append (StringBuilder builder , String name , String value , boolean quoted ) {
103
+ private static void append (StringBuilder builder , String name , @ Nullable String value , boolean quoted ) {
103
104
builder .append (name ).append ('=' );
104
105
if (quoted ) {
105
106
builder .append ('"' ).append (value ).append ('"' );
@@ -109,7 +110,7 @@ private static void append(StringBuilder builder, String name, String value, boo
109
110
builder .append (", " );
110
111
}
111
112
112
- public static String perConnectionProxyAuthorizationHeader (Request request , Realm proxyRealm ) {
113
+ public static @ Nullable String perConnectionProxyAuthorizationHeader (Request request , @ Nullable Realm proxyRealm ) {
113
114
String proxyAuthorization = null ;
114
115
if (proxyRealm != null && proxyRealm .isUsePreemptiveAuth ()) {
115
116
switch (proxyRealm .getScheme ()) {
@@ -130,7 +131,7 @@ public static String perConnectionProxyAuthorizationHeader(Request request, Real
130
131
return proxyAuthorization ;
131
132
}
132
133
133
- public static String perRequestProxyAuthorizationHeader (Request request , Realm proxyRealm ) {
134
+ public static @ Nullable String perRequestProxyAuthorizationHeader (Request request , @ Nullable Realm proxyRealm ) {
134
135
String proxyAuthorization = null ;
135
136
if (proxyRealm != null && proxyRealm .isUsePreemptiveAuth ()) {
136
137
@@ -141,11 +142,12 @@ public static String perRequestProxyAuthorizationHeader(Request request, Realm p
141
142
case DIGEST :
142
143
if (isNonEmpty (proxyRealm .getNonce ())) {
143
144
// update realm with request information
145
+ final Uri uri = request .getUri ();
144
146
proxyRealm = realm (proxyRealm )
145
- .setUri (request . getUri () )
147
+ .setUri (uri )
146
148
.setMethodName (request .getMethod ())
147
149
.build ();
148
- proxyAuthorization = computeDigestAuthentication (proxyRealm );
150
+ proxyAuthorization = computeDigestAuthentication (proxyRealm , uri );
149
151
}
150
152
break ;
151
153
case NTLM :
@@ -162,7 +164,8 @@ public static String perRequestProxyAuthorizationHeader(Request request, Realm p
162
164
return proxyAuthorization ;
163
165
}
164
166
165
- public static String perConnectionAuthorizationHeader (Request request , ProxyServer proxyServer , Realm realm ) {
167
+ public static @ Nullable String perConnectionAuthorizationHeader (Request request , @ Nullable ProxyServer proxyServer ,
168
+ @ Nullable Realm realm ) {
166
169
String authorizationHeader = null ;
167
170
168
171
if (realm != null && realm .isUsePreemptiveAuth ()) {
@@ -203,7 +206,7 @@ public static String perConnectionAuthorizationHeader(Request request, ProxyServ
203
206
return authorizationHeader ;
204
207
}
205
208
206
- public static String perRequestAuthorizationHeader (Request request , Realm realm ) {
209
+ public static @ Nullable String perRequestAuthorizationHeader (Request request , @ Nullable Realm realm ) {
207
210
String authorizationHeader = null ;
208
211
if (realm != null && realm .isUsePreemptiveAuth ()) {
209
212
@@ -214,11 +217,12 @@ public static String perRequestAuthorizationHeader(Request request, Realm realm)
214
217
case DIGEST :
215
218
if (isNonEmpty (realm .getNonce ())) {
216
219
// update realm with request information
220
+ final Uri uri = request .getUri ();
217
221
realm = realm (realm )
218
- .setUri (request . getUri () )
222
+ .setUri (uri )
219
223
.setMethodName (request .getMethod ())
220
224
.build ();
221
- authorizationHeader = computeDigestAuthentication (realm );
225
+ authorizationHeader = computeDigestAuthentication (realm , uri );
222
226
}
223
227
break ;
224
228
case NTLM :
0 commit comments