OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/supervised_user/chromeos/manager_password_service.h" | 5 #include "chrome/browser/supervised_user/chromeos/manager_password_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/chromeos/login/supervised/supervised_user_authenticatio
n.h" | 11 #include "chrome/browser/chromeos/login/supervised/supervised_user_authenticatio
n.h" |
12 #include "chrome/browser/chromeos/login/supervised/supervised_user_constants.h" | 12 #include "chrome/browser/chromeos/login/supervised/supervised_user_constants.h" |
| 13 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
13 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" | 14 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" |
14 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
15 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 15 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
16 #include "chrome/browser/supervised_user/supervised_user_sync_service.h" | 16 #include "chrome/browser/supervised_user/supervised_user_sync_service.h" |
17 #include "chromeos/login/auth/key.h" | 17 #include "chromeos/login/auth/key.h" |
18 #include "chromeos/login/auth/user_context.h" | 18 #include "chromeos/login/auth/user_context.h" |
19 #include "components/user_manager/user.h" | 19 #include "components/user_manager/user.h" |
| 20 #include "components/user_manager/user_manager.h" |
20 #include "components/user_manager/user_type.h" | 21 #include "components/user_manager/user_type.h" |
21 | 22 |
22 namespace chromeos { | 23 namespace chromeos { |
23 | 24 |
24 ManagerPasswordService::ManagerPasswordService() : weak_ptr_factory_(this) {} | 25 ManagerPasswordService::ManagerPasswordService() : weak_ptr_factory_(this) {} |
25 | 26 |
26 ManagerPasswordService::~ManagerPasswordService() {} | 27 ManagerPasswordService::~ManagerPasswordService() {} |
27 | 28 |
28 void ManagerPasswordService::Init( | 29 void ManagerPasswordService::Init( |
29 const std::string& user_id, | 30 const std::string& user_id, |
30 SupervisedUserSyncService* user_service, | 31 SupervisedUserSyncService* user_service, |
31 SupervisedUserSharedSettingsService* shared_settings_service) { | 32 SupervisedUserSharedSettingsService* shared_settings_service) { |
32 user_id_ = user_id; | 33 user_id_ = user_id; |
33 user_service_ = user_service; | 34 user_service_ = user_service; |
34 settings_service_ = shared_settings_service; | 35 settings_service_ = shared_settings_service; |
35 settings_service_subscription_ = settings_service_->Subscribe( | 36 settings_service_subscription_ = settings_service_->Subscribe( |
36 base::Bind(&ManagerPasswordService::OnSharedSettingsChange, | 37 base::Bind(&ManagerPasswordService::OnSharedSettingsChange, |
37 weak_ptr_factory_.GetWeakPtr())); | 38 weak_ptr_factory_.GetWeakPtr())); |
38 | 39 |
39 authenticator_ = new ExtendedAuthenticator(this); | 40 authenticator_ = new ExtendedAuthenticator(this); |
40 | 41 |
41 UserManager* user_manager = UserManager::Get(); | 42 SupervisedUserManager* supervised_user_manager = |
| 43 ChromeUserManager::Get()->GetSupervisedUserManager(); |
42 | 44 |
43 SupervisedUserManager* supervised_user_manager = | 45 const user_manager::UserList& users = |
44 user_manager->GetSupervisedUserManager(); | 46 user_manager::UserManager::Get()->GetUsers(); |
45 | |
46 const user_manager::UserList& users = user_manager->GetUsers(); | |
47 | 47 |
48 for (user_manager::UserList::const_iterator it = users.begin(); | 48 for (user_manager::UserList::const_iterator it = users.begin(); |
49 it != users.end(); | 49 it != users.end(); |
50 ++it) { | 50 ++it) { |
51 if ((*it)->GetType() != user_manager::USER_TYPE_SUPERVISED) | 51 if ((*it)->GetType() != user_manager::USER_TYPE_SUPERVISED) |
52 continue; | 52 continue; |
53 if (user_id != supervised_user_manager->GetManagerUserId((*it)->email())) | 53 if (user_id != supervised_user_manager->GetManagerUserId((*it)->email())) |
54 continue; | 54 continue; |
55 OnSharedSettingsChange( | 55 OnSharedSettingsChange( |
56 supervised_user_manager->GetUserSyncId((*it)->email()), | 56 supervised_user_manager->GetUserSyncId((*it)->email()), |
57 supervised_users::kChromeOSPasswordData); | 57 supervised_users::kChromeOSPasswordData); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 void ManagerPasswordService::OnSharedSettingsChange( | 61 void ManagerPasswordService::OnSharedSettingsChange( |
62 const std::string& su_id, | 62 const std::string& su_id, |
63 const std::string& key) { | 63 const std::string& key) { |
64 if (key != supervised_users::kChromeOSPasswordData) | 64 if (key != supervised_users::kChromeOSPasswordData) |
65 return; | 65 return; |
66 | 66 |
67 SupervisedUserManager* supervised_user_manager = | 67 SupervisedUserManager* supervised_user_manager = |
68 UserManager::Get()->GetSupervisedUserManager(); | 68 ChromeUserManager::Get()->GetSupervisedUserManager(); |
69 const user_manager::User* user = supervised_user_manager->FindBySyncId(su_id); | 69 const user_manager::User* user = supervised_user_manager->FindBySyncId(su_id); |
70 // No user on device. | 70 // No user on device. |
71 if (user == NULL) | 71 if (user == NULL) |
72 return; | 72 return; |
73 | 73 |
74 const base::Value* value = settings_service_->GetValue(su_id, key); | 74 const base::Value* value = settings_service_->GetValue(su_id, key); |
75 | 75 |
76 if (value == NULL) { | 76 if (value == NULL) { |
77 LOG(WARNING) << "Got empty value from sync."; | 77 LOG(WARNING) << "Got empty value from sync."; |
78 return; | 78 return; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 const UserContext& master_key_context, | 191 const UserContext& master_key_context, |
192 const std::string& user_id, | 192 const std::string& user_id, |
193 scoped_ptr<base::DictionaryValue> password_data) { | 193 scoped_ptr<base::DictionaryValue> password_data) { |
194 VLOG(0) << "Password changed for " << user_id; | 194 VLOG(0) << "Password changed for " << user_id; |
195 UMA_HISTOGRAM_ENUMERATION( | 195 UMA_HISTOGRAM_ENUMERATION( |
196 "ManagedUsers.ChromeOS.PasswordChange", | 196 "ManagedUsers.ChromeOS.PasswordChange", |
197 SupervisedUserAuthentication::PASSWORD_CHANGED_IN_MANAGER_SESSION, | 197 SupervisedUserAuthentication::PASSWORD_CHANGED_IN_MANAGER_SESSION, |
198 SupervisedUserAuthentication::PASSWORD_CHANGE_RESULT_MAX_VALUE); | 198 SupervisedUserAuthentication::PASSWORD_CHANGE_RESULT_MAX_VALUE); |
199 | 199 |
200 SupervisedUserAuthentication* auth = | 200 SupervisedUserAuthentication* auth = |
201 UserManager::Get()->GetSupervisedUserManager()->GetAuthentication(); | 201 ChromeUserManager::Get()->GetSupervisedUserManager()->GetAuthentication(); |
202 int old_schema = auth->GetPasswordSchema(user_id); | 202 int old_schema = auth->GetPasswordSchema(user_id); |
203 auth->StorePasswordData(user_id, *password_data.get()); | 203 auth->StorePasswordData(user_id, *password_data.get()); |
204 | 204 |
205 if (auth->HasIncompleteKey(user_id)) | 205 if (auth->HasIncompleteKey(user_id)) |
206 auth->MarkKeyIncomplete(user_id, false /* key is complete now */); | 206 auth->MarkKeyIncomplete(user_id, false /* key is complete now */); |
207 | 207 |
208 // Check if we have legacy labels for keys. | 208 // Check if we have legacy labels for keys. |
209 // TODO(antrim): Migrate it to GetLabels call once wad@ implement it. | 209 // TODO(antrim): Migrate it to GetLabels call once wad@ implement it. |
210 if (old_schema == SupervisedUserAuthentication::SCHEMA_PLAIN) { | 210 if (old_schema == SupervisedUserAuthentication::SCHEMA_PLAIN) { |
211 // 1) Add new manager key (using old key). | 211 // 1) Add new manager key (using old key). |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 void ManagerPasswordService::OnOldManagerKeyDeleted( | 263 void ManagerPasswordService::OnOldManagerKeyDeleted( |
264 const UserContext& master_key_context) { | 264 const UserContext& master_key_context) { |
265 VLOG(1) << "Removed old master key for " << master_key_context.GetUserID(); | 265 VLOG(1) << "Removed old master key for " << master_key_context.GetUserID(); |
266 } | 266 } |
267 | 267 |
268 void ManagerPasswordService::Shutdown() { | 268 void ManagerPasswordService::Shutdown() { |
269 settings_service_subscription_.reset(); | 269 settings_service_subscription_.reset(); |
270 } | 270 } |
271 | 271 |
272 } // namespace chromeos | 272 } // namespace chromeos |
OLD | NEW |