Chromium Code Reviews| 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/chromeos/login/supervised_user_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/supervised_user_manager_impl.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_registry_simple.h" | 7 #include "base/prefs/pref_registry_simple.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h " | |
| 15 #include "chrome/browser/chromeos/login/user_manager_impl.h" | 16 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
| 16 #include "chromeos/settings/cros_settings_names.h" | 17 #include "chromeos/settings/cros_settings_names.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "google_apis/gaia/gaia_auth_util.h" | 19 #include "google_apis/gaia/gaia_auth_util.h" |
| 19 | 20 |
| 20 using content::BrowserThread; | 21 using content::BrowserThread; |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 25 // Names for pref keys in Local State. | |
| 24 // A map from locally managed user local user id to sync user id. | 26 // A map from locally managed user local user id to sync user id. |
| 25 const char kManagedUserSyncId[] = | 27 const char kManagedUserSyncId[] = |
| 26 "ManagedUserSyncId"; | 28 "ManagedUserSyncId"; |
| 27 | 29 |
| 28 // A map from locally managed user id to manager user id. | 30 // A map from locally managed user id to manager user id. |
| 29 const char kManagedUserManagers[] = | 31 const char kManagedUserManagers[] = |
| 30 "ManagedUserManagers"; | 32 "ManagedUserManagers"; |
| 31 | 33 |
| 32 // A map from locally managed user id to manager display name. | 34 // A map from locally managed user id to manager display name. |
| 33 const char kManagedUserManagerNames[] = | 35 const char kManagedUserManagerNames[] = |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 46 "LocallyManagedUsersNextId"; | 48 "LocallyManagedUsersNextId"; |
| 47 | 49 |
| 48 // A pref of the next id for locally managed users generation. | 50 // A pref of the next id for locally managed users generation. |
| 49 const char kLocallyManagedUserCreationTransactionDisplayName[] = | 51 const char kLocallyManagedUserCreationTransactionDisplayName[] = |
| 50 "LocallyManagedUserCreationTransactionDisplayName"; | 52 "LocallyManagedUserCreationTransactionDisplayName"; |
| 51 | 53 |
| 52 // A pref of the next id for locally managed users generation. | 54 // A pref of the next id for locally managed users generation. |
| 53 const char kLocallyManagedUserCreationTransactionUserId[] = | 55 const char kLocallyManagedUserCreationTransactionUserId[] = |
| 54 "LocallyManagedUserCreationTransactionUserId"; | 56 "LocallyManagedUserCreationTransactionUserId"; |
| 55 | 57 |
| 58 // A map from user id to password schema id. | |
| 59 const char kSupervisedUserPasswordSchema[] = | |
| 60 "SupervisedUserPasswordSchema"; | |
| 61 | |
| 62 // A map from user id to password salt. | |
| 63 const char kSupervisedUserPasswordSalt[] = | |
| 64 "SupervisedUserPasswordSalt"; | |
| 65 | |
| 66 // A map from user id to password revision. | |
| 67 const char kSupervisedUserPasswordRevision[] = | |
| 68 "SupervisedUserPasswordRevision"; | |
| 69 | |
| 56 } // namespace | 70 } // namespace |
| 57 | 71 |
| 58 namespace chromeos { | 72 namespace chromeos { |
| 59 | 73 |
| 74 // | |
|
Nikita (slow)
2013/12/19 14:53:03
nit: Comment is missing?
Denis Kuznetsov (DE-MUC)
2013/12/19 16:22:17
Done.
| |
| 75 const char kSchemaVersion[] = "SchemaVersion"; | |
| 76 const char kPasswordRevision[] = "PasswordRevision"; | |
| 77 const char kSalt[] = "PasswordSalt"; | |
| 78 const char kEncryptedPassword[] = "EncryptedPassword"; | |
| 79 const int kMinPasswordRevision = 1; | |
| 80 | |
| 60 // static | 81 // static |
| 61 void SupervisedUserManager::RegisterPrefs(PrefRegistrySimple* registry) { | 82 void SupervisedUserManager::RegisterPrefs(PrefRegistrySimple* registry) { |
| 62 registry->RegisterListPref(kLocallyManagedUsersFirstRun); | 83 registry->RegisterListPref(kLocallyManagedUsersFirstRun); |
| 63 registry->RegisterIntegerPref(kLocallyManagedUsersNextId, 0); | 84 registry->RegisterIntegerPref(kLocallyManagedUsersNextId, 0); |
| 64 registry->RegisterStringPref( | 85 registry->RegisterStringPref( |
| 65 kLocallyManagedUserCreationTransactionDisplayName, ""); | 86 kLocallyManagedUserCreationTransactionDisplayName, ""); |
| 66 registry->RegisterStringPref( | 87 registry->RegisterStringPref( |
| 67 kLocallyManagedUserCreationTransactionUserId, ""); | 88 kLocallyManagedUserCreationTransactionUserId, ""); |
| 68 registry->RegisterDictionaryPref(kManagedUserSyncId); | 89 registry->RegisterDictionaryPref(kManagedUserSyncId); |
| 69 registry->RegisterDictionaryPref(kManagedUserManagers); | 90 registry->RegisterDictionaryPref(kManagedUserManagers); |
| 70 registry->RegisterDictionaryPref(kManagedUserManagerNames); | 91 registry->RegisterDictionaryPref(kManagedUserManagerNames); |
| 71 registry->RegisterDictionaryPref(kManagedUserManagerDisplayEmails); | 92 registry->RegisterDictionaryPref(kManagedUserManagerDisplayEmails); |
| 93 | |
| 94 registry->RegisterDictionaryPref(kSupervisedUserPasswordSchema); | |
| 95 registry->RegisterDictionaryPref(kSupervisedUserPasswordSalt); | |
| 96 registry->RegisterDictionaryPref(kSupervisedUserPasswordRevision); | |
| 72 } | 97 } |
| 73 | 98 |
| 74 SupervisedUserManagerImpl::SupervisedUserManagerImpl(UserManagerImpl* owner) | 99 SupervisedUserManagerImpl::SupervisedUserManagerImpl(UserManagerImpl* owner) |
| 75 : owner_(owner), | 100 : owner_(owner), |
| 76 cros_settings_(CrosSettings::Get()) { | 101 cros_settings_(CrosSettings::Get()) { |
| 77 // SupervisedUserManager instance should be used only on UI thread. | 102 // SupervisedUserManager instance should be used only on UI thread. |
| 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 104 authentication_.reset(new SupervisedUserAuthentication(this)); | |
| 79 } | 105 } |
| 80 | 106 |
| 81 SupervisedUserManagerImpl::~SupervisedUserManagerImpl() { | 107 SupervisedUserManagerImpl::~SupervisedUserManagerImpl() { |
| 82 } | 108 } |
| 83 | 109 |
| 84 std::string SupervisedUserManagerImpl::GenerateUserId() { | 110 std::string SupervisedUserManagerImpl::GenerateUserId() { |
| 85 int counter = g_browser_process->local_state()-> | 111 int counter = g_browser_process->local_state()-> |
| 86 GetInteger(kLocallyManagedUsersNextId); | 112 GetInteger(kLocallyManagedUsersNextId); |
| 87 std::string id; | 113 std::string id; |
| 88 bool user_exists; | 114 bool user_exists; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 new base::StringValue(manager->display_email())); | 169 new base::StringValue(manager->display_email())); |
| 144 | 170 |
| 145 owner_->SaveUserDisplayName(local_user_id, display_name); | 171 owner_->SaveUserDisplayName(local_user_id, display_name); |
| 146 | 172 |
| 147 g_browser_process->local_state()->CommitPendingWrite(); | 173 g_browser_process->local_state()->CommitPendingWrite(); |
| 148 return new_user; | 174 return new_user; |
| 149 } | 175 } |
| 150 | 176 |
| 151 std::string SupervisedUserManagerImpl::GetUserSyncId(const std::string& user_id) | 177 std::string SupervisedUserManagerImpl::GetUserSyncId(const std::string& user_id) |
| 152 const { | 178 const { |
| 153 PrefService* local_state = g_browser_process->local_state(); | |
| 154 const DictionaryValue* sync_ids = | |
| 155 local_state->GetDictionary(kManagedUserSyncId); | |
| 156 std::string result; | 179 std::string result; |
| 157 sync_ids->GetStringWithoutPathExpansion(user_id, &result); | 180 GetUserValue(user_id, kManagedUserSyncId, &result); |
| 158 return result; | 181 return result; |
| 159 } | 182 } |
| 160 | 183 |
| 161 string16 SupervisedUserManagerImpl::GetManagerDisplayName( | 184 string16 SupervisedUserManagerImpl::GetManagerDisplayName( |
| 162 const std::string& user_id) const { | 185 const std::string& user_id) const { |
| 163 PrefService* local_state = g_browser_process->local_state(); | 186 PrefService* local_state = g_browser_process->local_state(); |
| 164 const DictionaryValue* manager_names = | 187 const DictionaryValue* manager_names = |
| 165 local_state->GetDictionary(kManagedUserManagerNames); | 188 local_state->GetDictionary(kManagedUserManagerNames); |
| 166 base::string16 result; | 189 base::string16 result; |
| 167 if (manager_names->GetStringWithoutPathExpansion(user_id, &result) && | 190 if (manager_names->GetStringWithoutPathExpansion(user_id, &result) && |
| 168 !result.empty()) | 191 !result.empty()) |
| 169 return result; | 192 return result; |
| 170 return UTF8ToUTF16(GetManagerDisplayEmail(user_id)); | 193 return UTF8ToUTF16(GetManagerDisplayEmail(user_id)); |
| 171 } | 194 } |
| 172 | 195 |
| 173 std::string SupervisedUserManagerImpl::GetManagerUserId( | 196 std::string SupervisedUserManagerImpl::GetManagerUserId( |
| 174 const std::string& user_id) const { | 197 const std::string& user_id) const { |
| 175 PrefService* local_state = g_browser_process->local_state(); | |
| 176 const DictionaryValue* manager_ids = | |
| 177 local_state->GetDictionary(kManagedUserManagers); | |
| 178 std::string result; | 198 std::string result; |
| 179 manager_ids->GetStringWithoutPathExpansion(user_id, &result); | 199 GetUserValue(user_id, kManagedUserManagers, &result); |
| 180 return result; | 200 return result; |
| 181 } | 201 } |
| 182 | 202 |
| 183 std::string SupervisedUserManagerImpl::GetManagerDisplayEmail( | 203 std::string SupervisedUserManagerImpl::GetManagerDisplayEmail( |
| 184 const std::string& user_id) const { | 204 const std::string& user_id) const { |
| 205 std::string result; | |
| 206 if (GetUserValue(user_id, kManagedUserManagerDisplayEmails, &result) && | |
| 207 !result.empty()) | |
| 208 return result; | |
| 209 return GetManagerUserId(user_id); | |
| 210 } | |
| 211 | |
| 212 void SupervisedUserManagerImpl::GetPasswordInformation( | |
| 213 const std::string& user_id, | |
| 214 base::DictionaryValue* result) { | |
| 215 std::string holder; | |
| 216 if (GetUserValue(user_id, kSupervisedUserPasswordSchema, &holder)) | |
| 217 result->SetStringWithoutPathExpansion(kSchemaVersion, holder); | |
| 218 if (GetUserValue(user_id, kSupervisedUserPasswordRevision, &holder)) | |
| 219 result->SetStringWithoutPathExpansion(kPasswordRevision, holder); | |
| 220 if (GetUserValue(user_id, kSupervisedUserPasswordSalt, &holder)) | |
| 221 result->SetStringWithoutPathExpansion(kSalt, holder); | |
| 222 } | |
| 223 | |
| 224 void SupervisedUserManagerImpl::SetPasswordInformation( | |
| 225 const std::string& user_id, | |
| 226 const base::DictionaryValue* password_info) { | |
| 227 std::string holder; | |
| 228 if (password_info->GetStringWithoutPathExpansion(kSchemaVersion, &holder)) | |
| 229 SetUserValue(user_id, kSupervisedUserPasswordSchema, holder); | |
| 230 if (password_info->GetStringWithoutPathExpansion(kPasswordRevision, &holder)) | |
| 231 SetUserValue(user_id, kSupervisedUserPasswordRevision, holder); | |
| 232 if (password_info->GetStringWithoutPathExpansion(kSalt, &holder)) | |
| 233 SetUserValue(user_id, kSupervisedUserPasswordSalt, holder); | |
| 234 g_browser_process->local_state()->CommitPendingWrite(); | |
| 235 } | |
| 236 | |
| 237 bool SupervisedUserManagerImpl::GetUserValue( | |
| 238 const std::string& user_id, | |
| 239 const char* key, | |
| 240 std::string* out_value) const { | |
| 185 PrefService* local_state = g_browser_process->local_state(); | 241 PrefService* local_state = g_browser_process->local_state(); |
| 186 const DictionaryValue* manager_mails = | 242 const DictionaryValue* dictionary = local_state->GetDictionary(key); |
| 187 local_state->GetDictionary(kManagedUserManagerDisplayEmails); | 243 return dictionary->GetStringWithoutPathExpansion(user_id, out_value); |
| 188 std::string result; | 244 } |
| 189 if (manager_mails->GetStringWithoutPathExpansion(user_id, &result) && | 245 |
| 190 !result.empty()) { | 246 void SupervisedUserManagerImpl::SetUserValue( |
| 191 return result; | 247 const std::string& user_id, |
| 192 } | 248 const char* key, |
| 193 return GetManagerUserId(user_id); | 249 const std::string& value) { |
| 250 PrefService* local_state = g_browser_process->local_state(); | |
| 251 DictionaryPrefUpdate update(local_state, key); | |
| 252 update->SetStringWithoutPathExpansion(user_id, value); | |
| 194 } | 253 } |
| 195 | 254 |
| 196 const User* SupervisedUserManagerImpl::FindByDisplayName( | 255 const User* SupervisedUserManagerImpl::FindByDisplayName( |
| 197 const base::string16& display_name) const { | 256 const base::string16& display_name) const { |
| 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 199 const UserList& users = owner_->GetUsers(); | 258 const UserList& users = owner_->GetUsers(); |
| 200 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 259 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
| 201 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) && | 260 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) && |
| 202 ((*it)->display_name() == display_name)) { | 261 ((*it)->display_name() == display_name)) { |
| 203 return *it; | 262 return *it; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 prefs->ClearPref(kLocallyManagedUserCreationTransactionUserId); | 341 prefs->ClearPref(kLocallyManagedUserCreationTransactionUserId); |
| 283 prefs->CommitPendingWrite(); | 342 prefs->CommitPendingWrite(); |
| 284 } | 343 } |
| 285 | 344 |
| 286 void SupervisedUserManagerImpl::RemoveNonCryptohomeData( | 345 void SupervisedUserManagerImpl::RemoveNonCryptohomeData( |
| 287 const std::string& user_id) { | 346 const std::string& user_id) { |
| 288 PrefService* prefs = g_browser_process->local_state(); | 347 PrefService* prefs = g_browser_process->local_state(); |
| 289 ListPrefUpdate prefs_new_users_update(prefs, kLocallyManagedUsersFirstRun); | 348 ListPrefUpdate prefs_new_users_update(prefs, kLocallyManagedUsersFirstRun); |
| 290 prefs_new_users_update->Remove(base::StringValue(user_id), NULL); | 349 prefs_new_users_update->Remove(base::StringValue(user_id), NULL); |
| 291 | 350 |
| 292 DictionaryPrefUpdate synd_id_update(prefs, kManagedUserSyncId); | 351 CleanPref(user_id, kManagedUserSyncId); |
| 293 synd_id_update->RemoveWithoutPathExpansion(user_id, NULL); | 352 CleanPref(user_id, kManagedUserManagers); |
| 353 CleanPref(user_id, kManagedUserManagerNames); | |
| 354 CleanPref(user_id, kManagedUserManagerDisplayEmails); | |
| 355 CleanPref(user_id, kSupervisedUserPasswordSalt); | |
| 356 CleanPref(user_id, kSupervisedUserPasswordSchema); | |
| 357 CleanPref(user_id, kSupervisedUserPasswordRevision); | |
| 358 } | |
| 294 | 359 |
| 295 DictionaryPrefUpdate managers_update(prefs, kManagedUserManagers); | 360 void SupervisedUserManagerImpl::CleanPref(const std::string& user_id, |
| 296 managers_update->RemoveWithoutPathExpansion(user_id, NULL); | 361 const char* key) { |
| 297 | 362 PrefService* prefs = g_browser_process->local_state(); |
| 298 DictionaryPrefUpdate manager_names_update(prefs, | 363 DictionaryPrefUpdate dict_update(prefs, key); |
| 299 kManagedUserManagerNames); | 364 dict_update->RemoveWithoutPathExpansion(user_id, NULL); |
| 300 manager_names_update->RemoveWithoutPathExpansion(user_id, NULL); | |
| 301 | |
| 302 DictionaryPrefUpdate manager_emails_update(prefs, | |
| 303 kManagedUserManagerDisplayEmails); | |
| 304 manager_emails_update->RemoveWithoutPathExpansion(user_id, NULL); | |
| 305 } | 365 } |
| 306 | 366 |
| 307 bool SupervisedUserManagerImpl::CheckForFirstRun(const std::string& user_id) { | 367 bool SupervisedUserManagerImpl::CheckForFirstRun(const std::string& user_id) { |
| 308 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(), | 368 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(), |
| 309 kLocallyManagedUsersFirstRun); | 369 kLocallyManagedUsersFirstRun); |
| 310 return prefs_new_users_update->Remove(base::StringValue(user_id), NULL); | 370 return prefs_new_users_update->Remove(base::StringValue(user_id), NULL); |
| 311 } | 371 } |
| 312 | 372 |
| 313 void SupervisedUserManagerImpl::UpdateManagerName(const std::string& manager_id, | 373 void SupervisedUserManagerImpl::UpdateManagerName(const std::string& manager_id, |
| 314 const base::string16& new_display_name) { | 374 const base::string16& new_display_name) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 325 bool has_manager_id = it.value().GetAsString(&user_id); | 385 bool has_manager_id = it.value().GetAsString(&user_id); |
| 326 DCHECK(has_manager_id); | 386 DCHECK(has_manager_id); |
| 327 if (user_id == manager_id) { | 387 if (user_id == manager_id) { |
| 328 manager_name_update->SetWithoutPathExpansion( | 388 manager_name_update->SetWithoutPathExpansion( |
| 329 it.key(), | 389 it.key(), |
| 330 new base::StringValue(new_display_name)); | 390 new base::StringValue(new_display_name)); |
| 331 } | 391 } |
| 332 } | 392 } |
| 333 } | 393 } |
| 334 | 394 |
| 395 SupervisedUserAuthentication* SupervisedUserManagerImpl::GetAuthentication() { | |
| 396 return authentication_.get(); | |
| 397 } | |
| 335 | 398 |
| 336 } // namespace chromeos | 399 } // namespace chromeos |
| OLD | NEW |