Commit 6112a8f4 authored by antrim@chromium.org's avatar antrim@chromium.org

Make supervised user ChromeOS import aware of new password schema.

R=nkostylev@chromium.org
TBR=bauerb@chromium.org

BUG=282464

Review URL: https://codereview.chromium.org/220913003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261482 0039d316-1c4b-4281-b951-d872f2087c98
parent 2d1d16f1
......@@ -21,6 +21,9 @@
#include "chrome/browser/chromeos/login/user_image.h"
#include "chrome/browser/chromeos/login/user_image_manager.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/managed_mode/managed_user_constants.h"
#include "chrome/browser/managed_mode/managed_user_shared_settings_service.h"
#include "chrome/browser/managed_mode/managed_user_shared_settings_service_factory.h"
#include "chrome/browser/managed_mode/managed_user_sync_service.h"
#include "chrome/browser/managed_mode/managed_user_sync_service_factory.h"
#include "chrome/common/chrome_switches.h"
......@@ -226,11 +229,17 @@ void LocallyManagedUserCreationScreen::ImportManagedUser(
}
base::string16 display_name;
std::string master_key;
std::string signature_key;
std::string encryption_key;
std::string avatar;
bool exists;
int avatar_index = ManagedUserCreationController::kDummyAvatarIndex;
user_info->GetString(ManagedUserSyncService::kName, &display_name);
user_info->GetString(ManagedUserSyncService::kMasterKey, &master_key);
user_info->GetString(ManagedUserSyncService::kPasswordSignatureKey,
&signature_key);
user_info->GetString(ManagedUserSyncService::kPasswordEncryptionKey,
&encryption_key);
user_info->GetString(ManagedUserSyncService::kChromeOsAvatar, &avatar);
user_info->GetBoolean(kUserExists, &exists);
......@@ -248,11 +257,27 @@ void LocallyManagedUserCreationScreen::ImportManagedUser(
ManagedUserSyncService::GetAvatarIndex(avatar, &avatar_index);
controller_->StartImport(display_name,
std::string(),
avatar_index,
user_id,
master_key);
const base::DictionaryValue* password_data = NULL;
ManagedUserSharedSettingsService* shared_settings_service =
ManagedUserSharedSettingsServiceFactory::GetForBrowserContext(
controller_->GetManagerProfile());
const base::Value* value = shared_settings_service->GetValue(
user_id, managed_users::kChromeOSPasswordData);
bool password_right_here = value && value->GetAsDictionary(&password_data) &&
!password_data->empty();
if (password_right_here) {
controller_->StartImport(display_name,
avatar_index,
user_id,
master_key,
password_data,
encryption_key,
signature_key);
} else {
NOTREACHED() << " Oops, no password";
}
}
// TODO(antrim): Code duplication with previous method will be removed once
......@@ -503,8 +528,14 @@ void LocallyManagedUserCreationScreen::OnGetManagedUsers(
ui_copy->SetString(kUserConflict, kUserConflictName);
}
ui_copy->SetString(ManagedUserSyncService::kName, display_name);
// TODO(antrim): For now mark all users as having no password.
ui_copy->SetBoolean(kUserNeedPassword, true);
std::string signature_key;
bool has_password =
local_copy->GetString(ManagedUserSyncService::kPasswordSignatureKey,
&signature_key) &&
!signature_key.empty();
ui_copy->SetBoolean(kUserNeedPassword, !has_password);
ui_copy->SetString("id", it.key());
existing_users_->Set(it.key(), local_copy);
......
......@@ -75,7 +75,21 @@ class ManagedUserCreationController {
const std::string& sync_id,
const std::string& master_key) = 0;
// Configures and initiates importing existing supervised user to this device.
// Existing user is identified by |sync_id|, has |display_name|,
// |avatar_index|. The master key for cryptohome is a |master_key|. The user
// has password specified in |password_data| and
// |encryption_key|/|signature_key| for cryptohome.
virtual void StartImport(const base::string16& display_name,
int avatar_index,
const std::string& sync_id,
const std::string& master_key,
const base::DictionaryValue* password_data,
const std::string& encryption_key,
const std::string& signature_key) = 0;
virtual void SetManagerProfile(Profile* manager_profile) = 0;
virtual Profile* GetManagerProfile() = 0;
virtual void CancelCreation() = 0;
virtual void FinishCreation() = 0;
virtual std::string GetManagedUserId() = 0;
......
......@@ -72,6 +72,10 @@ void ManagedUserCreationControllerNew::SetManagerProfile(
creation_context_->manager_profile = manager_profile;
}
Profile* ManagedUserCreationControllerNew::GetManagerProfile() {
return creation_context_->manager_profile;
}
void ManagedUserCreationControllerNew::StartCreation(
const base::string16& display_name,
const std::string& password,
......@@ -105,7 +109,6 @@ void ManagedUserCreationControllerNew::StartImport(
void ManagedUserCreationControllerNew::StartImport(
const base::string16& display_name,
const std::string& password,
int avatar_index,
const std::string& sync_id,
const std::string& master_key,
......@@ -113,10 +116,10 @@ void ManagedUserCreationControllerNew::StartImport(
const std::string& encryption_key,
const std::string& signature_key) {
DCHECK(creation_context_);
creation_context_->creation_type = USER_IMPORT_OLD;
creation_context_->creation_type = USER_IMPORT_NEW;
creation_context_->display_name = display_name;
creation_context_->password = password;
creation_context_->avatar_index = avatar_index;
creation_context_->sync_user_id = sync_id;
......
......@@ -66,20 +66,21 @@ class ManagedUserCreationControllerNew
const std::string& master_key) OVERRIDE;
// Configures and initiates importing existing supervised user to this device.
// Existing user is identified by |sync_id|, has |display_name|, |password|,
// |avatar_index|. The master key for cryptohome is a |master_key|.
// The user has password specified in |password_data| and |encryption_key|/
// |signature_key| for cryptohome.
// Existing user is identified by |sync_id|, has |display_name|,
// |avatar_index|. The master key for cryptohome is a |master_key|. The user
// has password specified in |password_data| and
// |encryption_key|/|signature_key| for cryptohome.
virtual void StartImport(const base::string16& display_name,
const std::string& password,
int avatar_index,
const std::string& sync_id,
const std::string& master_key,
const base::DictionaryValue* password_data,
const std::string& encryption_key,
const std::string& signature_key);
const std::string& signature_key) OVERRIDE;
virtual void SetManagerProfile(Profile* manager_profile) OVERRIDE;
virtual Profile* GetManagerProfile() OVERRIDE;
virtual void CancelCreation() OVERRIDE;
virtual void FinishCreation() OVERRIDE;
virtual std::string GetManagedUserId() OVERRIDE;
......
......@@ -95,11 +95,26 @@ void ManagedUserCreationControllerOld::StartImport(
StartCreation();
}
void ManagedUserCreationControllerOld::StartImport(
const base::string16& display_name,
int avatar_index,
const std::string& sync_id,
const std::string& master_key,
const base::DictionaryValue* password_data,
const std::string& encryption_key,
const std::string& signature_key) {
NOTREACHED();
}
void ManagedUserCreationControllerOld::SetManagerProfile(
Profile* manager_profile) {
creation_context_->manager_profile = manager_profile;
}
Profile* ManagedUserCreationControllerOld::GetManagerProfile() {
return creation_context_->manager_profile;
}
void ManagedUserCreationControllerOld::StartCreation() {
DCHECK(creation_context_);
VLOG(1) << "Starting supervised user creation";
......
......@@ -58,7 +58,17 @@ class ManagedUserCreationControllerOld
const std::string& sync_id,
const std::string& master_key) OVERRIDE;
// Not implemented in this class.
virtual void StartImport(const base::string16& display_name,
int avatar_index,
const std::string& sync_id,
const std::string& master_key,
const base::DictionaryValue* password_data,
const std::string& encryption_key,
const std::string& signature_key) OVERRIDE;
virtual void SetManagerProfile(Profile* manager_profile) OVERRIDE;
virtual Profile* GetManagerProfile() OVERRIDE;
virtual void CancelCreation() OVERRIDE;
virtual void FinishCreation() OVERRIDE;
......
......@@ -228,6 +228,7 @@ void ManagedUserRegistrationUtilityImpl::Register(
callback_ = callback;
pending_managed_user_id_ = managed_user_id;
bool need_password_update = !info.password_data.empty();
const base::DictionaryValue* dict =
prefs_->GetDictionary(prefs::kManagedUsers);
is_existing_managed_user_ = dict->HasKey(managed_user_id);
......@@ -265,6 +266,7 @@ void ManagedUserRegistrationUtilityImpl::Register(
info.avatar_index);
} else {
// The user already exists and does not need to be updated.
need_password_update = false;
OnManagedUserAcknowledged(managed_user_id);
}
avatar_updated_ =
......@@ -280,7 +282,7 @@ void ManagedUserRegistrationUtilityImpl::Register(
managed_user_shared_settings_service_->SetValue(
pending_managed_user_id_, kAvatarKey,
base::FundamentalValue(info.avatar_index));
if (!info.password_data.empty()) {
if (need_password_update) {
password_update_.reset(new ManagedUserSharedSettingsUpdate(
managed_user_shared_settings_service_,
pending_managed_user_id_,
......
......@@ -39,7 +39,6 @@
#managed-user-creation .button-link {
font-size: small;
padding: 0 20px;
position: absolute;
}
.below-marketing::-webkit-scrollbar {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment