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

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

Issue 2382293004: [net/auth] Don't abort network transaction over non-permanent auth errors. (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
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_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 return OK; 151 return OK;
152 const AuthCredentials* credentials = NULL; 152 const AuthCredentials* credentials = NULL;
153 if (identity_.source != HttpAuth::IDENT_SRC_DEFAULT_CREDENTIALS) 153 if (identity_.source != HttpAuth::IDENT_SRC_DEFAULT_CREDENTIALS)
154 credentials = &identity_.credentials; 154 credentials = &identity_.credentials;
155 DCHECK(auth_token_.empty()); 155 DCHECK(auth_token_.empty());
156 DCHECK(callback_.is_null()); 156 DCHECK(callback_.is_null());
157 int rv = handler_->GenerateAuthToken( 157 int rv = handler_->GenerateAuthToken(
158 credentials, request, 158 credentials, request,
159 base::Bind(&HttpAuthController::OnIOComplete, base::Unretained(this)), 159 base::Bind(&HttpAuthController::OnIOComplete, base::Unretained(this)),
160 &auth_token_); 160 &auth_token_);
161 if (DisableOnAuthHandlerResult(rv)) 161 rv = HandleGenerateTokenResult(rv);
162 rv = OK;
163 if (rv == ERR_IO_PENDING) 162 if (rv == ERR_IO_PENDING)
164 callback_ = callback; 163 callback_ = callback;
165 else 164 else
166 OnIOComplete(rv); 165 OnIOComplete(rv);
mmenke 2016/10/04 19:42:14 OnIOComplete calls HandleGenerateTokenResult itsel
asanka 2016/10/06 14:16:35 Thanks for catching this. I moved things around so
167 return rv; 166 return rv;
168 } 167 }
169 168
170 bool HttpAuthController::SelectPreemptiveAuth(const NetLogWithSource& net_log) { 169 bool HttpAuthController::SelectPreemptiveAuth(const NetLogWithSource& net_log) {
171 DCHECK(CalledOnValidThread()); 170 DCHECK(CalledOnValidThread());
172 DCHECK(!HaveAuth()); 171 DCHECK(!HaveAuth());
173 DCHECK(identity_.invalid); 172 DCHECK(identity_.invalid);
174 173
175 // Don't do preemptive authorization if the URL contains a username:password, 174 // Don't do preemptive authorization if the URL contains a username:password,
176 // since we must first be challenged in order to use the URL's identity. 175 // since we must first be challenged in order to use the URL's identity.
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 // Populates response_.auth_challenge with the authentication challenge info. 463 // Populates response_.auth_challenge with the authentication challenge info.
465 // This info is consumed by URLRequestHttpJob::GetAuthChallengeInfo(). 464 // This info is consumed by URLRequestHttpJob::GetAuthChallengeInfo().
466 465
467 auth_info_ = new AuthChallengeInfo; 466 auth_info_ = new AuthChallengeInfo;
468 auth_info_->is_proxy = (target_ == HttpAuth::AUTH_PROXY); 467 auth_info_->is_proxy = (target_ == HttpAuth::AUTH_PROXY);
469 auth_info_->challenger = url::Origin(auth_origin_); 468 auth_info_->challenger = url::Origin(auth_origin_);
470 auth_info_->scheme = HttpAuth::SchemeToString(handler_->auth_scheme()); 469 auth_info_->scheme = HttpAuth::SchemeToString(handler_->auth_scheme());
471 auth_info_->realm = handler_->realm(); 470 auth_info_->realm = handler_->realm();
472 } 471 }
473 472
474 bool HttpAuthController::DisableOnAuthHandlerResult(int result) { 473 int HttpAuthController::HandleGenerateTokenResult(int result) {
475 DCHECK(CalledOnValidThread()); 474 DCHECK(CalledOnValidThread());
475 switch (result) {
476 case ERR_INVALID_AUTH_CREDENTIALS:
477 // If the GenerateAuthToken call fails with this error, this means that
478 // the handler can no longer be used. However, the authentication scheme
479 // is considered still usable. This allows a scheme that attempted and
480 // failed to use default credentials to recover and use explicit
481 // credentials.
482 //
483 // If the handler does not support any remaining identity sources, then
484 // the authentication controller will pick another authentication handler.
485 auth_token_.clear();
486 return OK;
mmenke 2016/10/04 19:42:14 So this makes us send a new request, without a tok
asanka 2016/10/06 14:16:35 Either an error displayed to the user, or dependin
476 487
477 switch (result) {
478 // Occurs with GSSAPI, if the user has not already logged in. 488 // Occurs with GSSAPI, if the user has not already logged in.
479 case ERR_MISSING_AUTH_CREDENTIALS: 489 case ERR_MISSING_AUTH_CREDENTIALS:
mmenke 2016/10/04 19:42:14 We get ERR_INVALID_AUTH_CREDENTIALS instead of ERR
asanka 2016/10/06 14:16:35 Initially we ask the system whether we can initiat
480 490
481 // Can occur with GSSAPI or SSPI if the underlying library reports 491 // Can occur with GSSAPI or SSPI if the underlying library reports
482 // a permanent error. 492 // a permanent error.
483 case ERR_UNSUPPORTED_AUTH_SCHEME: 493 case ERR_UNSUPPORTED_AUTH_SCHEME:
484 494
485 // These two error codes represent failures we aren't handling. 495 // These two error codes represent failures we aren't handling.
486 case ERR_UNEXPECTED_SECURITY_LIBRARY_STATUS: 496 case ERR_UNEXPECTED_SECURITY_LIBRARY_STATUS:
487 case ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS: 497 case ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS:
488 498
489 // Can be returned by SSPI if the authenticating authority or 499 // Can be returned by SSPI if the authenticating authority or
490 // target is not known. 500 // target is not known.
491 case ERR_MISCONFIGURED_AUTH_ENVIRONMENT: 501 case ERR_MISCONFIGURED_AUTH_ENVIRONMENT:
492 502
493 // In these cases, disable the current scheme as it cannot 503 // In these cases, disable the current scheme as it cannot
494 // succeed. 504 // succeed.
495 DisableAuthScheme(handler_->auth_scheme()); 505 DisableAuthScheme(handler_->auth_scheme());
496 auth_token_.clear(); 506 auth_token_.clear();
497 return true; 507 return OK;
498 508
499 default: 509 default:
500 return false; 510 return result;
501 } 511 }
502 } 512 }
503 513
504 void HttpAuthController::OnIOComplete(int result) { 514 void HttpAuthController::OnIOComplete(int result) {
505 DCHECK(CalledOnValidThread()); 515 DCHECK(CalledOnValidThread());
506 if (DisableOnAuthHandlerResult(result)) 516 result = HandleGenerateTokenResult(result);
507 result = OK;
508 if (!callback_.is_null()) { 517 if (!callback_.is_null()) {
509 CompletionCallback c = callback_; 518 CompletionCallback c = callback_;
510 callback_.Reset(); 519 callback_.Reset();
511 c.Run(result); 520 c.Run(result);
512 } 521 }
513 } 522 }
514 523
515 scoped_refptr<AuthChallengeInfo> HttpAuthController::auth_info() { 524 scoped_refptr<AuthChallengeInfo> HttpAuthController::auth_info() {
516 DCHECK(CalledOnValidThread()); 525 DCHECK(CalledOnValidThread());
517 return auth_info_; 526 return auth_info_;
518 } 527 }
519 528
520 bool HttpAuthController::IsAuthSchemeDisabled(HttpAuth::Scheme scheme) const { 529 bool HttpAuthController::IsAuthSchemeDisabled(HttpAuth::Scheme scheme) const {
521 DCHECK(CalledOnValidThread()); 530 DCHECK(CalledOnValidThread());
522 return disabled_schemes_.find(scheme) != disabled_schemes_.end(); 531 return disabled_schemes_.find(scheme) != disabled_schemes_.end();
523 } 532 }
524 533
525 void HttpAuthController::DisableAuthScheme(HttpAuth::Scheme scheme) { 534 void HttpAuthController::DisableAuthScheme(HttpAuth::Scheme scheme) {
526 DCHECK(CalledOnValidThread()); 535 DCHECK(CalledOnValidThread());
527 disabled_schemes_.insert(scheme); 536 disabled_schemes_.insert(scheme);
528 } 537 }
529 538
530 void HttpAuthController::DisableEmbeddedIdentity() { 539 void HttpAuthController::DisableEmbeddedIdentity() {
531 DCHECK(CalledOnValidThread()); 540 DCHECK(CalledOnValidThread());
532 embedded_identity_used_ = true; 541 embedded_identity_used_ = true;
533 } 542 }
534 543
535 } // namespace net 544 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698