Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc

Issue 148843002: Make an online wildcard login check for enterprise devices. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Joao's comments. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/policy/user_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/metrics/sparse_histogram.h" 11 #include "base/metrics/sparse_histogram.h"
12 #include "base/sequenced_task_runner.h" 12 #include "base/sequenced_task_runner.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" 14 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h"
15 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" 15 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h"
16 #include "chrome/browser/chromeos/policy/wildcard_login_checker.h"
16 #include "chrome/browser/chromeos/profiles/profile_helper.h" 17 #include "chrome/browser/chromeos/profiles/profile_helper.h"
18 #include "chrome/browser/lifetime/application_lifetime.h"
17 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" 19 #include "components/policy/core/common/cloud/cloud_external_data_manager.h"
18 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" 20 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h"
19 #include "components/policy/core/common/cloud/device_management_service.h" 21 #include "components/policy/core/common/cloud/device_management_service.h"
20 #include "components/policy/core/common/cloud/system_policy_request_context.h" 22 #include "components/policy/core/common/cloud/system_policy_request_context.h"
21 #include "components/policy/core/common/policy_pref_names.h" 23 #include "components/policy/core/common/policy_pref_names.h"
22 #include "content/public/common/content_client.h" 24 #include "content/public/common/content_client.h"
23 #include "net/url_request/url_request_context_getter.h" 25 #include "net/url_request/url_request_context_getter.h"
24 #include "url/gurl.h" 26 #include "url/gurl.h"
25 27
26 namespace em = enterprise_management; 28 namespace em = enterprise_management;
(...skipping 13 matching lines...) Expand all
40 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayOAuth2Token"; 42 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayOAuth2Token";
41 const char kUMAInitialFetchDelayPolicyFetch[] = 43 const char kUMAInitialFetchDelayPolicyFetch[] =
42 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayPolicyFetch"; 44 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayPolicyFetch";
43 const char kUMAInitialFetchDelayTotal[] = 45 const char kUMAInitialFetchDelayTotal[] =
44 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayTotal"; 46 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayTotal";
45 const char kUMAInitialFetchOAuth2Error[] = 47 const char kUMAInitialFetchOAuth2Error[] =
46 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2Error"; 48 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2Error";
47 const char kUMAInitialFetchOAuth2NetworkError[] = 49 const char kUMAInitialFetchOAuth2NetworkError[] =
48 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2NetworkError"; 50 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2NetworkError";
49 51
52 void OnWildcardCheckCompleted(const std::string& username, bool result) {
53 if (!result) {
54 LOG(ERROR) << "Online wildcard login check failed, terminating session.";
55
56 // TODO(mnissler): This only removes the user pod from the login screen, but
57 // the cryptohome remains. This is because deleting the cryptohome for a
58 // logged-in session is not possible. Fix this either by delaying the
59 // cryptohome deletion operation or by getting rid of the in-session
60 // wildcard check.
61 chromeos::UserManager::Get()->RemoveUserFromList(username);
62 chrome::AttemptUserExit();
63 }
64 }
65
50 } // namespace 66 } // namespace
51 67
52 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS( 68 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS(
53 scoped_ptr<CloudPolicyStore> store, 69 scoped_ptr<CloudPolicyStore> store,
54 scoped_ptr<CloudExternalDataManager> external_data_manager, 70 scoped_ptr<CloudExternalDataManager> external_data_manager,
55 const base::FilePath& component_policy_cache_path, 71 const base::FilePath& component_policy_cache_path,
56 bool wait_for_policy_fetch, 72 bool wait_for_policy_fetch,
57 base::TimeDelta initial_policy_fetch_timeout, 73 base::TimeDelta initial_policy_fetch_timeout,
58 const scoped_refptr<base::SequencedTaskRunner>& task_runner, 74 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
59 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner, 75 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 if (service()->IsInitializationComplete()) { 134 if (service()->IsInitializationComplete()) {
119 OnInitializationCompleted(service()); 135 OnInitializationCompleted(service());
120 } else { 136 } else {
121 service()->AddObserver(this); 137 service()->AddObserver(this);
122 } 138 }
123 } 139 }
124 140
125 void UserCloudPolicyManagerChromeOS::OnAccessTokenAvailable( 141 void UserCloudPolicyManagerChromeOS::OnAccessTokenAvailable(
126 const std::string& access_token) { 142 const std::string& access_token) {
127 access_token_ = access_token; 143 access_token_ = access_token;
144
145 if (!wildcard_username_.empty()) {
146 wildcard_login_checker_.reset(new WildcardLoginChecker());
147 wildcard_login_checker_->StartWithAccessToken(
148 access_token,
149 base::Bind(&OnWildcardCheckCompleted, wildcard_username_));
150 }
151
128 if (service() && service()->IsInitializationComplete() && 152 if (service() && service()->IsInitializationComplete() &&
129 client() && !client()->is_registered()) { 153 client() && !client()->is_registered()) {
130 OnOAuth2PolicyTokenFetched( 154 OnOAuth2PolicyTokenFetched(
131 access_token, GoogleServiceAuthError(GoogleServiceAuthError::NONE)); 155 access_token, GoogleServiceAuthError(GoogleServiceAuthError::NONE));
132 } 156 }
133 } 157 }
134 158
135 bool UserCloudPolicyManagerChromeOS::IsClientRegistered() const { 159 bool UserCloudPolicyManagerChromeOS::IsClientRegistered() const {
136 return client() && client()->is_registered(); 160 return client() && client()->is_registered();
137 } 161 }
138 162
163 void UserCloudPolicyManagerChromeOS::EnableWildcardLoginCheck(
164 const std::string& username) {
165 wildcard_username_ = username;
Andrew T Wilson (Slow) 2014/01/28 16:31:13 So, this breaks if for some reason EnableWildcardL
Mattias Nissler (ping if slow) 2014/01/29 12:12:32 Done.
166 }
167
139 void UserCloudPolicyManagerChromeOS::Shutdown() { 168 void UserCloudPolicyManagerChromeOS::Shutdown() {
140 if (client()) 169 if (client())
141 client()->RemoveObserver(this); 170 client()->RemoveObserver(this);
142 if (service()) 171 if (service())
143 service()->RemoveObserver(this); 172 service()->RemoveObserver(this);
144 token_fetcher_.reset(); 173 token_fetcher_.reset();
145 external_data_manager_->Disconnect(); 174 external_data_manager_->Disconnect();
146 CloudPolicyManager::Shutdown(); 175 CloudPolicyManager::Shutdown();
147 } 176 }
148 177
(...skipping 25 matching lines...) Expand all
174 // 203 //
175 // If |wait_for_policy_fetch_| is false then the UserCloudPolicyTokenForwarder 204 // If |wait_for_policy_fetch_| is false then the UserCloudPolicyTokenForwarder
176 // service will eventually call OnAccessTokenAvailable() once an access token 205 // service will eventually call OnAccessTokenAvailable() once an access token
177 // is available. That call may have already happened while waiting for 206 // is available. That call may have already happened while waiting for
178 // initialization of the CloudPolicyService, so in that case check if an 207 // initialization of the CloudPolicyService, so in that case check if an
179 // access token is already available. 208 // access token is already available.
180 if (!client()->is_registered()) { 209 if (!client()->is_registered()) {
181 if (wait_for_policy_fetch_) { 210 if (wait_for_policy_fetch_) {
182 FetchPolicyOAuthTokenUsingSigninProfile(); 211 FetchPolicyOAuthTokenUsingSigninProfile();
183 } else if (!access_token_.empty()) { 212 } else if (!access_token_.empty()) {
184 OnOAuth2PolicyTokenFetched( 213 OnAccessTokenAvailable(access_token_);
185 access_token_, GoogleServiceAuthError(GoogleServiceAuthError::NONE));
186 } 214 }
187 } 215 }
188 216
189 if (!wait_for_policy_fetch_) { 217 if (!wait_for_policy_fetch_) {
190 // If this isn't blocking on a policy fetch then 218 // If this isn't blocking on a policy fetch then
191 // CloudPolicyManager::OnStoreLoaded() already published the cached policy. 219 // CloudPolicyManager::OnStoreLoaded() already published the cached policy.
192 // Start the refresh scheduler now, which will eventually refresh the 220 // Start the refresh scheduler now, which will eventually refresh the
193 // cached policy or make the first fetch once the OAuth2 token is 221 // cached policy or make the first fetch once the OAuth2 token is
194 // available. 222 // available.
195 StartRefreshSchedulerIfReady(); 223 StartRefreshSchedulerIfReady();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 g_browser_process->system_request_context(), 288 g_browser_process->system_request_context(),
261 base::Bind(&UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched, 289 base::Bind(&UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched,
262 base::Unretained(this)))); 290 base::Unretained(this))));
263 token_fetcher_->Start(); 291 token_fetcher_->Start();
264 } 292 }
265 293
266 void UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched( 294 void UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched(
267 const std::string& policy_token, 295 const std::string& policy_token,
268 const GoogleServiceAuthError& error) { 296 const GoogleServiceAuthError& error) {
269 DCHECK(!client()->is_registered()); 297 DCHECK(!client()->is_registered());
270
271 time_token_available_ = base::Time::Now(); 298 time_token_available_ = base::Time::Now();
272 if (wait_for_policy_fetch_) { 299 if (wait_for_policy_fetch_) {
273 UMA_HISTOGRAM_MEDIUM_TIMES(kUMAInitialFetchDelayOAuth2Token, 300 UMA_HISTOGRAM_MEDIUM_TIMES(kUMAInitialFetchDelayOAuth2Token,
274 time_token_available_ - time_init_completed_); 301 time_token_available_ - time_init_completed_);
275 } 302 }
276 303
277 if (error.state() == GoogleServiceAuthError::NONE) { 304 if (error.state() == GoogleServiceAuthError::NONE) {
278 // Start client registration. Either OnRegistrationStateChanged() or 305 // Start client registration. Either OnRegistrationStateChanged() or
279 // OnClientError() will be called back. 306 // OnClientError() will be called back.
280 client()->Register(em::DeviceRegisterRequest::USER, 307 client()->Register(em::DeviceRegisterRequest::USER,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // OnComponentCloudPolicyUpdated() once it's ready. 369 // OnComponentCloudPolicyUpdated() once it's ready.
343 return; 370 return;
344 } 371 }
345 372
346 core()->StartRefreshScheduler(); 373 core()->StartRefreshScheduler();
347 core()->TrackRefreshDelayPref(local_state_, 374 core()->TrackRefreshDelayPref(local_state_,
348 policy_prefs::kUserPolicyRefreshRate); 375 policy_prefs::kUserPolicyRefreshRate);
349 } 376 }
350 377
351 } // namespace policy 378 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698