| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 auth_token_.clear(); | 244 auth_token_.clear(); |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 | 247 |
| 248 int HttpAuthController::HandleAuthChallenge( | 248 int HttpAuthController::HandleAuthChallenge( |
| 249 scoped_refptr<HttpResponseHeaders> headers, | 249 scoped_refptr<HttpResponseHeaders> headers, |
| 250 bool do_not_send_server_auth, | 250 bool do_not_send_server_auth, |
| 251 bool establishing_tunnel, | 251 bool establishing_tunnel, |
| 252 const BoundNetLog& net_log) { | 252 const BoundNetLog& net_log) { |
| 253 DCHECK(CalledOnValidThread()); | 253 DCHECK(CalledOnValidThread()); |
| 254 DCHECK(headers); | 254 DCHECK(headers.get()); |
| 255 DCHECK(auth_origin_.is_valid()); | 255 DCHECK(auth_origin_.is_valid()); |
| 256 VLOG(1) << "The " << HttpAuth::GetAuthTargetString(target_) << " " | 256 VLOG(1) << "The " << HttpAuth::GetAuthTargetString(target_) << " " |
| 257 << auth_origin_ << " requested auth " | 257 << auth_origin_ << " requested auth " |
| 258 << AuthChallengeLogMessage(headers.get()); | 258 << AuthChallengeLogMessage(headers.get()); |
| 259 | 259 |
| 260 // Give the existing auth handler first try at the authentication headers. | 260 // Give the existing auth handler first try at the authentication headers. |
| 261 // This will also evict the entry in the HttpAuthCache if the previous | 261 // This will also evict the entry in the HttpAuthCache if the previous |
| 262 // challenge appeared to be rejected, or is using a stale nonce in the Digest | 262 // challenge appeared to be rejected, or is using a stale nonce in the Digest |
| 263 // case. | 263 // case. |
| 264 if (HaveAuth()) { | 264 if (HaveAuth()) { |
| 265 std::string challenge_used; | 265 std::string challenge_used; |
| 266 HttpAuth::AuthorizationResult result = HttpAuth::HandleChallengeResponse( | 266 HttpAuth::AuthorizationResult result = |
| 267 handler_.get(), headers, target_, disabled_schemes_, &challenge_used); | 267 HttpAuth::HandleChallengeResponse(handler_.get(), |
| 268 headers.get(), |
| 269 target_, |
| 270 disabled_schemes_, |
| 271 &challenge_used); |
| 268 switch (result) { | 272 switch (result) { |
| 269 case HttpAuth::AUTHORIZATION_RESULT_ACCEPT: | 273 case HttpAuth::AUTHORIZATION_RESULT_ACCEPT: |
| 270 break; | 274 break; |
| 271 case HttpAuth::AUTHORIZATION_RESULT_INVALID: | 275 case HttpAuth::AUTHORIZATION_RESULT_INVALID: |
| 272 InvalidateCurrentHandler(INVALIDATE_HANDLER_AND_CACHED_CREDENTIALS); | 276 InvalidateCurrentHandler(INVALIDATE_HANDLER_AND_CACHED_CREDENTIALS); |
| 273 break; | 277 break; |
| 274 case HttpAuth::AUTHORIZATION_RESULT_REJECT: | 278 case HttpAuth::AUTHORIZATION_RESULT_REJECT: |
| 275 HistogramAuthEvent(handler_.get(), AUTH_EVENT_REJECT); | 279 HistogramAuthEvent(handler_.get(), AUTH_EVENT_REJECT); |
| 276 InvalidateCurrentHandler(INVALIDATE_HANDLER_AND_CACHED_CREDENTIALS); | 280 InvalidateCurrentHandler(INVALIDATE_HANDLER_AND_CACHED_CREDENTIALS); |
| 277 break; | 281 break; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 307 | 311 |
| 308 identity_.invalid = true; | 312 identity_.invalid = true; |
| 309 | 313 |
| 310 bool can_send_auth = (target_ != HttpAuth::AUTH_SERVER || | 314 bool can_send_auth = (target_ != HttpAuth::AUTH_SERVER || |
| 311 !do_not_send_server_auth); | 315 !do_not_send_server_auth); |
| 312 | 316 |
| 313 do { | 317 do { |
| 314 if (!handler_.get() && can_send_auth) { | 318 if (!handler_.get() && can_send_auth) { |
| 315 // Find the best authentication challenge that we support. | 319 // Find the best authentication challenge that we support. |
| 316 HttpAuth::ChooseBestChallenge(http_auth_handler_factory_, | 320 HttpAuth::ChooseBestChallenge(http_auth_handler_factory_, |
| 317 headers, target_, auth_origin_, | 321 headers.get(), |
| 318 disabled_schemes_, net_log, | 322 target_, |
| 323 auth_origin_, |
| 324 disabled_schemes_, |
| 325 net_log, |
| 319 &handler_); | 326 &handler_); |
| 320 if (handler_.get()) | 327 if (handler_.get()) |
| 321 HistogramAuthEvent(handler_.get(), AUTH_EVENT_START); | 328 HistogramAuthEvent(handler_.get(), AUTH_EVENT_START); |
| 322 } | 329 } |
| 323 | 330 |
| 324 if (!handler_.get()) { | 331 if (!handler_.get()) { |
| 325 if (establishing_tunnel) { | 332 if (establishing_tunnel) { |
| 326 LOG(ERROR) << "Can't perform auth to the " | 333 LOG(ERROR) << "Can't perform auth to the " |
| 327 << HttpAuth::GetAuthTargetString(target_) << " " | 334 << HttpAuth::GetAuthTargetString(target_) << " " |
| 328 << auth_origin_ << " when establishing a tunnel" | 335 << auth_origin_ << " when establishing a tunnel" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 DCHECK(CalledOnValidThread()); | 564 DCHECK(CalledOnValidThread()); |
| 558 return disabled_schemes_.find(scheme) != disabled_schemes_.end(); | 565 return disabled_schemes_.find(scheme) != disabled_schemes_.end(); |
| 559 } | 566 } |
| 560 | 567 |
| 561 void HttpAuthController::DisableAuthScheme(HttpAuth::Scheme scheme) { | 568 void HttpAuthController::DisableAuthScheme(HttpAuth::Scheme scheme) { |
| 562 DCHECK(CalledOnValidThread()); | 569 DCHECK(CalledOnValidThread()); |
| 563 disabled_schemes_.insert(scheme); | 570 disabled_schemes_.insert(scheme); |
| 564 } | 571 } |
| 565 | 572 |
| 566 } // namespace net | 573 } // namespace net |
| OLD | NEW |