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