| 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/multi_profile_user_controller.h" | 5 #include "chrome/browser/chromeos/login/multi_profile_user_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/prefs/pref_change_registrar.h" | 9 #include "base/prefs/pref_change_registrar.h" |
| 10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/prefs/scoped_user_pref_update.h" | 12 #include "base/prefs/scoped_user_pref_update.h" |
| 13 #include "chrome/browser/chromeos/login/multi_profile_user_controller_delegate.h
" | 13 #include "chrome/browser/chromeos/login/multi_profile_user_controller_delegate.h
" |
| 14 #include "chrome/browser/chromeos/login/user.h" |
| 14 #include "chrome/browser/chromeos/login/user_manager.h" | 15 #include "chrome/browser/chromeos/login/user_manager.h" |
| 16 #include "chrome/browser/chromeos/policy/policy_cert_service.h" |
| 17 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
| 15 #include "chrome/browser/prefs/pref_service_syncable.h" | 18 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 18 #include "google_apis/gaia/gaia_auth_util.h" | 21 #include "google_apis/gaia/gaia_auth_util.h" |
| 19 | 22 |
| 20 namespace chromeos { | 23 namespace chromeos { |
| 21 | 24 |
| 22 namespace { | 25 namespace { |
| 23 | 26 |
| 24 std::string SanitizeBehaviorValue(const std::string& value) { | 27 std::string SanitizeBehaviorValue(const std::string& value) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 prefs::kMultiProfileUserBehavior, | 63 prefs::kMultiProfileUserBehavior, |
| 61 kBehaviorUnrestricted, | 64 kBehaviorUnrestricted, |
| 62 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 65 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 63 } | 66 } |
| 64 | 67 |
| 65 bool MultiProfileUserController::IsUserAllowedInSession( | 68 bool MultiProfileUserController::IsUserAllowedInSession( |
| 66 const std::string& user_email) const { | 69 const std::string& user_email) const { |
| 67 UserManager* user_manager = UserManager::Get(); | 70 UserManager* user_manager = UserManager::Get(); |
| 68 CHECK(user_manager); | 71 CHECK(user_manager); |
| 69 | 72 |
| 73 const User* primary_user = user_manager->GetPrimaryUser(); |
| 70 std::string primary_user_email; | 74 std::string primary_user_email; |
| 71 if (user_manager->GetPrimaryUser()) | 75 if (primary_user) |
| 72 primary_user_email = user_manager->GetPrimaryUser()->email(); | 76 primary_user_email = primary_user->email(); |
| 73 | 77 |
| 74 // Always allow if there is no primary user or user being checked is the | 78 // Always allow if there is no primary user or user being checked is the |
| 75 // primary user. | 79 // primary user. |
| 76 if (primary_user_email.empty() || primary_user_email == user_email) | 80 if (primary_user_email.empty() || primary_user_email == user_email) |
| 77 return true; | 81 return true; |
| 78 | 82 |
| 79 // Owner is not allowed to be secondary user. | 83 // Owner is not allowed to be secondary user. |
| 80 if (user_manager->GetOwnerEmail() == user_email) | 84 if (user_manager->GetOwnerEmail() == user_email) |
| 81 return false; | 85 return false; |
| 82 | 86 |
| 87 // Don't allow profiles potentially tainted by data fetched with policy-pushed |
| 88 // certificates to join a multiprofile session. |
| 89 if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(user_email)) |
| 90 return false; |
| 91 |
| 92 // Don't allow any secondary profiles if the primary profile is tainted. |
| 93 if (policy::PolicyCertServiceFactory::UsedPolicyCertificates( |
| 94 primary_user_email)) { |
| 95 // Check directly in local_state before checking if the primary user has |
| 96 // a PolicyCertService. His profile may have been tainted previously though |
| 97 // he didn't get a PolicyCertService created for this session. |
| 98 return false; |
| 99 } |
| 100 |
| 101 // If the primary profile already has policy certificates installed but hasn't |
| 102 // used them yet then it can become tainted at any time during this session; |
| 103 // disable secondary profiles in this case too. |
| 104 Profile* profile = |
| 105 primary_user ? user_manager->GetProfileByUser(primary_user) : NULL; |
| 106 policy::PolicyCertService* service = |
| 107 profile ? policy::PolicyCertServiceFactory::GetForProfile(profile) : NULL; |
| 108 if (service && service->has_policy_certificates()) |
| 109 return false; |
| 110 |
| 83 // No user is allowed if the primary user policy forbids it. | 111 // No user is allowed if the primary user policy forbids it. |
| 84 const std::string primary_user_behavior = GetCachedValue(primary_user_email); | 112 const std::string primary_user_behavior = GetCachedValue(primary_user_email); |
| 85 if (primary_user_behavior == kBehaviorNotAllowed) | 113 if (primary_user_behavior == kBehaviorNotAllowed) |
| 86 return false; | 114 return false; |
| 87 | 115 |
| 88 // The user must have 'unrestricted' policy to be a secondary user. | 116 // The user must have 'unrestricted' policy to be a secondary user. |
| 89 const std::string behavior = GetCachedValue(user_email); | 117 const std::string behavior = GetCachedValue(user_email); |
| 90 return behavior == kBehaviorUnrestricted; | 118 return behavior == kBehaviorUnrestricted; |
| 91 } | 119 } |
| 92 | 120 |
| 93 void MultiProfileUserController::StartObserving(Profile* user_profile) { | 121 void MultiProfileUserController::StartObserving(Profile* user_profile) { |
| 94 // Profile name could be empty during tests. | 122 // Profile name could be empty during tests. |
| 95 if (user_profile->GetProfileName().empty()) | 123 if (user_profile->GetProfileName().empty()) |
| 96 return; | 124 return; |
| 97 | 125 |
| 98 scoped_ptr<PrefChangeRegistrar> registrar(new PrefChangeRegistrar); | 126 scoped_ptr<PrefChangeRegistrar> registrar(new PrefChangeRegistrar); |
| 99 registrar->Init(user_profile->GetPrefs()); | 127 registrar->Init(user_profile->GetPrefs()); |
| 100 registrar->Add( | 128 registrar->Add( |
| 101 prefs::kMultiProfileUserBehavior, | 129 prefs::kMultiProfileUserBehavior, |
| 102 base::Bind(&MultiProfileUserController::OnUserPrefChanged, | 130 base::Bind(&MultiProfileUserController::OnUserPrefChanged, |
| 103 base::Unretained(this), | 131 base::Unretained(this), |
| 104 user_profile)); | 132 user_profile)); |
| 105 pref_watchers_.push_back(registrar.release()); | 133 pref_watchers_.push_back(registrar.release()); |
| 106 | 134 |
| 107 OnUserPrefChanged(user_profile); | 135 OnUserPrefChanged(user_profile); |
| 108 } | 136 } |
| 109 | 137 |
| 110 void MultiProfileUserController::RemoveCachedValue( | 138 void MultiProfileUserController::RemoveCachedValues( |
| 111 const std::string& user_email) { | 139 const std::string& user_email) { |
| 112 DictionaryPrefUpdate update(local_state_, | 140 DictionaryPrefUpdate update(local_state_, |
| 113 prefs::kCachedMultiProfileUserBehavior); | 141 prefs::kCachedMultiProfileUserBehavior); |
| 114 update->RemoveWithoutPathExpansion(user_email, NULL); | 142 update->RemoveWithoutPathExpansion(user_email, NULL); |
| 143 policy::PolicyCertServiceFactory::ClearUsedPolicyCertificates(user_email); |
| 115 } | 144 } |
| 116 | 145 |
| 117 std::string MultiProfileUserController::GetCachedValue( | 146 std::string MultiProfileUserController::GetCachedValue( |
| 118 const std::string& user_email) const { | 147 const std::string& user_email) const { |
| 119 const DictionaryValue* dict = | 148 const DictionaryValue* dict = |
| 120 local_state_->GetDictionary(prefs::kCachedMultiProfileUserBehavior); | 149 local_state_->GetDictionary(prefs::kCachedMultiProfileUserBehavior); |
| 121 std::string value; | 150 std::string value; |
| 122 if (dict && dict->GetStringWithoutPathExpansion(user_email, &value)) | 151 if (dict && dict->GetStringWithoutPathExpansion(user_email, &value)) |
| 123 return SanitizeBehaviorValue(value); | 152 return SanitizeBehaviorValue(value); |
| 124 | 153 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 152 | 181 |
| 153 PrefService* prefs = user_profile->GetPrefs(); | 182 PrefService* prefs = user_profile->GetPrefs(); |
| 154 const std::string behavior = | 183 const std::string behavior = |
| 155 prefs->GetString(prefs::kMultiProfileUserBehavior); | 184 prefs->GetString(prefs::kMultiProfileUserBehavior); |
| 156 SetCachedValue(user_email, behavior); | 185 SetCachedValue(user_email, behavior); |
| 157 | 186 |
| 158 CheckSessionUsers(); | 187 CheckSessionUsers(); |
| 159 } | 188 } |
| 160 | 189 |
| 161 } // namespace chromeos | 190 } // namespace chromeos |
| OLD | NEW |