Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: net/http/http_auth_controller.cc

Issue 6525035: Invalidate credentials if the server rejects them. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplify auth handlers for basic and digest Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/http_auth_controller.h ('k') | net/http/http_auth_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_auth_controller.h" 5 #include "net/http/http_auth_controller.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 263
264 // Give the existing auth handler first try at the authentication headers. 264 // Give the existing auth handler first try at the authentication headers.
265 // This will also evict the entry in the HttpAuthCache if the previous 265 // This will also evict the entry in the HttpAuthCache if the previous
266 // challenge appeared to be rejected, or is using a stale nonce in the Digest 266 // challenge appeared to be rejected, or is using a stale nonce in the Digest
267 // case. 267 // case.
268 if (HaveAuth()) { 268 if (HaveAuth()) {
269 std::string challenge_used; 269 std::string challenge_used;
270 HttpAuth::AuthorizationResult result = HttpAuth::HandleChallengeResponse( 270 HttpAuth::AuthorizationResult result = HttpAuth::HandleChallengeResponse(
271 handler_.get(), headers, target_, disabled_schemes_, &challenge_used); 271 handler_.get(), headers, target_, disabled_schemes_, &challenge_used);
272 switch (result) { 272 switch (result) {
273 case HttpAuth::AUTHORIZATION_RESULT_ACCEPT: 273 case HttpAuth::AUTHORIZATION_RESULT_ACCEPT:
cbentzel 2011/02/16 16:13:05 Would it be cleaner if the new realm was done in H
274 break; 274 break;
275 case HttpAuth::AUTHORIZATION_RESULT_INVALID: 275 case HttpAuth::AUTHORIZATION_RESULT_INVALID:
276 InvalidateCurrentHandler(); 276 InvalidateCurrentHandler(headers.get());
277 break; 277 break;
278 case HttpAuth::AUTHORIZATION_RESULT_REJECT: 278 case HttpAuth::AUTHORIZATION_RESULT_REJECT:
279 HistogramAuthEvent(handler_.get(), AUTH_EVENT_REJECT); 279 HistogramAuthEvent(handler_.get(), AUTH_EVENT_REJECT);
280 InvalidateCurrentHandler(); 280 InvalidateCurrentHandler(headers.get());
281 break; 281 break;
282 case HttpAuth::AUTHORIZATION_RESULT_STALE: 282 case HttpAuth::AUTHORIZATION_RESULT_STALE:
283 if (http_auth_cache_->UpdateStaleChallenge(auth_origin_, 283 if (http_auth_cache_->UpdateStaleChallenge(auth_origin_,
284 handler_->realm(), 284 handler_->realm(),
285 handler_->auth_scheme(), 285 handler_->auth_scheme(),
286 challenge_used)) { 286 challenge_used)) {
287 handler_.reset(); 287 handler_.reset();
288 identity_ = HttpAuth::Identity(); 288 identity_ = HttpAuth::Identity();
289 } else { 289 } else {
290 // It's possible that a server could incorrectly issue a stale 290 // It's possible that a server could incorrectly issue a stale
291 // response when the entry is not in the cache. Just evict the 291 // response when the entry is not in the cache. Just evict the
292 // current value from the cache. 292 // current value from the cache.
293 InvalidateCurrentHandler(); 293 InvalidateCurrentHandler(headers.get());
294 } 294 }
295 break; 295 break;
296 default: 296 default:
297 NOTREACHED(); 297 NOTREACHED();
298 break; 298 break;
299 } 299 }
300 } 300 }
301 301
302 identity_.invalid = true; 302 identity_.invalid = true;
303 303
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 } 396 }
397 397
398 bool HttpAuthController::HaveAuthHandler() const { 398 bool HttpAuthController::HaveAuthHandler() const {
399 return handler_.get() != NULL; 399 return handler_.get() != NULL;
400 } 400 }
401 401
402 bool HttpAuthController::HaveAuth() const { 402 bool HttpAuthController::HaveAuth() const {
403 return handler_.get() && !identity_.invalid; 403 return handler_.get() && !identity_.invalid;
404 } 404 }
405 405
406 void HttpAuthController::InvalidateCurrentHandler() { 406 void HttpAuthController::InvalidateCurrentHandler(
407 const HttpResponseHeaders* headers) {
407 DCHECK(CalledOnValidThread()); 408 DCHECK(CalledOnValidThread());
408 409
409 InvalidateRejectedAuthFromCache(); 410 InvalidateRejectedAuthFromCache(headers);
410 handler_.reset(); 411 handler_.reset();
411 identity_ = HttpAuth::Identity(); 412 identity_ = HttpAuth::Identity();
412 } 413 }
413 414
414 void HttpAuthController::InvalidateRejectedAuthFromCache() { 415 void HttpAuthController::InvalidateRejectedAuthFromCache(
416 const HttpResponseHeaders* headers) {
415 DCHECK(CalledOnValidThread()); 417 DCHECK(CalledOnValidThread());
416 DCHECK(HaveAuth()); 418 DCHECK(HaveAuth());
417 419
418 // TODO(eroman): this short-circuit can be relaxed. If the realm of 420 // TODO(eroman): this short-circuit can be relaxed. If the realm of
419 // the preemptively used auth entry matches the realm of the subsequent 421 // the preemptively used auth entry matches the realm of the subsequent
420 // challenge, then we can invalidate the preemptively used entry. 422 // challenge, then we can invalidate the preemptively used entry.
421 // Otherwise as-is we may send the failed credentials one extra time. 423 // Otherwise as-is we may send the failed credentials one extra time.
422 if (identity_.source == HttpAuth::IDENT_SRC_PATH_LOOKUP) 424 if (identity_.source == HttpAuth::IDENT_SRC_PATH_LOOKUP &&
425 !HttpAuth::ShouldInvalidateRejectedAuth(headers,
426 target_,
427 handler_.get()))
423 return; 428 return;
424 429
425 // Clear the cache entry for the identity we just failed on. 430 // Clear the cache entry for the identity we just failed on.
426 // Note: we require the username/password to match before invalidating 431 // Note: we require the username/password to match before invalidating
427 // since the entry in the cache may be newer than what we used last time. 432 // since the entry in the cache may be newer than what we used last time.
428 http_auth_cache_->Remove(auth_origin_, handler_->realm(), 433 http_auth_cache_->Remove(auth_origin_, handler_->realm(),
429 handler_->auth_scheme(), identity_.username, 434 handler_->auth_scheme(), identity_.username,
430 identity_.password); 435 identity_.password);
431 } 436 }
432 437
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 DCHECK(CalledOnValidThread()); 523 DCHECK(CalledOnValidThread());
519 return disabled_schemes_.find(scheme) != disabled_schemes_.end(); 524 return disabled_schemes_.find(scheme) != disabled_schemes_.end();
520 } 525 }
521 526
522 void HttpAuthController::DisableAuthScheme(HttpAuth::Scheme scheme) { 527 void HttpAuthController::DisableAuthScheme(HttpAuth::Scheme scheme) {
523 DCHECK(CalledOnValidThread()); 528 DCHECK(CalledOnValidThread());
524 disabled_schemes_.insert(scheme); 529 disabled_schemes_.insert(scheme);
525 } 530 }
526 531
527 } // namespace net 532 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_controller.h ('k') | net/http/http_auth_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698