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

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

Issue 2489883007: [net/auth] Discard current handler token generation fails. (Closed)
Patch Set: Missed a few comments in the last round. Created 4 years, 1 month 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
« no previous file with comments | « net/http/http_auth_controller.h ('k') | net/http/http_auth_handler_mock.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) 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 bool needs_auth = HaveAuth() || SelectPreemptiveAuth(net_log); 149 bool needs_auth = HaveAuth() || SelectPreemptiveAuth(net_log);
150 if (!needs_auth) 150 if (!needs_auth)
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::OnGenerateAuthTokenDone,
160 base::Unretained(this)),
160 &auth_token_); 161 &auth_token_);
161 162
162 if (rv == ERR_IO_PENDING) { 163 if (rv == ERR_IO_PENDING) {
163 callback_ = callback; 164 callback_ = callback;
164 return rv; 165 return rv;
165 } 166 }
166 167
167 return HandleGenerateTokenResult(rv); 168 return HandleGenerateTokenResult(rv);
168 } 169 }
169 170
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 int HttpAuthController::HandleGenerateTokenResult(int result) { 475 int HttpAuthController::HandleGenerateTokenResult(int result) {
475 DCHECK(CalledOnValidThread()); 476 DCHECK(CalledOnValidThread());
476 switch (result) { 477 switch (result) {
477 case ERR_INVALID_AUTH_CREDENTIALS: 478 case ERR_INVALID_AUTH_CREDENTIALS:
478 // If the GenerateAuthToken call fails with this error, this means that 479 // If the GenerateAuthToken call fails with this error, this means that
479 // the handler can no longer be used. However, the authentication scheme 480 // the handler can no longer be used. However, the authentication scheme
480 // is considered still usable. This allows a scheme that attempted and 481 // is considered still usable. This allows a scheme that attempted and
481 // failed to use default credentials to recover and use explicit 482 // failed to use default credentials to recover and use explicit
482 // credentials. 483 // credentials.
483 // 484 //
484 // If the handler does not support any remaining identity sources, then 485 // The current handler may be tied to external state that is no longer
485 // the authentication controller will pick another authentication handler. 486 // valid, hence should be discarded. Since the scheme is still valid, a
487 // new handler can be created for the current scheme.
488 InvalidateCurrentHandler(INVALIDATE_HANDLER_AND_CACHED_CREDENTIALS);
486 auth_token_.clear(); 489 auth_token_.clear();
487 return OK; 490 return OK;
488 491
489 // Occurs with GSSAPI, if the user has not already logged in. 492 // Occurs with GSSAPI, if the user has not already logged in.
490 case ERR_MISSING_AUTH_CREDENTIALS: 493 case ERR_MISSING_AUTH_CREDENTIALS:
491 494
492 // Can occur with GSSAPI or SSPI if the underlying library reports 495 // Can occur with GSSAPI or SSPI if the underlying library reports
493 // a permanent error. 496 // a permanent error.
494 case ERR_UNSUPPORTED_AUTH_SCHEME: 497 case ERR_UNSUPPORTED_AUTH_SCHEME:
495 498
496 // These two error codes represent failures we aren't handling. 499 // These two error codes represent failures we aren't handling.
497 case ERR_UNEXPECTED_SECURITY_LIBRARY_STATUS: 500 case ERR_UNEXPECTED_SECURITY_LIBRARY_STATUS:
498 case ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS: 501 case ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS:
499 502
500 // Can be returned by SSPI if the authenticating authority or 503 // Can be returned by SSPI if the authenticating authority or
501 // target is not known. 504 // target is not known.
502 case ERR_MISCONFIGURED_AUTH_ENVIRONMENT: 505 case ERR_MISCONFIGURED_AUTH_ENVIRONMENT:
503 506
504 // In these cases, disable the current scheme as it cannot 507 // In these cases, disable the current scheme as it cannot
505 // succeed. 508 // succeed.
506 DisableAuthScheme(handler_->auth_scheme()); 509 InvalidateCurrentHandler(INVALIDATE_HANDLER_AND_DISABLE_SCHEME);
507 auth_token_.clear(); 510 auth_token_.clear();
508 return OK; 511 return OK;
509 512
510 default: 513 default:
511 return result; 514 return result;
512 } 515 }
513 } 516 }
514 517
515 void HttpAuthController::OnIOComplete(int result) { 518 void HttpAuthController::OnGenerateAuthTokenDone(int result) {
516 DCHECK(CalledOnValidThread()); 519 DCHECK(CalledOnValidThread());
517 result = HandleGenerateTokenResult(result); 520 result = HandleGenerateTokenResult(result);
518 if (!callback_.is_null()) { 521 if (!callback_.is_null()) {
519 CompletionCallback c = callback_; 522 CompletionCallback c = callback_;
520 callback_.Reset(); 523 callback_.Reset();
521 c.Run(result); 524 c.Run(result);
522 } 525 }
523 } 526 }
524 527
525 scoped_refptr<AuthChallengeInfo> HttpAuthController::auth_info() { 528 scoped_refptr<AuthChallengeInfo> HttpAuthController::auth_info() {
(...skipping 10 matching lines...) Expand all
536 DCHECK(CalledOnValidThread()); 539 DCHECK(CalledOnValidThread());
537 disabled_schemes_.insert(scheme); 540 disabled_schemes_.insert(scheme);
538 } 541 }
539 542
540 void HttpAuthController::DisableEmbeddedIdentity() { 543 void HttpAuthController::DisableEmbeddedIdentity() {
541 DCHECK(CalledOnValidThread()); 544 DCHECK(CalledOnValidThread());
542 embedded_identity_used_ = true; 545 embedded_identity_used_ = true;
543 } 546 }
544 547
545 } // namespace net 548 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_controller.h ('k') | net/http/http_auth_handler_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698