OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h" |
6 | 6 |
7 #include "ash/system/chromeos/devicetype_utils.h" | 7 #include "ash/system/chromeos/devicetype_utils.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 else | 429 else |
430 frame_error_ = net::ERR_INTERNET_DISCONNECTED; | 430 frame_error_ = net::ERR_INTERNET_DISCONNECTED; |
431 | 431 |
432 LOG(ERROR) << "Gaia webview error: " << error_reason_str; | 432 LOG(ERROR) << "Gaia webview error: " << error_reason_str; |
433 NetworkError::ErrorReason error_reason = | 433 NetworkError::ErrorReason error_reason = |
434 NetworkError::ERROR_REASON_FRAME_ERROR; | 434 NetworkError::ERROR_REASON_FRAME_ERROR; |
435 frame_state_ = FRAME_STATE_ERROR; | 435 frame_state_ = FRAME_STATE_ERROR; |
436 UpdateState(error_reason); | 436 UpdateState(error_reason); |
437 } | 437 } |
438 | 438 |
439 std::string GaiaScreenHandler::GetCanonicalEmail( | 439 AccountId GaiaScreenHandler::GetAccountId( |
440 const std::string& authenticated_email, | 440 const std::string& authenticated_email, |
441 const std::string& gaia_id) const { | 441 const std::string& gaia_id) const { |
442 const std::string sanitized_email = gaia::SanitizeEmail(authenticated_email); | 442 const std::string canonicalized_email = |
| 443 gaia::CanonicalizeEmail(gaia::SanitizeEmail(authenticated_email)); |
| 444 const AccountId authenticated_account_id( |
| 445 AccountId::FromUserEmailGaiaId(canonicalized_email, gaia_id)); |
443 | 446 |
444 const std::string canonicalized_email = | 447 // If we don't have UserManager instance (i.e. we are in unit test), |
445 gaia::CanonicalizeEmail(sanitized_email); | 448 // or a known user has authenticated, just log in. |
446 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 449 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
447 if (user_manager && !user_manager->IsKnownUser(canonicalized_email)) { | 450 if (!user_manager || user_manager->IsKnownUser(authenticated_account_id)) |
448 std::string old_canonical_email; | 451 return authenticated_account_id; |
449 if (user_manager->GetKnownUserCanonicalEmail(gaia_id, | 452 |
450 &old_canonical_email)) { | 453 // If [part of] user id has changed, update stored data and connect user |
451 if (old_canonical_email != canonicalized_email) { | 454 // to existing home directory. |
452 LOG(WARNING) << "Existing user '" << old_canonical_email | 455 AccountId old_account_id(EmptyAccountId()); |
453 << "' authenticated by alias '" << sanitized_email << "'."; | 456 if (!user_manager->GetKnownUserAccountId(authenticated_account_id, |
454 return old_canonical_email; | 457 &old_account_id)) { |
455 } | 458 return authenticated_account_id; |
456 } | |
457 } | 459 } |
458 // For compatibility reasons, sanitized email is used. | 460 |
459 return sanitized_email; | 461 if (old_account_id.GetUserEmail() != canonicalized_email) { |
| 462 LOG(WARNING) << "Existing user '" << old_account_id.GetUserEmail() |
| 463 << "' authenticated by alias '" << canonicalized_email << "'."; |
| 464 return old_account_id; |
| 465 } |
| 466 |
| 467 return authenticated_account_id; |
460 } | 468 } |
461 | 469 |
462 void GaiaScreenHandler::HandleCompleteAuthentication( | 470 void GaiaScreenHandler::HandleCompleteAuthentication( |
463 const std::string& gaia_id, | 471 const std::string& gaia_id, |
464 const std::string& email, | 472 const std::string& email, |
465 const std::string& password, | 473 const std::string& password, |
466 const std::string& auth_code, | 474 const std::string& auth_code, |
467 bool using_saml, | 475 bool using_saml, |
468 const std::string& gaps_cookie) { | 476 const std::string& gaps_cookie) { |
469 if (!Delegate()) | 477 if (!Delegate()) |
470 return; | 478 return; |
471 | 479 |
472 DCHECK(!email.empty()); | 480 DCHECK(!email.empty()); |
473 DCHECK(!gaia_id.empty()); | 481 DCHECK(!gaia_id.empty()); |
474 const std::string sanitized_email = gaia::SanitizeEmail(email); | 482 const std::string sanitized_email = gaia::SanitizeEmail(email); |
475 Delegate()->SetDisplayEmail(sanitized_email); | 483 Delegate()->SetDisplayEmail(sanitized_email); |
476 | 484 |
477 const std::string canonical_email = GetCanonicalEmail(email, gaia_id); | 485 UserContext user_context(GetAccountId(email, gaia_id)); |
478 UserContext user_context(canonical_email); | |
479 user_context.SetGaiaID(gaia_id); | 486 user_context.SetGaiaID(gaia_id); |
480 user_context.SetKey(Key(password)); | 487 user_context.SetKey(Key(password)); |
481 user_context.SetAuthCode(auth_code); | 488 user_context.SetAuthCode(auth_code); |
482 user_context.SetAuthFlow(using_saml | 489 user_context.SetAuthFlow(using_saml |
483 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML | 490 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML |
484 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 491 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
485 user_context.SetGAPSCookie(gaps_cookie); | 492 user_context.SetGAPSCookie(gaps_cookie); |
486 Delegate()->CompleteLogin(user_context); | 493 Delegate()->CompleteLogin(user_context); |
487 } | 494 } |
488 | 495 |
(...skipping 12 matching lines...) Expand all Loading... |
501 const std::string& typed_email, | 508 const std::string& typed_email, |
502 const std::string& password, | 509 const std::string& password, |
503 bool using_saml) { | 510 bool using_saml) { |
504 if (!is_enrolling_consumer_management_) { | 511 if (!is_enrolling_consumer_management_) { |
505 DoCompleteLogin(gaia_id, typed_email, password, using_saml); | 512 DoCompleteLogin(gaia_id, typed_email, password, using_saml); |
506 return; | 513 return; |
507 } | 514 } |
508 | 515 |
509 // Consumer management enrollment is in progress. | 516 // Consumer management enrollment is in progress. |
510 const std::string owner_email = | 517 const std::string owner_email = |
511 user_manager::UserManager::Get()->GetOwnerEmail(); | 518 user_manager::UserManager::Get()->GetOwnerAccountId().GetUserEmail(); |
512 if (typed_email != owner_email) { | 519 if (typed_email != owner_email) { |
513 // Show Gaia sign-in screen again, since we only allow the owner to sign | 520 // Show Gaia sign-in screen again, since we only allow the owner to sign |
514 // in. | 521 // in. |
515 populated_email_ = owner_email; | 522 populated_email_ = owner_email; |
516 ShowGaiaAsync(is_enrolling_consumer_management_); | 523 ShowGaiaAsync(is_enrolling_consumer_management_); |
517 return; | 524 return; |
518 } | 525 } |
519 | 526 |
520 CHECK(consumer_management_); | 527 CHECK(consumer_management_); |
521 consumer_management_->SetOwner(owner_email, | 528 consumer_management_->SetOwner(owner_email, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 if (!Delegate()) | 595 if (!Delegate()) |
589 return; | 596 return; |
590 | 597 |
591 if (using_saml && !using_saml_api_) | 598 if (using_saml && !using_saml_api_) |
592 RecordSAMLScrapingVerificationResultInHistogram(true); | 599 RecordSAMLScrapingVerificationResultInHistogram(true); |
593 | 600 |
594 DCHECK(!typed_email.empty()); | 601 DCHECK(!typed_email.empty()); |
595 DCHECK(!gaia_id.empty()); | 602 DCHECK(!gaia_id.empty()); |
596 const std::string sanitized_email = gaia::SanitizeEmail(typed_email); | 603 const std::string sanitized_email = gaia::SanitizeEmail(typed_email); |
597 Delegate()->SetDisplayEmail(sanitized_email); | 604 Delegate()->SetDisplayEmail(sanitized_email); |
598 const std::string canonical_email = GetCanonicalEmail(typed_email, gaia_id); | 605 UserContext user_context(GetAccountId(typed_email, gaia_id)); |
599 UserContext user_context(canonical_email); | |
600 user_context.SetGaiaID(gaia_id); | 606 user_context.SetGaiaID(gaia_id); |
601 user_context.SetKey(Key(password)); | 607 user_context.SetKey(Key(password)); |
602 user_context.SetAuthFlow(using_saml | 608 user_context.SetAuthFlow(using_saml |
603 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML | 609 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML |
604 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 610 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
605 Delegate()->CompleteLogin(user_context); | 611 Delegate()->CompleteLogin(user_context); |
606 | 612 |
607 if (test_expects_complete_login_) { | 613 if (test_expects_complete_login_) { |
608 VLOG(2) << "Complete test login for " << typed_email | 614 VLOG(2) << "Complete test login for " << typed_email |
609 << ", requested=" << test_user_; | 615 << ", requested=" << test_user_; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 imm->SetState(gaia_ime_state); | 754 imm->SetState(gaia_ime_state); |
749 | 755 |
750 // Set Least Recently Used input method for the user. | 756 // Set Least Recently Used input method for the user. |
751 if (!populated_email_.empty()) { | 757 if (!populated_email_.empty()) { |
752 SigninScreenHandler::SetUserInputMethod(populated_email_, | 758 SigninScreenHandler::SetUserInputMethod(populated_email_, |
753 gaia_ime_state.get()); | 759 gaia_ime_state.get()); |
754 } else { | 760 } else { |
755 std::vector<std::string> input_methods = | 761 std::vector<std::string> input_methods = |
756 imm->GetInputMethodUtil()->GetHardwareLoginInputMethodIds(); | 762 imm->GetInputMethodUtil()->GetHardwareLoginInputMethodIds(); |
757 const std::string owner_im = SigninScreenHandler::GetUserLRUInputMethod( | 763 const std::string owner_im = SigninScreenHandler::GetUserLRUInputMethod( |
758 user_manager::UserManager::Get()->GetOwnerEmail()); | 764 user_manager::UserManager::Get()->GetOwnerAccountId().GetUserEmail()); |
759 const std::string system_im = g_browser_process->local_state()->GetString( | 765 const std::string system_im = g_browser_process->local_state()->GetString( |
760 language_prefs::kPreferredKeyboardLayout); | 766 language_prefs::kPreferredKeyboardLayout); |
761 | 767 |
762 PushFrontIMIfNotExists(owner_im, &input_methods); | 768 PushFrontIMIfNotExists(owner_im, &input_methods); |
763 PushFrontIMIfNotExists(system_im, &input_methods); | 769 PushFrontIMIfNotExists(system_im, &input_methods); |
764 | 770 |
765 gaia_ime_state->EnableLoginLayouts( | 771 gaia_ime_state->EnableLoginLayouts( |
766 g_browser_process->GetApplicationLocale(), input_methods); | 772 g_browser_process->GetApplicationLocale(), input_methods); |
767 | 773 |
768 if (!system_im.empty()) { | 774 if (!system_im.empty()) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 VLOG(1) << "LoadAuthExtension, force: " << force | 838 VLOG(1) << "LoadAuthExtension, force: " << force |
833 << ", offline: " << offline; | 839 << ", offline: " << offline; |
834 GaiaContext context; | 840 GaiaContext context; |
835 context.force_reload = force; | 841 context.force_reload = force; |
836 context.is_local = offline; | 842 context.is_local = offline; |
837 context.use_offline = offline; | 843 context.use_offline = offline; |
838 context.email = populated_email_; | 844 context.email = populated_email_; |
839 context.is_enrolling_consumer_management = is_enrolling_consumer_management_; | 845 context.is_enrolling_consumer_management = is_enrolling_consumer_management_; |
840 | 846 |
841 std::string gaia_id; | 847 std::string gaia_id; |
842 if (user_manager::UserManager::Get()->FindGaiaID(context.email, &gaia_id)) | 848 if (user_manager::UserManager::Get()->FindGaiaID( |
| 849 AccountId::FromUserEmail(context.email), &gaia_id)) |
843 context.gaia_id = gaia_id; | 850 context.gaia_id = gaia_id; |
844 | 851 |
845 if (Delegate()) { | 852 if (Delegate()) { |
846 context.show_users = Delegate()->IsShowUsers(); | 853 context.show_users = Delegate()->IsShowUsers(); |
847 } | 854 } |
848 | 855 |
849 if (!context.email.empty()) { | 856 if (!context.email.empty()) { |
850 context.gaps_cookie = | 857 context.gaps_cookie = |
851 user_manager::UserManager::Get()->GetKnownUserGAPSCookie( | 858 user_manager::UserManager::Get()->GetKnownUserGAPSCookie( |
852 gaia::CanonicalizeEmail(context.email)); | 859 AccountId::FromUserEmail(gaia::CanonicalizeEmail(context.email))); |
853 } | 860 } |
854 | 861 |
855 populated_email_.clear(); | 862 populated_email_.clear(); |
856 | 863 |
857 LoadGaia(context); | 864 LoadGaia(context); |
858 } | 865 } |
859 | 866 |
860 void GaiaScreenHandler::UpdateState(NetworkError::ErrorReason reason) { | 867 void GaiaScreenHandler::UpdateState(NetworkError::ErrorReason reason) { |
861 if (signin_screen_handler_) | 868 if (signin_screen_handler_) |
862 signin_screen_handler_->UpdateState(reason); | 869 signin_screen_handler_->UpdateState(reason); |
(...skipping 11 matching lines...) Expand all Loading... |
874 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL || | 881 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL || |
875 captive_portal_status_ == | 882 captive_portal_status_ == |
876 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; | 883 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; |
877 } | 884 } |
878 | 885 |
879 void GaiaScreenHandler::DisableRestrictiveProxyCheckForTest() { | 886 void GaiaScreenHandler::DisableRestrictiveProxyCheckForTest() { |
880 disable_restrictive_proxy_check_for_test_ = true; | 887 disable_restrictive_proxy_check_for_test_ = true; |
881 } | 888 } |
882 | 889 |
883 } // namespace chromeos | 890 } // namespace chromeos |
OLD | NEW |