| Index: chrome/browser/chromeos/login/supervised_user_manager_impl.cc
|
| diff --git a/chrome/browser/chromeos/login/supervised_user_manager_impl.cc b/chrome/browser/chromeos/login/supervised_user_manager_impl.cc
|
| index 8b5bf98ebd037942ef19ebe12086f51dd63822df..73a161f5359031186afa616085ea2fd38bc51bcc 100644
|
| --- a/chrome/browser/chromeos/login/supervised_user_manager_impl.cc
|
| +++ b/chrome/browser/chromeos/login/supervised_user_manager_impl.cc
|
| @@ -12,6 +12,7 @@
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/values.h"
|
| #include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h"
|
| #include "chrome/browser/chromeos/login/user_manager_impl.h"
|
| #include "chromeos/settings/cros_settings_names.h"
|
| #include "content/public/browser/browser_thread.h"
|
| @@ -21,6 +22,7 @@ using content::BrowserThread;
|
|
|
| namespace {
|
|
|
| +// Names for pref keys in Local State.
|
| // A map from locally managed user local user id to sync user id.
|
| const char kManagedUserSyncId[] =
|
| "ManagedUserSyncId";
|
| @@ -53,10 +55,28 @@ const char kLocallyManagedUserCreationTransactionDisplayName[] =
|
| const char kLocallyManagedUserCreationTransactionUserId[] =
|
| "LocallyManagedUserCreationTransactionUserId";
|
|
|
| +// A map from user id to password schema id.
|
| +const char kSupervisedUserPasswordSchema[] =
|
| + "SupervisedUserPasswordSchema";
|
| +
|
| +// A map from user id to password salt.
|
| +const char kSupervisedUserPasswordSalt[] =
|
| + "SupervisedUserPasswordSalt";
|
| +
|
| +// A map from user id to password revision.
|
| +const char kSupervisedUserPasswordRevision[] =
|
| + "SupervisedUserPasswordRevision";
|
| +
|
| } // namespace
|
|
|
| namespace chromeos {
|
|
|
| +const char kSchemaVersion[] = "SchemaVersion";
|
| +const char kPasswordRevision[] = "PasswordRevision";
|
| +const char kSalt[] = "PasswordSalt";
|
| +const char kEncryptedPassword[] = "EncryptedPassword";
|
| +const int kMinPasswordRevision = 1;
|
| +
|
| // static
|
| void SupervisedUserManager::RegisterPrefs(PrefRegistrySimple* registry) {
|
| registry->RegisterListPref(kLocallyManagedUsersFirstRun);
|
| @@ -69,6 +89,10 @@ void SupervisedUserManager::RegisterPrefs(PrefRegistrySimple* registry) {
|
| registry->RegisterDictionaryPref(kManagedUserManagers);
|
| registry->RegisterDictionaryPref(kManagedUserManagerNames);
|
| registry->RegisterDictionaryPref(kManagedUserManagerDisplayEmails);
|
| +
|
| + registry->RegisterDictionaryPref(kSupervisedUserPasswordSchema);
|
| + registry->RegisterDictionaryPref(kSupervisedUserPasswordSalt);
|
| + registry->RegisterDictionaryPref(kSupervisedUserPasswordRevision);
|
| }
|
|
|
| SupervisedUserManagerImpl::SupervisedUserManagerImpl(UserManagerImpl* owner)
|
| @@ -76,6 +100,7 @@ SupervisedUserManagerImpl::SupervisedUserManagerImpl(UserManagerImpl* owner)
|
| cros_settings_(CrosSettings::Get()) {
|
| // SupervisedUserManager instance should be used only on UI thread.
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + authentication_.reset(new SupervisedUserAuthentication(this));
|
| }
|
|
|
| SupervisedUserManagerImpl::~SupervisedUserManagerImpl() {
|
| @@ -150,11 +175,8 @@ const User* SupervisedUserManagerImpl::CreateUserRecord(
|
|
|
| std::string SupervisedUserManagerImpl::GetUserSyncId(const std::string& user_id)
|
| const {
|
| - PrefService* local_state = g_browser_process->local_state();
|
| - const DictionaryValue* sync_ids =
|
| - local_state->GetDictionary(kManagedUserSyncId);
|
| std::string result;
|
| - sync_ids->GetStringWithoutPathExpansion(user_id, &result);
|
| + GetUserStringValue(user_id, kManagedUserSyncId, &result);
|
| return result;
|
| }
|
|
|
| @@ -172,27 +194,85 @@ base::string16 SupervisedUserManagerImpl::GetManagerDisplayName(
|
|
|
| std::string SupervisedUserManagerImpl::GetManagerUserId(
|
| const std::string& user_id) const {
|
| - PrefService* local_state = g_browser_process->local_state();
|
| - const DictionaryValue* manager_ids =
|
| - local_state->GetDictionary(kManagedUserManagers);
|
| std::string result;
|
| - manager_ids->GetStringWithoutPathExpansion(user_id, &result);
|
| + GetUserStringValue(user_id, kManagedUserManagers, &result);
|
| return result;
|
| }
|
|
|
| std::string SupervisedUserManagerImpl::GetManagerDisplayEmail(
|
| const std::string& user_id) const {
|
| - PrefService* local_state = g_browser_process->local_state();
|
| - const DictionaryValue* manager_mails =
|
| - local_state->GetDictionary(kManagedUserManagerDisplayEmails);
|
| std::string result;
|
| - if (manager_mails->GetStringWithoutPathExpansion(user_id, &result) &&
|
| - !result.empty()) {
|
| + if (GetUserStringValue(user_id, kManagedUserManagerDisplayEmails, &result) &&
|
| + !result.empty())
|
| return result;
|
| - }
|
| return GetManagerUserId(user_id);
|
| }
|
|
|
| +void SupervisedUserManagerImpl::GetPasswordInformation(
|
| + const std::string& user_id,
|
| + base::DictionaryValue* result) {
|
| + int value;
|
| + if (GetUserIntegerValue(user_id, kSupervisedUserPasswordSchema, &value))
|
| + result->SetIntegerWithoutPathExpansion(kSchemaVersion, value);
|
| + if (GetUserIntegerValue(user_id, kSupervisedUserPasswordRevision, &value))
|
| + result->SetIntegerWithoutPathExpansion(kPasswordRevision, value);
|
| +
|
| + std::string salt;
|
| + if (GetUserStringValue(user_id, kSupervisedUserPasswordSalt, &salt))
|
| + result->SetStringWithoutPathExpansion(kSalt, salt);
|
| +}
|
| +
|
| +void SupervisedUserManagerImpl::SetPasswordInformation(
|
| + const std::string& user_id,
|
| + const base::DictionaryValue* password_info) {
|
| + int value;
|
| + if (password_info->GetIntegerWithoutPathExpansion(kSchemaVersion, &value))
|
| + SetUserIntegerValue(user_id, kSupervisedUserPasswordSchema, value);
|
| + if (password_info->GetIntegerWithoutPathExpansion(kPasswordRevision, &value))
|
| + SetUserIntegerValue(user_id, kSupervisedUserPasswordRevision, value);
|
| +
|
| + std::string salt;
|
| + if (password_info->GetStringWithoutPathExpansion(kSalt, &salt))
|
| + SetUserStringValue(user_id, kSupervisedUserPasswordSalt, salt);
|
| + g_browser_process->local_state()->CommitPendingWrite();
|
| +}
|
| +
|
| +bool SupervisedUserManagerImpl::GetUserStringValue(
|
| + const std::string& user_id,
|
| + const char* key,
|
| + std::string* out_value) const {
|
| + PrefService* local_state = g_browser_process->local_state();
|
| + const DictionaryValue* dictionary = local_state->GetDictionary(key);
|
| + return dictionary->GetStringWithoutPathExpansion(user_id, out_value);
|
| +}
|
| +
|
| +bool SupervisedUserManagerImpl::GetUserIntegerValue(
|
| + const std::string& user_id,
|
| + const char* key,
|
| + int* out_value) const {
|
| + PrefService* local_state = g_browser_process->local_state();
|
| + const DictionaryValue* dictionary = local_state->GetDictionary(key);
|
| + return dictionary->GetIntegerWithoutPathExpansion(user_id, out_value);
|
| +}
|
| +
|
| +void SupervisedUserManagerImpl::SetUserStringValue(
|
| + const std::string& user_id,
|
| + const char* key,
|
| + const std::string& value) {
|
| + PrefService* local_state = g_browser_process->local_state();
|
| + DictionaryPrefUpdate update(local_state, key);
|
| + update->SetStringWithoutPathExpansion(user_id, value);
|
| +}
|
| +
|
| +void SupervisedUserManagerImpl::SetUserIntegerValue(
|
| + const std::string& user_id,
|
| + const char* key,
|
| + const int value) {
|
| + PrefService* local_state = g_browser_process->local_state();
|
| + DictionaryPrefUpdate update(local_state, key);
|
| + update->SetIntegerWithoutPathExpansion(user_id, value);
|
| +}
|
| +
|
| const User* SupervisedUserManagerImpl::FindByDisplayName(
|
| const base::string16& display_name) const {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| @@ -289,19 +369,20 @@ void SupervisedUserManagerImpl::RemoveNonCryptohomeData(
|
| ListPrefUpdate prefs_new_users_update(prefs, kLocallyManagedUsersFirstRun);
|
| prefs_new_users_update->Remove(base::StringValue(user_id), NULL);
|
|
|
| - DictionaryPrefUpdate synd_id_update(prefs, kManagedUserSyncId);
|
| - synd_id_update->RemoveWithoutPathExpansion(user_id, NULL);
|
| -
|
| - DictionaryPrefUpdate managers_update(prefs, kManagedUserManagers);
|
| - managers_update->RemoveWithoutPathExpansion(user_id, NULL);
|
| -
|
| - DictionaryPrefUpdate manager_names_update(prefs,
|
| - kManagedUserManagerNames);
|
| - manager_names_update->RemoveWithoutPathExpansion(user_id, NULL);
|
| + CleanPref(user_id, kManagedUserSyncId);
|
| + CleanPref(user_id, kManagedUserManagers);
|
| + CleanPref(user_id, kManagedUserManagerNames);
|
| + CleanPref(user_id, kManagedUserManagerDisplayEmails);
|
| + CleanPref(user_id, kSupervisedUserPasswordSalt);
|
| + CleanPref(user_id, kSupervisedUserPasswordSchema);
|
| + CleanPref(user_id, kSupervisedUserPasswordRevision);
|
| +}
|
|
|
| - DictionaryPrefUpdate manager_emails_update(prefs,
|
| - kManagedUserManagerDisplayEmails);
|
| - manager_emails_update->RemoveWithoutPathExpansion(user_id, NULL);
|
| +void SupervisedUserManagerImpl::CleanPref(const std::string& user_id,
|
| + const char* key) {
|
| + PrefService* prefs = g_browser_process->local_state();
|
| + DictionaryPrefUpdate dict_update(prefs, key);
|
| + dict_update->RemoveWithoutPathExpansion(user_id, NULL);
|
| }
|
|
|
| bool SupervisedUserManagerImpl::CheckForFirstRun(const std::string& user_id) {
|
| @@ -332,5 +413,8 @@ void SupervisedUserManagerImpl::UpdateManagerName(const std::string& manager_id,
|
| }
|
| }
|
|
|
| +SupervisedUserAuthentication* SupervisedUserManagerImpl::GetAuthentication() {
|
| + return authentication_.get();
|
| +}
|
|
|
| } // namespace chromeos
|
|
|