Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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: |
| 274 break; | 274 break; |
| 275 case HttpAuth::AUTHORIZATION_RESULT_INVALID: | 275 case HttpAuth::AUTHORIZATION_RESULT_INVALID: |
| 276 InvalidateCurrentHandler(); | 276 InvalidateCurrentHandler(INVALIDATE_HANDLER_AND_CACHED_CREDENTIALS); |
| 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(INVALIDATE_HANDLER_AND_CACHED_CREDENTIALS); |
| 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 InvalidateCurrentHandler(INVALIDATE_HANDLER); |
| 288 identity_ = HttpAuth::Identity(); | |
| 289 } else { | 288 } else { |
| 290 // It's possible that a server could incorrectly issue a stale | 289 // It's possible that a server could incorrectly issue a stale |
| 291 // response when the entry is not in the cache. Just evict the | 290 // response when the entry is not in the cache. Just evict the |
| 292 // current value from the cache. | 291 // current value from the cache. |
| 293 InvalidateCurrentHandler(); | 292 InvalidateCurrentHandler(INVALIDATE_HANDLER_AND_CACHED_CREDENTIALS); |
| 294 } | 293 } |
| 295 break; | 294 break; |
| 295 case HttpAuth::AUTHORIZATION_RESULT_DIFFERENT_REALM: | |
| 296 // If the server asks for credentials for one realm and then | |
| 297 // rejects them, we remove the credentials from the cache | |
| 298 // unless it was in response to a preemptive authorization | |
| 299 // header. | |
|
wtc
2011/02/22 23:17:32
This comment is confusing because it seems self-co
cbentzel
2011/02/23 14:49:54
It means that the server returns a 401 after we pr
asanka
2011/02/23 18:06:40
I'll clarify the comment.
| |
| 300 InvalidateCurrentHandler( | |
| 301 (identity_.source == HttpAuth::IDENT_SRC_PATH_LOOKUP) ? | |
| 302 INVALIDATE_HANDLER : | |
| 303 INVALIDATE_HANDLER_AND_CACHED_CREDENTIALS); | |
| 304 break; | |
| 296 default: | 305 default: |
| 297 NOTREACHED(); | 306 NOTREACHED(); |
| 298 break; | 307 break; |
| 299 } | 308 } |
| 300 } | 309 } |
| 301 | 310 |
| 302 identity_.invalid = true; | 311 identity_.invalid = true; |
| 303 | 312 |
| 304 bool can_send_auth = (target_ != HttpAuth::AUTH_SERVER || | 313 bool can_send_auth = (target_ != HttpAuth::AUTH_SERVER || |
| 305 !do_not_send_server_auth); | 314 !do_not_send_server_auth); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 } | 405 } |
| 397 | 406 |
| 398 bool HttpAuthController::HaveAuthHandler() const { | 407 bool HttpAuthController::HaveAuthHandler() const { |
| 399 return handler_.get() != NULL; | 408 return handler_.get() != NULL; |
| 400 } | 409 } |
| 401 | 410 |
| 402 bool HttpAuthController::HaveAuth() const { | 411 bool HttpAuthController::HaveAuth() const { |
| 403 return handler_.get() && !identity_.invalid; | 412 return handler_.get() && !identity_.invalid; |
| 404 } | 413 } |
| 405 | 414 |
| 406 void HttpAuthController::InvalidateCurrentHandler() { | 415 void HttpAuthController::InvalidateCurrentHandler( |
| 416 InvalidateHandlerAction action) { | |
| 407 DCHECK(CalledOnValidThread()); | 417 DCHECK(CalledOnValidThread()); |
| 408 | 418 |
| 409 InvalidateRejectedAuthFromCache(); | 419 if (action == INVALIDATE_HANDLER_AND_CACHED_CREDENTIALS) |
| 420 InvalidateRejectedAuthFromCache(); | |
| 410 handler_.reset(); | 421 handler_.reset(); |
| 411 identity_ = HttpAuth::Identity(); | 422 identity_ = HttpAuth::Identity(); |
| 412 } | 423 } |
| 413 | 424 |
| 414 void HttpAuthController::InvalidateRejectedAuthFromCache() { | 425 void HttpAuthController::InvalidateRejectedAuthFromCache() { |
| 415 DCHECK(CalledOnValidThread()); | 426 DCHECK(CalledOnValidThread()); |
| 416 DCHECK(HaveAuth()); | 427 DCHECK(HaveAuth()); |
| 417 | 428 |
| 418 // TODO(eroman): this short-circuit can be relaxed. If the realm of | |
| 419 // the preemptively used auth entry matches the realm of the subsequent | |
| 420 // challenge, then we can invalidate the preemptively used entry. | |
| 421 // Otherwise as-is we may send the failed credentials one extra time. | |
| 422 if (identity_.source == HttpAuth::IDENT_SRC_PATH_LOOKUP) | |
| 423 return; | |
| 424 | |
| 425 // Clear the cache entry for the identity we just failed on. | 429 // Clear the cache entry for the identity we just failed on. |
| 426 // Note: we require the username/password to match before invalidating | 430 // 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. | 431 // since the entry in the cache may be newer than what we used last time. |
| 428 http_auth_cache_->Remove(auth_origin_, handler_->realm(), | 432 http_auth_cache_->Remove(auth_origin_, handler_->realm(), |
| 429 handler_->auth_scheme(), identity_.username, | 433 handler_->auth_scheme(), identity_.username, |
| 430 identity_.password); | 434 identity_.password); |
| 431 } | 435 } |
| 432 | 436 |
| 433 bool HttpAuthController::SelectNextAuthIdentityToTry() { | 437 bool HttpAuthController::SelectNextAuthIdentityToTry() { |
| 434 DCHECK(CalledOnValidThread()); | 438 DCHECK(CalledOnValidThread()); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 DCHECK(CalledOnValidThread()); | 522 DCHECK(CalledOnValidThread()); |
| 519 return disabled_schemes_.find(scheme) != disabled_schemes_.end(); | 523 return disabled_schemes_.find(scheme) != disabled_schemes_.end(); |
| 520 } | 524 } |
| 521 | 525 |
| 522 void HttpAuthController::DisableAuthScheme(HttpAuth::Scheme scheme) { | 526 void HttpAuthController::DisableAuthScheme(HttpAuth::Scheme scheme) { |
| 523 DCHECK(CalledOnValidThread()); | 527 DCHECK(CalledOnValidThread()); |
| 524 disabled_schemes_.insert(scheme); | 528 disabled_schemes_.insert(scheme); |
| 525 } | 529 } |
| 526 | 530 |
| 527 } // namespace net | 531 } // namespace net |
| OLD | NEW |