equal
deleted
inserted
replaced
34 import java.util.Random; |
34 import java.util.Random; |
35 |
35 |
36 import sun.net.www.HeaderParser; |
36 import sun.net.www.HeaderParser; |
37 import java.security.MessageDigest; |
37 import java.security.MessageDigest; |
38 import java.security.NoSuchAlgorithmException; |
38 import java.security.NoSuchAlgorithmException; |
|
39 import static sun.net.www.protocol.http.HttpURLConnection.HTTP_CONNECT; |
39 |
40 |
40 |
41 |
41 /** |
42 /** |
42 * DigestAuthentication: Encapsulate an http server authentication using |
43 * DigestAuthentication: Encapsulate an http server authentication using |
43 * the "Digest" scheme, as described in RFC2069 and updated in RFC2617 |
44 * the "Digest" scheme, as described in RFC2069 and updated in RFC2617 |
208 } |
209 } |
209 } |
210 } |
210 |
211 |
211 /** |
212 /** |
212 * Reclaculates the request-digest and returns it. |
213 * Reclaculates the request-digest and returns it. |
|
214 * |
|
215 * <P> Used in the common case where the requestURI is simply the |
|
216 * abs_path. |
|
217 * |
|
218 * @param url |
|
219 * the URL |
|
220 * |
|
221 * @param method |
|
222 * the HTTP method |
|
223 * |
213 * @return the value of the HTTP header this authentication wants set |
224 * @return the value of the HTTP header this authentication wants set |
214 */ |
225 */ |
215 String getHeaderValue(URL url, String method) { |
226 String getHeaderValue(URL url, String method) { |
216 return getHeaderValueImpl (url.getFile(), method); |
227 return getHeaderValueImpl(url.getFile(), method); |
|
228 } |
|
229 |
|
230 /** |
|
231 * Reclaculates the request-digest and returns it. |
|
232 * |
|
233 * <P> Used when the requestURI is not the abs_path. The exact |
|
234 * requestURI can be passed as a String. |
|
235 * |
|
236 * @param requestURI |
|
237 * the Request-URI from the HTTP request line |
|
238 * |
|
239 * @param method |
|
240 * the HTTP method |
|
241 * |
|
242 * @return the value of the HTTP header this authentication wants set |
|
243 */ |
|
244 String getHeaderValue(String requestURI, String method) { |
|
245 return getHeaderValueImpl(requestURI, method); |
217 } |
246 } |
218 |
247 |
219 /** |
248 /** |
220 * Check if the header indicates that the current auth. parameters are stale. |
249 * Check if the header indicates that the current auth. parameters are stale. |
221 * If so, then replace the relevant field with the new value |
250 * If so, then replace the relevant field with the new value |
247 boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw) { |
276 boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw) { |
248 params.setNonce (p.findValue("nonce")); |
277 params.setNonce (p.findValue("nonce")); |
249 params.setOpaque (p.findValue("opaque")); |
278 params.setOpaque (p.findValue("opaque")); |
250 params.setQop (p.findValue("qop")); |
279 params.setQop (p.findValue("qop")); |
251 |
280 |
252 String uri = conn.getURL().getFile(); |
281 String uri; |
|
282 String method; |
|
283 if (type == PROXY_AUTHENTICATION && |
|
284 conn.tunnelState() == HttpURLConnection.TunnelState.SETUP) { |
|
285 uri = HttpURLConnection.connectRequestURI(conn.getURL()); |
|
286 method = HTTP_CONNECT; |
|
287 } else { |
|
288 uri = conn.getURL().getFile(); |
|
289 method = conn.getMethod(); |
|
290 } |
253 |
291 |
254 if (params.nonce == null || authMethod == null || pw == null || realm == null) { |
292 if (params.nonce == null || authMethod == null || pw == null || realm == null) { |
255 return false; |
293 return false; |
256 } |
294 } |
257 if (authMethod.length() >= 1) { |
295 if (authMethod.length() >= 1) { |
273 |
311 |
274 if (params.authQop()) { |
312 if (params.authQop()) { |
275 params.setNewCnonce(); |
313 params.setNewCnonce(); |
276 } |
314 } |
277 |
315 |
278 String value = getHeaderValueImpl (uri, conn.getMethod()); |
316 String value = getHeaderValueImpl (uri, method); |
279 if (value != null) { |
317 if (value != null) { |
280 conn.setAuthenticationProperty(getHeaderName(), value); |
318 conn.setAuthenticationProperty(getHeaderName(), value); |
281 return true; |
319 return true; |
282 } else { |
320 } else { |
283 return false; |
321 return false; |