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 |
24 // A map from locally managed user local user id to sync user id. | 25 // A map from locally managed user local user id to sync user id. |
(...skipping 21 matching lines...) Expand all Loading... | |
46 "LocallyManagedUsersNextId"; | 47 "LocallyManagedUsersNextId"; |
47 | 48 |
48 // A pref of the next id for locally managed users generation. | 49 // A pref of the next id for locally managed users generation. |
49 const char kLocallyManagedUserCreationTransactionDisplayName[] = | 50 const char kLocallyManagedUserCreationTransactionDisplayName[] = |
50 "LocallyManagedUserCreationTransactionDisplayName"; | 51 "LocallyManagedUserCreationTransactionDisplayName"; |
51 | 52 |
52 // A pref of the next id for locally managed users generation. | 53 // A pref of the next id for locally managed users generation. |
53 const char kLocallyManagedUserCreationTransactionUserId[] = | 54 const char kLocallyManagedUserCreationTransactionUserId[] = |
54 "LocallyManagedUserCreationTransactionUserId"; | 55 "LocallyManagedUserCreationTransactionUserId"; |
55 | 56 |
57 // A map from user id to password schema version, | |
Nikita (slow)
2013/12/09 16:42:16
nit: revision, dot at the end.
Denis Kuznetsov (DE-MUC)
2013/12/12 19:45:24
Done.
| |
58 const char kSupervisedUserPasswordSchemaVersion[] = | |
59 "SupervisedUserPasswordSchemaVersion"; | |
60 | |
61 // A map from user id to password version. | |
62 const char kSupervisedUserPasswordSalt[] = | |
63 "SupervisedUserPasswordSalt"; | |
64 | |
65 // A map from user id to password salt. | |
66 const char kSupervisedUserPasswordVersion[] = | |
67 "SupervisedUserPasswordVersion"; | |
68 | |
56 } // namespace | 69 } // namespace |
57 | 70 |
58 namespace chromeos { | 71 namespace chromeos { |
59 | 72 |
73 const char kSchemaVersion[] = "SchemaVersion"; | |
Nikita (slow)
2013/12/09 16:42:16
nit: One small comment about these would be helpfu
Denis Kuznetsov (DE-MUC)
2013/12/12 19:45:24
Done.
| |
74 const char kPasswordVersion[] = "PasswordVersion"; | |
75 const char kSalt[] = "PasswordSalt"; | |
76 const char kEncryptedPassword[] = "EncryptedPassword"; | |
77 | |
60 // static | 78 // static |
61 void SupervisedUserManager::RegisterPrefs(PrefRegistrySimple* registry) { | 79 void SupervisedUserManager::RegisterPrefs(PrefRegistrySimple* registry) { |
62 registry->RegisterListPref(kLocallyManagedUsersFirstRun); | 80 registry->RegisterListPref(kLocallyManagedUsersFirstRun); |
63 registry->RegisterIntegerPref(kLocallyManagedUsersNextId, 0); | 81 registry->RegisterIntegerPref(kLocallyManagedUsersNextId, 0); |
64 registry->RegisterStringPref( | 82 registry->RegisterStringPref( |
65 kLocallyManagedUserCreationTransactionDisplayName, ""); | 83 kLocallyManagedUserCreationTransactionDisplayName, ""); |
66 registry->RegisterStringPref( | 84 registry->RegisterStringPref( |
67 kLocallyManagedUserCreationTransactionUserId, ""); | 85 kLocallyManagedUserCreationTransactionUserId, ""); |
68 registry->RegisterDictionaryPref(kManagedUserSyncId); | 86 registry->RegisterDictionaryPref(kManagedUserSyncId); |
69 registry->RegisterDictionaryPref(kManagedUserManagers); | 87 registry->RegisterDictionaryPref(kManagedUserManagers); |
70 registry->RegisterDictionaryPref(kManagedUserManagerNames); | 88 registry->RegisterDictionaryPref(kManagedUserManagerNames); |
71 registry->RegisterDictionaryPref(kManagedUserManagerDisplayEmails); | 89 registry->RegisterDictionaryPref(kManagedUserManagerDisplayEmails); |
90 | |
91 registry->RegisterDictionaryPref(kSupervisedUserPasswordSchemaVersion); | |
92 registry->RegisterDictionaryPref(kSupervisedUserPasswordSalt); | |
93 registry->RegisterDictionaryPref(kSupervisedUserPasswordVersion); | |
72 } | 94 } |
73 | 95 |
74 SupervisedUserManagerImpl::SupervisedUserManagerImpl(UserManagerImpl* owner) | 96 SupervisedUserManagerImpl::SupervisedUserManagerImpl(UserManagerImpl* owner) |
75 : owner_(owner), | 97 : owner_(owner), |
76 cros_settings_(CrosSettings::Get()) { | 98 cros_settings_(CrosSettings::Get()) { |
77 // SupervisedUserManager instance should be used only on UI thread. | 99 // SupervisedUserManager instance should be used only on UI thread. |
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
101 authentication_.reset(new SupervisedUserAuthentication(this)); | |
79 } | 102 } |
80 | 103 |
81 SupervisedUserManagerImpl::~SupervisedUserManagerImpl() { | 104 SupervisedUserManagerImpl::~SupervisedUserManagerImpl() { |
82 } | 105 } |
83 | 106 |
84 std::string SupervisedUserManagerImpl::GenerateUserId() { | 107 std::string SupervisedUserManagerImpl::GenerateUserId() { |
85 int counter = g_browser_process->local_state()-> | 108 int counter = g_browser_process->local_state()-> |
86 GetInteger(kLocallyManagedUsersNextId); | 109 GetInteger(kLocallyManagedUsersNextId); |
87 std::string id; | 110 std::string id; |
88 bool user_exists; | 111 bool user_exists; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 new base::StringValue(manager->display_email())); | 166 new base::StringValue(manager->display_email())); |
144 | 167 |
145 owner_->SaveUserDisplayName(local_user_id, display_name); | 168 owner_->SaveUserDisplayName(local_user_id, display_name); |
146 | 169 |
147 g_browser_process->local_state()->CommitPendingWrite(); | 170 g_browser_process->local_state()->CommitPendingWrite(); |
148 return new_user; | 171 return new_user; |
149 } | 172 } |
150 | 173 |
151 std::string SupervisedUserManagerImpl::GetUserSyncId(const std::string& user_id) | 174 std::string SupervisedUserManagerImpl::GetUserSyncId(const std::string& user_id) |
152 const { | 175 const { |
153 PrefService* local_state = g_browser_process->local_state(); | |
154 const DictionaryValue* sync_ids = | |
155 local_state->GetDictionary(kManagedUserSyncId); | |
156 std::string result; | 176 std::string result; |
157 sync_ids->GetStringWithoutPathExpansion(user_id, &result); | 177 GetUserValue(user_id, kManagedUserSyncId, &result); |
158 return result; | 178 return result; |
159 } | 179 } |
160 | 180 |
161 string16 SupervisedUserManagerImpl::GetManagerDisplayName( | 181 string16 SupervisedUserManagerImpl::GetManagerDisplayName( |
162 const std::string& user_id) const { | 182 const std::string& user_id) const { |
163 PrefService* local_state = g_browser_process->local_state(); | 183 PrefService* local_state = g_browser_process->local_state(); |
164 const DictionaryValue* manager_names = | 184 const DictionaryValue* manager_names = |
165 local_state->GetDictionary(kManagedUserManagerNames); | 185 local_state->GetDictionary(kManagedUserManagerNames); |
166 string16 result; | 186 string16 result; |
167 if (manager_names->GetStringWithoutPathExpansion(user_id, &result) && | 187 if (manager_names->GetStringWithoutPathExpansion(user_id, &result) && |
168 !result.empty()) | 188 !result.empty()) |
169 return result; | 189 return result; |
170 return UTF8ToUTF16(GetManagerDisplayEmail(user_id)); | 190 return UTF8ToUTF16(GetManagerDisplayEmail(user_id)); |
171 } | 191 } |
172 | 192 |
173 std::string SupervisedUserManagerImpl::GetManagerUserId( | 193 std::string SupervisedUserManagerImpl::GetManagerUserId( |
174 const std::string& user_id) const { | 194 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; | 195 std::string result; |
179 manager_ids->GetStringWithoutPathExpansion(user_id, &result); | 196 GetUserValue(user_id, kManagedUserManagers, &result); |
180 return result; | 197 return result; |
181 } | 198 } |
182 | 199 |
183 std::string SupervisedUserManagerImpl::GetManagerDisplayEmail( | 200 std::string SupervisedUserManagerImpl::GetManagerDisplayEmail( |
184 const std::string& user_id) const { | 201 const std::string& user_id) const { |
202 std::string result; | |
203 if (GetUserValue(user_id, kManagedUserManagerDisplayEmails, &result) && | |
204 !result.empty()) | |
205 return result; | |
206 return GetManagerUserId(user_id); | |
207 } | |
208 | |
209 void SupervisedUserManagerImpl::GetPasswordInformation( | |
210 const std::string& user_id, | |
211 base::DictionaryValue* result) { | |
Bernhard Bauer
2013/12/11 14:46:43
You don't really need to pass a dictionary here th
Denis Kuznetsov (DE-MUC)
2013/12/12 19:45:24
I want to keep things simple - same dictionary wil
Bernhard Bauer
2013/12/13 00:30:50
Like I explained above, it won't be the exact same
| |
212 std::string holder; | |
213 if (GetUserValue(user_id, kSupervisedUserPasswordSchemaVersion, &holder)) | |
214 result->SetStringWithoutPathExpansion(kSchemaVersion, holder); | |
215 if (GetUserValue(user_id, kSupervisedUserPasswordVersion, &holder)) | |
216 result->SetStringWithoutPathExpansion(kPasswordVersion, holder); | |
217 if (GetUserValue(user_id, kSupervisedUserPasswordSalt, &holder)) | |
218 result->SetStringWithoutPathExpansion(kSalt, holder); | |
219 } | |
220 | |
221 void SupervisedUserManagerImpl::SetPasswordInformation( | |
222 const std::string& user_id, | |
223 const base::DictionaryValue* password_info) { | |
224 std::string holder; | |
225 if (password_info->GetStringWithoutPathExpansion(kSchemaVersion, &holder)) | |
226 SetUserValue(user_id, kSupervisedUserPasswordSchemaVersion, holder); | |
227 if (password_info->GetStringWithoutPathExpansion(kPasswordVersion, &holder)) | |
228 SetUserValue(user_id, kSupervisedUserPasswordVersion, holder); | |
229 if (password_info->GetStringWithoutPathExpansion(kSalt, &holder)) | |
230 SetUserValue(user_id, kSupervisedUserPasswordSalt, holder); | |
231 g_browser_process->local_state()->CommitPendingWrite(); | |
232 } | |
233 | |
234 bool SupervisedUserManagerImpl::GetUserValue( | |
235 const std::string& user_id, | |
236 const char* key, | |
237 std::string* out_value) const { | |
185 PrefService* local_state = g_browser_process->local_state(); | 238 PrefService* local_state = g_browser_process->local_state(); |
186 const DictionaryValue* manager_mails = | 239 const DictionaryValue* dictionary = local_state->GetDictionary(key); |
187 local_state->GetDictionary(kManagedUserManagerDisplayEmails); | 240 return dictionary->GetStringWithoutPathExpansion(user_id, out_value); |
188 std::string result; | 241 } |
189 if (manager_mails->GetStringWithoutPathExpansion(user_id, &result) && | 242 |
190 !result.empty()) { | 243 void SupervisedUserManagerImpl::SetUserValue( |
191 return result; | 244 const std::string& user_id, |
192 } | 245 const char* key, |
193 return GetManagerUserId(user_id); | 246 const std::string& value) { |
247 PrefService* local_state = g_browser_process->local_state(); | |
248 DictionaryPrefUpdate update(local_state, key); | |
249 update->SetWithoutPathExpansion(user_id, new base::StringValue(value)); | |
Bernhard Bauer
2013/12/11 14:46:43
SetStringWithoutPathExpansion()
Denis Kuznetsov (DE-MUC)
2013/12/12 19:45:24
Done.
| |
194 } | 250 } |
195 | 251 |
196 const User* SupervisedUserManagerImpl::FindByDisplayName( | 252 const User* SupervisedUserManagerImpl::FindByDisplayName( |
197 const string16& display_name) const { | 253 const string16& display_name) const { |
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
199 const UserList& users = owner_->GetUsers(); | 255 const UserList& users = owner_->GetUsers(); |
200 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 256 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
201 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) && | 257 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) && |
202 ((*it)->display_name() == display_name)) { | 258 ((*it)->display_name() == display_name)) { |
203 return *it; | 259 return *it; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 prefs->ClearPref(kLocallyManagedUserCreationTransactionUserId); | 338 prefs->ClearPref(kLocallyManagedUserCreationTransactionUserId); |
283 prefs->CommitPendingWrite(); | 339 prefs->CommitPendingWrite(); |
284 } | 340 } |
285 | 341 |
286 void SupervisedUserManagerImpl::RemoveNonCryptohomeData( | 342 void SupervisedUserManagerImpl::RemoveNonCryptohomeData( |
287 const std::string& user_id) { | 343 const std::string& user_id) { |
288 PrefService* prefs = g_browser_process->local_state(); | 344 PrefService* prefs = g_browser_process->local_state(); |
289 ListPrefUpdate prefs_new_users_update(prefs, kLocallyManagedUsersFirstRun); | 345 ListPrefUpdate prefs_new_users_update(prefs, kLocallyManagedUsersFirstRun); |
290 prefs_new_users_update->Remove(base::StringValue(user_id), NULL); | 346 prefs_new_users_update->Remove(base::StringValue(user_id), NULL); |
291 | 347 |
292 DictionaryPrefUpdate synd_id_update(prefs, kManagedUserSyncId); | 348 CleanPref(user_id, kManagedUserSyncId); |
293 synd_id_update->RemoveWithoutPathExpansion(user_id, NULL); | 349 CleanPref(user_id, kManagedUserManagers); |
350 CleanPref(user_id, kManagedUserManagerNames); | |
351 CleanPref(user_id, kManagedUserManagerDisplayEmails); | |
352 CleanPref(user_id, kSupervisedUserPasswordSalt); | |
353 CleanPref(user_id, kSupervisedUserPasswordSchemaVersion); | |
354 CleanPref(user_id, kSupervisedUserPasswordVersion); | |
355 } | |
294 | 356 |
295 DictionaryPrefUpdate managers_update(prefs, kManagedUserManagers); | 357 void SupervisedUserManagerImpl::CleanPref(const std::string& user_id, |
296 managers_update->RemoveWithoutPathExpansion(user_id, NULL); | 358 const char* key) { |
297 | 359 PrefService* prefs = g_browser_process->local_state(); |
298 DictionaryPrefUpdate manager_names_update(prefs, | 360 DictionaryPrefUpdate dict_update(prefs, key); |
299 kManagedUserManagerNames); | 361 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 } | 362 } |
306 | 363 |
307 bool SupervisedUserManagerImpl::CheckForFirstRun(const std::string& user_id) { | 364 bool SupervisedUserManagerImpl::CheckForFirstRun(const std::string& user_id) { |
308 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(), | 365 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(), |
309 kLocallyManagedUsersFirstRun); | 366 kLocallyManagedUsersFirstRun); |
310 return prefs_new_users_update->Remove(base::StringValue(user_id), NULL); | 367 return prefs_new_users_update->Remove(base::StringValue(user_id), NULL); |
311 } | 368 } |
312 | 369 |
313 void SupervisedUserManagerImpl::UpdateManagerName(const std::string& manager_id, | 370 void SupervisedUserManagerImpl::UpdateManagerName(const std::string& manager_id, |
314 const string16& new_display_name) { | 371 const string16& new_display_name) { |
(...skipping 10 matching lines...) Expand all Loading... | |
325 bool has_manager_id = it.value().GetAsString(&user_id); | 382 bool has_manager_id = it.value().GetAsString(&user_id); |
326 DCHECK(has_manager_id); | 383 DCHECK(has_manager_id); |
327 if (user_id == manager_id) { | 384 if (user_id == manager_id) { |
328 manager_name_update->SetWithoutPathExpansion( | 385 manager_name_update->SetWithoutPathExpansion( |
329 it.key(), | 386 it.key(), |
330 new base::StringValue(new_display_name)); | 387 new base::StringValue(new_display_name)); |
331 } | 388 } |
332 } | 389 } |
333 } | 390 } |
334 | 391 |
392 SupervisedUserAuthentication* SupervisedUserManagerImpl:: | |
393 GetSupervisedUserAuthentication() { | |
394 return authentication_.get(); | |
395 } | |
335 | 396 |
336 } // namespace chromeos | 397 } // namespace chromeos |
OLD | NEW |