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

Unified Diff: components/user_manager/known_user.cc

Issue 2529103002: Add account_type into AccountId (Closed)
Patch Set: Fix MultiUserWindowManagerChromeOSTest.* Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/user_manager/known_user.h ('k') | components/user_manager/user_manager_base.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/user_manager/known_user.cc
diff --git a/components/user_manager/known_user.cc b/components/user_manager/known_user.cc
index 8ad90614b9f3444673b46fb8a9fdb69ee8a2a7a8..815d105e187f75d648fc1543cf7d0e0a184a6a7d 100644
--- a/components/user_manager/known_user.cc
+++ b/components/user_manager/known_user.cc
@@ -32,6 +32,12 @@ const char kCanonicalEmail[] = "email";
// Key of obfuscated GAIA id value.
const char kGAIAIdKey[] = "gaia_id";
+// Key of obfuscated object guid value for Active Directory accounts.
+const char kObjGuidKey[] = "obj_guid";
+
+// Key of account type.
+const char kAccountTypeKey[] = "account_type";
+
// Key of whether this user ID refers to a SAML user.
const char kUsingSAMLKey[] = "using_saml";
@@ -58,11 +64,29 @@ PrefService* GetLocalState() {
bool UserMatches(const AccountId& account_id,
const base::DictionaryValue& dict) {
std::string value;
+ if (account_id.GetAccountType() != AccountType::UNKNOWN &&
+ dict.GetString(kAccountTypeKey, &value) &&
+ account_id.GetAccountType() != AccountId::StringToAccountType(value)) {
+ return false;
+ }
// TODO(alemate): update code once user id is really a struct.
- bool has_gaia_id = dict.GetString(kGAIAIdKey, &value);
- if (has_gaia_id && account_id.GetGaiaId() == value)
- return true;
+ switch (account_id.GetAccountType()) {
+ case AccountType::GOOGLE: {
+ bool has_gaia_id = dict.GetString(kGAIAIdKey, &value);
+ if (has_gaia_id && account_id.GetGaiaId() == value)
+ return true;
+ break;
+ }
+ case AccountType::ACTIVE_DIRECTORY: {
+ bool has_obj_guid = dict.GetString(kObjGuidKey, &value);
+ if (has_obj_guid && account_id.GetObjGuid() == value)
+ return true;
+ break;
+ }
+ case AccountType::UNKNOWN: {
+ }
+ }
bool has_email = dict.GetString(kCanonicalEmail, &value);
if (has_email && account_id.GetUserEmail() == value)
@@ -76,8 +100,20 @@ void UpdateIdentity(const AccountId& account_id, base::DictionaryValue& dict) {
if (!account_id.GetUserEmail().empty())
dict.SetString(kCanonicalEmail, account_id.GetUserEmail());
- if (!account_id.GetGaiaId().empty())
- dict.SetString(kGAIAIdKey, account_id.GetGaiaId());
+ switch (account_id.GetAccountType()) {
+ case AccountType::GOOGLE:
+ if (!account_id.GetGaiaId().empty())
+ dict.SetString(kGAIAIdKey, account_id.GetGaiaId());
+ break;
+ case AccountType::ACTIVE_DIRECTORY:
+ if (!account_id.GetObjGuid().empty())
+ dict.SetString(kObjGuidKey, account_id.GetObjGuid());
+ break;
+ case AccountType::UNKNOWN:
+ return;
+ }
+ dict.SetString(kAccountTypeKey,
+ AccountId::AccountTypeToString(account_id.GetAccountType()));
}
} // namespace
@@ -216,48 +252,76 @@ void SetIntegerPref(const AccountId& account_id,
}
AccountId GetAccountId(const std::string& user_email,
- const std::string& gaia_id) {
+ const std::string& id,
+ const AccountType& account_type) {
+ DCHECK((id.empty() && account_type == AccountType::UNKNOWN) ||
+ (!id.empty() && account_type != AccountType::UNKNOWN));
// In tests empty accounts are possible.
- if (user_email.empty() && gaia_id.empty())
+ if (user_email.empty() && id.empty() &&
+ account_type == AccountType::UNKNOWN) {
return EmptyAccountId();
+ }
AccountId result(EmptyAccountId());
// UserManager is usually NULL in unit tests.
- if (UserManager::IsInitialized() &&
- UserManager::Get()->GetPlatformKnownUserId(user_email, gaia_id,
- &result)) {
+ if (account_type == AccountType::UNKNOWN && UserManager::IsInitialized() &&
+ UserManager::Get()->GetPlatformKnownUserId(user_email, id, &result)) {
return result;
}
- // We can have several users with the same gaia_id but different e-mails.
- // The opposite case is not possible.
std::string stored_gaia_id;
+ std::string stored_obj_guid;
const std::string sanitized_email =
user_email.empty()
? std::string()
: gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_email));
- if (!sanitized_email.empty() &&
- GetStringPref(AccountId::FromUserEmail(sanitized_email), kGAIAIdKey,
- &stored_gaia_id)) {
- if (!gaia_id.empty() && gaia_id != stored_gaia_id)
- LOG(ERROR) << "User gaia id has changed. Sync will not work.";
+ if (!sanitized_email.empty()) {
+ if (GetStringPref(AccountId::FromUserEmail(sanitized_email), kGAIAIdKey,
+ &stored_gaia_id)) {
+ if (!id.empty()) {
+ DCHECK(account_type == AccountType::GOOGLE);
+ if (id != stored_gaia_id)
+ LOG(ERROR) << "User gaia id has changed. Sync will not work.";
+ }
+
+ // gaia_id is associated with cryptohome.
+ return AccountId::FromUserEmailGaiaId(sanitized_email, stored_gaia_id);
+ }
- // gaia_id is associated with cryptohome.
- return AccountId::FromUserEmailGaiaId(sanitized_email, stored_gaia_id);
+ if (GetStringPref(AccountId::FromUserEmail(sanitized_email), kObjGuidKey,
+ &stored_obj_guid)) {
+ if (!id.empty()) {
+ DCHECK(account_type == AccountType::ACTIVE_DIRECTORY);
+ if (id != stored_obj_guid)
+ LOG(ERROR) << "User object guid has changed. Sync will not work.";
+ }
+
+ // obj_guid is associated with cryptohome.
+ return AccountId::AdFromUserEmailObjGuid(sanitized_email,
+ stored_obj_guid);
+ }
}
std::string stored_email;
- // GetStringPref() returns the first user record that matches
- // given ID. So we will get the first one if there are multiples.
- if (!gaia_id.empty() && GetStringPref(AccountId::FromGaiaId(gaia_id),
- kCanonicalEmail, &stored_email)) {
- return AccountId::FromUserEmailGaiaId(stored_email, gaia_id);
+ switch (account_type) {
+ case AccountType::GOOGLE:
+ if (GetStringPref(AccountId::FromGaiaId(id), kCanonicalEmail,
+ &stored_email)) {
+ return AccountId::FromUserEmailGaiaId(stored_email, id);
+ }
+ return AccountId::FromUserEmailGaiaId(sanitized_email, id);
+ case AccountType::ACTIVE_DIRECTORY:
+ if (GetStringPref(AccountId::AdFromObjGuid(id), kCanonicalEmail,
+ &stored_email)) {
+ return AccountId::AdFromUserEmailObjGuid(stored_email, id);
+ }
+ return AccountId::AdFromUserEmailObjGuid(sanitized_email, id);
+ case AccountType::UNKNOWN:
+ return AccountId::FromUserEmail(sanitized_email);
}
-
- return (gaia_id.empty()
- ? AccountId::FromUserEmail(user_email)
- : AccountId::FromUserEmailGaiaId(user_email, gaia_id));
+ NOTREACHED();
+ return EmptyAccountId();
}
std::vector<AccountId> GetKnownAccountIds() {
@@ -274,10 +338,30 @@ std::vector<AccountId> GetKnownAccountIds() {
if (known_users->GetDictionary(i, &element)) {
std::string email;
std::string gaia_id;
+ std::string obj_guid;
const bool has_email = element->GetString(kCanonicalEmail, &email);
const bool has_gaia_id = element->GetString(kGAIAIdKey, &gaia_id);
- if (has_email || has_gaia_id)
- result.push_back(AccountId::FromUserEmailGaiaId(email, gaia_id));
+ const bool has_obj_guid = element->GetString(kObjGuidKey, &obj_guid);
+ AccountType account_type = AccountType::GOOGLE;
+ std::string account_type_string;
+ if (element->GetString(kAccountTypeKey, &account_type_string)) {
+ account_type = AccountId::StringToAccountType(account_type_string);
+ }
+ switch (account_type) {
+ case AccountType::GOOGLE:
+ if (has_email || has_gaia_id) {
+ result.push_back(AccountId::FromUserEmailGaiaId(email, gaia_id));
+ }
+ break;
+ case AccountType::ACTIVE_DIRECTORY:
+ if (has_email && has_obj_guid) {
+ result.push_back(
+ AccountId::AdFromUserEmailObjGuid(email, obj_guid));
+ }
+ break;
+ default:
+ NOTREACHED() << "Unknown account type";
+ }
}
}
return result;
@@ -304,6 +388,23 @@ void SetGaiaIdMigrationStatusDone(const AccountId& account_id,
void UpdateGaiaID(const AccountId& account_id, const std::string& gaia_id) {
SetStringPref(account_id, kGAIAIdKey, gaia_id);
+ SetStringPref(account_id, kAccountTypeKey,
+ AccountId::AccountTypeToString(AccountType::GOOGLE));
+}
+
+void UpdateId(const AccountId& account_id) {
+ switch (account_id.GetAccountType()) {
+ case AccountType::GOOGLE:
+ SetStringPref(account_id, kGAIAIdKey, account_id.GetGaiaId());
+ break;
+ case AccountType::ACTIVE_DIRECTORY:
+ SetStringPref(account_id, kObjGuidKey, account_id.GetObjGuid());
+ break;
+ case AccountType::UNKNOWN:
+ return;
+ }
+ SetStringPref(account_id, kAccountTypeKey,
+ AccountId::AccountTypeToString(account_id.GetAccountType()));
}
bool FindGaiaID(const AccountId& account_id, std::string* out_value) {
« no previous file with comments | « components/user_manager/known_user.h ('k') | components/user_manager/user_manager_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698