226 * headers such as those defined in EXCLUDE_HEADERS.
227 */
228 private MessageHeader requests;
229
230 /* The following two fields are only used with Digest Authentication */
231 String domain; /* The list of authentication domains */
232 DigestAuthentication.Parameters digestparams;
233
234 /* Current credentials in use */
235 AuthenticationInfo currentProxyCredentials = null;
236 AuthenticationInfo currentServerCredentials = null;
237 boolean needToCheck = true;
238 private boolean doingNTLM2ndStage = false; /* doing the 2nd stage of an NTLM server authentication */
239 private boolean doingNTLMp2ndStage = false; /* doing the 2nd stage of an NTLM proxy authentication */
240
241 /* try auth without calling Authenticator. Used for transparent NTLM authentication */
242 private boolean tryTransparentNTLMServer = true;
243 private boolean tryTransparentNTLMProxy = true;
244
245 /* Used by Windows specific code */
246 Object authObj;
247
248 /* Set if the user is manually setting the Authorization or Proxy-Authorization headers */
249 boolean isUserServerAuth;
250 boolean isUserProxyAuth;
251
252 /* Progress source */
253 protected ProgressSource pi;
254
255 /* all the response headers we get back */
256 private MessageHeader responses;
257 /* the stream _from_ the server */
258 private InputStream inputStream = null;
259 /* post stream _to_ the server, if any */
260 private PosterOutputStream poster = null;
261
262 /* Indicates if the std. request headers have been set in requests. */
263 private boolean setRequests=false;
264
265 /* Indicates whether a request has already failed or not */
266 private boolean failedOnce=false;
315 public PasswordAuthentication run() {
316 if (logger.isLoggable(PlatformLogger.FINEST)) {
317 logger.finest("Requesting Authentication: host =" + host + " url = " + url);
318 }
319 PasswordAuthentication pass = Authenticator.requestPasswordAuthentication(
320 host, addr, port, protocol,
321 prompt, scheme, url, authType);
322 if (logger.isLoggable(PlatformLogger.FINEST)) {
323 logger.finest("Authentication returned: " + (pass != null ? pass.toString() : "null"));
324 }
325 return pass;
326 }
327 });
328 }
329
330 /* Logging support */
331 public static PlatformLogger getHttpLogger() {
332 return logger;
333 }
334
335 /*
336 * checks the validity of http message header and throws
337 * IllegalArgumentException if invalid.
338 */
339 private void checkMessageHeader(String key, String value) {
340 char LF = '\n';
341 int index = key.indexOf(LF);
342 if (index != -1) {
343 throw new IllegalArgumentException(
344 "Illegal character(s) in message header field: " + key);
345 }
346 else {
347 if (value == null) {
348 return;
349 }
350
351 index = value.indexOf(LF);
352 while (index != -1) {
353 index++;
354 if (index < value.length()) {
2512 * (e.g., "<code>accept</code>").
2513 * @param value the value associated with it.
2514 * @see #getRequestProperties(java.lang.String)
2515 * @since 1.4
2516 */
2517 @Override
2518 public void addRequestProperty(String key, String value) {
2519 if (connected)
2520 throw new IllegalStateException("Already connected");
2521 if (key == null)
2522 throw new NullPointerException ("key is null");
2523
2524 checkMessageHeader(key, value);
2525 requests.add(key, value);
2526 }
2527
2528 //
2529 // Set a property for authentication. This can safely disregard
2530 // the connected test.
2531 //
2532 void setAuthenticationProperty(String key, String value) {
2533 checkMessageHeader(key, value);
2534 requests.set(key, value);
2535 }
2536
2537 @Override
2538 public String getRequestProperty (String key) {
2539 // don't return headers containing security sensitive information
2540 if (key != null) {
2541 for (int i=0; i < EXCLUDE_HEADERS.length; i++) {
2542 if (key.equalsIgnoreCase(EXCLUDE_HEADERS[i])) {
2543 return null;
2544 }
2545 }
2546 }
2547 return requests.findValue(key);
2548 }
2549
2550 /**
2551 * Returns an unmodifiable Map of general request
2552 * properties for this connection. The Map keys
|
226 * headers such as those defined in EXCLUDE_HEADERS.
227 */
228 private MessageHeader requests;
229
230 /* The following two fields are only used with Digest Authentication */
231 String domain; /* The list of authentication domains */
232 DigestAuthentication.Parameters digestparams;
233
234 /* Current credentials in use */
235 AuthenticationInfo currentProxyCredentials = null;
236 AuthenticationInfo currentServerCredentials = null;
237 boolean needToCheck = true;
238 private boolean doingNTLM2ndStage = false; /* doing the 2nd stage of an NTLM server authentication */
239 private boolean doingNTLMp2ndStage = false; /* doing the 2nd stage of an NTLM proxy authentication */
240
241 /* try auth without calling Authenticator. Used for transparent NTLM authentication */
242 private boolean tryTransparentNTLMServer = true;
243 private boolean tryTransparentNTLMProxy = true;
244
245 /* Used by Windows specific code */
246 private Object authObj;
247
248 /* Set if the user is manually setting the Authorization or Proxy-Authorization headers */
249 boolean isUserServerAuth;
250 boolean isUserProxyAuth;
251
252 /* Progress source */
253 protected ProgressSource pi;
254
255 /* all the response headers we get back */
256 private MessageHeader responses;
257 /* the stream _from_ the server */
258 private InputStream inputStream = null;
259 /* post stream _to_ the server, if any */
260 private PosterOutputStream poster = null;
261
262 /* Indicates if the std. request headers have been set in requests. */
263 private boolean setRequests=false;
264
265 /* Indicates whether a request has already failed or not */
266 private boolean failedOnce=false;
315 public PasswordAuthentication run() {
316 if (logger.isLoggable(PlatformLogger.FINEST)) {
317 logger.finest("Requesting Authentication: host =" + host + " url = " + url);
318 }
319 PasswordAuthentication pass = Authenticator.requestPasswordAuthentication(
320 host, addr, port, protocol,
321 prompt, scheme, url, authType);
322 if (logger.isLoggable(PlatformLogger.FINEST)) {
323 logger.finest("Authentication returned: " + (pass != null ? pass.toString() : "null"));
324 }
325 return pass;
326 }
327 });
328 }
329
330 /* Logging support */
331 public static PlatformLogger getHttpLogger() {
332 return logger;
333 }
334
335 /* Used for Windows NTLM implementation */
336 public Object authObj() {
337 return authObj;
338 }
339
340 public void authObj(Object authObj) {
341 this.authObj = authObj;
342 }
343
344 /*
345 * checks the validity of http message header and throws
346 * IllegalArgumentException if invalid.
347 */
348 private void checkMessageHeader(String key, String value) {
349 char LF = '\n';
350 int index = key.indexOf(LF);
351 if (index != -1) {
352 throw new IllegalArgumentException(
353 "Illegal character(s) in message header field: " + key);
354 }
355 else {
356 if (value == null) {
357 return;
358 }
359
360 index = value.indexOf(LF);
361 while (index != -1) {
362 index++;
363 if (index < value.length()) {
2521 * (e.g., "<code>accept</code>").
2522 * @param value the value associated with it.
2523 * @see #getRequestProperties(java.lang.String)
2524 * @since 1.4
2525 */
2526 @Override
2527 public void addRequestProperty(String key, String value) {
2528 if (connected)
2529 throw new IllegalStateException("Already connected");
2530 if (key == null)
2531 throw new NullPointerException ("key is null");
2532
2533 checkMessageHeader(key, value);
2534 requests.add(key, value);
2535 }
2536
2537 //
2538 // Set a property for authentication. This can safely disregard
2539 // the connected test.
2540 //
2541 public void setAuthenticationProperty(String key, String value) {
2542 checkMessageHeader(key, value);
2543 requests.set(key, value);
2544 }
2545
2546 @Override
2547 public String getRequestProperty (String key) {
2548 // don't return headers containing security sensitive information
2549 if (key != null) {
2550 for (int i=0; i < EXCLUDE_HEADERS.length; i++) {
2551 if (key.equalsIgnoreCase(EXCLUDE_HEADERS[i])) {
2552 return null;
2553 }
2554 }
2555 }
2556 return requests.findValue(key);
2557 }
2558
2559 /**
2560 * Returns an unmodifiable Map of general request
2561 * properties for this connection. The Map keys
|