| 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/chromeos/login/enrollment/enterprise_enrollment_helper_
impl.h" | 5 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_
impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 namespace chromeos { | 66 namespace chromeos { |
| 67 | 67 |
| 68 EnterpriseEnrollmentHelperImpl::EnterpriseEnrollmentHelperImpl( | 68 EnterpriseEnrollmentHelperImpl::EnterpriseEnrollmentHelperImpl( |
| 69 EnrollmentStatusConsumer* status_consumer, | 69 EnrollmentStatusConsumer* status_consumer, |
| 70 const policy::EnrollmentConfig& enrollment_config, | 70 const policy::EnrollmentConfig& enrollment_config, |
| 71 const std::string& enrolling_user_domain) | 71 const std::string& enrolling_user_domain) |
| 72 : EnterpriseEnrollmentHelper(status_consumer), | 72 : EnterpriseEnrollmentHelper(status_consumer), |
| 73 enrollment_config_(enrollment_config), | 73 enrollment_config_(enrollment_config), |
| 74 enrolling_user_domain_(enrolling_user_domain), | 74 enrolling_user_domain_(enrolling_user_domain), |
| 75 started_(false), | |
| 76 finished_(false), | |
| 77 success_(false), | |
| 78 auth_data_cleared_(false), | |
| 79 weak_ptr_factory_(this) { | 75 weak_ptr_factory_(this) { |
| 80 // Init the TPM if it has not been done until now (in debug build we might | 76 // Init the TPM if it has not been done until now (in debug build we might |
| 81 // have not done that yet). | 77 // have not done that yet). |
| 82 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( | 78 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( |
| 83 EmptyVoidDBusMethodCallback()); | 79 EmptyVoidDBusMethodCallback()); |
| 84 } | 80 } |
| 85 | 81 |
| 86 EnterpriseEnrollmentHelperImpl::~EnterpriseEnrollmentHelperImpl() { | 82 EnterpriseEnrollmentHelperImpl::~EnterpriseEnrollmentHelperImpl() { |
| 87 DCHECK(g_browser_process->IsShuttingDown() || !started_ || | 83 DCHECK( |
| 88 (finished_ && (success_ || auth_data_cleared_))); | 84 g_browser_process->IsShuttingDown() || |
| 85 oauth_status_ == OAUTH_NOT_STARTED || |
| 86 (oauth_status_ == OAUTH_FINISHED && (success_ || oauth_data_cleared_))); |
| 89 } | 87 } |
| 90 | 88 |
| 91 void EnterpriseEnrollmentHelperImpl::EnrollUsingAuthCode( | 89 void EnterpriseEnrollmentHelperImpl::EnrollUsingAuthCode( |
| 92 const std::string& auth_code, | 90 const std::string& auth_code, |
| 93 bool fetch_additional_token) { | 91 bool fetch_additional_token) { |
| 94 DCHECK(!started_); | 92 DCHECK(oauth_status_ == OAUTH_NOT_STARTED); |
| 95 started_ = true; | 93 oauth_status_ = OAUTH_STARTED_WITH_AUTH_CODE; |
| 96 oauth_fetcher_.reset(policy::PolicyOAuth2TokenFetcher::CreateInstance()); | 94 oauth_fetcher_.reset(policy::PolicyOAuth2TokenFetcher::CreateInstance()); |
| 97 oauth_fetcher_->StartWithAuthCode( | 95 oauth_fetcher_->StartWithAuthCode( |
| 98 auth_code, g_browser_process->system_request_context(), | 96 auth_code, g_browser_process->system_request_context(), |
| 99 base::Bind(&EnterpriseEnrollmentHelperImpl::OnTokenFetched, | 97 base::Bind(&EnterpriseEnrollmentHelperImpl::OnTokenFetched, |
| 100 weak_ptr_factory_.GetWeakPtr(), | 98 weak_ptr_factory_.GetWeakPtr(), |
| 101 fetch_additional_token /* is_additional_token */)); | 99 fetch_additional_token /* is_additional_token */)); |
| 102 } | 100 } |
| 103 | 101 |
| 104 void EnterpriseEnrollmentHelperImpl::EnrollUsingToken( | 102 void EnterpriseEnrollmentHelperImpl::EnrollUsingToken( |
| 105 const std::string& token) { | 103 const std::string& token) { |
| 106 DCHECK(!started_); | 104 DCHECK(oauth_status_ != OAUTH_STARTED_WITH_TOKEN); |
| 107 started_ = true; | 105 if (oauth_status_ == OAUTH_NOT_STARTED) |
| 108 DoEnrollUsingToken(token); | 106 oauth_status_ = OAUTH_STARTED_WITH_TOKEN; |
| 107 DoEnroll(token); |
| 108 } |
| 109 |
| 110 void EnterpriseEnrollmentHelperImpl::EnrollUsingAttestation() { |
| 111 CHECK(enrollment_config_.is_mode_attestation()); |
| 112 DoEnroll(""); // The token is not used in attestation mode. |
| 109 } | 113 } |
| 110 | 114 |
| 111 void EnterpriseEnrollmentHelperImpl::ClearAuth(const base::Closure& callback) { | 115 void EnterpriseEnrollmentHelperImpl::ClearAuth(const base::Closure& callback) { |
| 112 // Do not revoke the additional token if enrollment has finished | 116 if (oauth_status_ != OAUTH_NOT_STARTED) { |
| 113 // successfully. | 117 // Do not revoke the additional token if enrollment has finished |
| 114 if (!success_ && additional_token_.length()) | 118 // successfully. |
| 115 (new TokenRevoker())->Start(additional_token_); | 119 if (!success_ && additional_token_.length()) |
| 120 (new TokenRevoker())->Start(additional_token_); |
| 116 | 121 |
| 117 if (oauth_fetcher_) { | 122 if (oauth_fetcher_) { |
| 118 if (!oauth_fetcher_->OAuth2AccessToken().empty()) | 123 if (!oauth_fetcher_->OAuth2AccessToken().empty()) |
| 119 (new TokenRevoker())->Start(oauth_fetcher_->OAuth2AccessToken()); | 124 (new TokenRevoker())->Start(oauth_fetcher_->OAuth2AccessToken()); |
| 120 | 125 |
| 121 if (!oauth_fetcher_->OAuth2RefreshToken().empty()) | 126 if (!oauth_fetcher_->OAuth2RefreshToken().empty()) |
| 122 (new TokenRevoker())->Start(oauth_fetcher_->OAuth2RefreshToken()); | 127 (new TokenRevoker())->Start(oauth_fetcher_->OAuth2RefreshToken()); |
| 123 | 128 |
| 124 oauth_fetcher_.reset(); | 129 oauth_fetcher_.reset(); |
| 125 } else if (oauth_token_.length()) { | 130 } else if (oauth_token_.length()) { |
| 126 // EnrollUsingToken was called. | 131 // EnrollUsingToken was called. |
| 127 (new TokenRevoker())->Start(oauth_token_); | 132 (new TokenRevoker())->Start(oauth_token_); |
| 133 } |
| 128 } | 134 } |
| 129 | 135 |
| 130 chromeos::ProfileHelper::Get()->ClearSigninProfile( | 136 chromeos::ProfileHelper::Get()->ClearSigninProfile( |
| 131 base::Bind(&EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared, | 137 base::Bind(&EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared, |
| 132 weak_ptr_factory_.GetWeakPtr(), callback)); | 138 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 133 } | 139 } |
| 134 | 140 |
| 135 void EnterpriseEnrollmentHelperImpl::DoEnrollUsingToken( | 141 void EnterpriseEnrollmentHelperImpl::DoEnroll(const std::string& token) { |
| 136 const std::string& token) { | |
| 137 DCHECK(token == oauth_token_ || oauth_token_.empty()); | 142 DCHECK(token == oauth_token_ || oauth_token_.empty()); |
| 143 DCHECK(enrollment_config_.is_mode_attestation() || |
| 144 oauth_status_ == OAUTH_STARTED_WITH_AUTH_CODE || |
| 145 oauth_status_ == OAUTH_STARTED_WITH_TOKEN); |
| 138 oauth_token_ = token; | 146 oauth_token_ = token; |
| 139 policy::BrowserPolicyConnectorChromeOS* connector = | 147 policy::BrowserPolicyConnectorChromeOS* connector = |
| 140 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 148 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 141 if (connector->IsEnterpriseManaged() && | 149 if (connector->IsEnterpriseManaged() && |
| 142 connector->GetEnterpriseDomain() != enrolling_user_domain_) { | 150 connector->GetEnterpriseDomain() != enrolling_user_domain_) { |
| 143 LOG(ERROR) << "Trying to re-enroll to a different domain than " | 151 LOG(ERROR) << "Trying to re-enroll to a different domain than " |
| 144 << connector->GetEnterpriseDomain(); | 152 << connector->GetEnterpriseDomain(); |
| 145 UMA(policy::kMetricEnrollmentPrecheckDomainMismatch); | 153 UMA(policy::kMetricEnrollmentPrecheckDomainMismatch); |
| 146 finished_ = true; | 154 if (oauth_status_ != OAUTH_NOT_STARTED) |
| 155 oauth_status_ = OAUTH_FINISHED; |
| 147 status_consumer()->OnOtherError(OTHER_ERROR_DOMAIN_MISMATCH); | 156 status_consumer()->OnOtherError(OTHER_ERROR_DOMAIN_MISMATCH); |
| 148 return; | 157 return; |
| 149 } | 158 } |
| 150 | 159 |
| 151 policy::DeviceCloudPolicyInitializer::AllowedDeviceModes device_modes; | 160 policy::DeviceCloudPolicyInitializer::AllowedDeviceModes device_modes; |
| 152 device_modes[policy::DEVICE_MODE_ENTERPRISE] = true; | 161 device_modes[policy::DEVICE_MODE_ENTERPRISE] = true; |
| 153 connector->ScheduleServiceInitialization(0); | 162 connector->ScheduleServiceInitialization(0); |
| 154 | 163 |
| 155 policy::DeviceCloudPolicyInitializer* dcp_initializer = | 164 policy::DeviceCloudPolicyInitializer* dcp_initializer = |
| 156 connector->GetDeviceCloudPolicyInitializer(); | 165 connector->GetDeviceCloudPolicyInitializer(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 &EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUploadCompleted, | 202 &EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUploadCompleted, |
| 194 weak_ptr_factory_.GetWeakPtr())); | 203 weak_ptr_factory_.GetWeakPtr())); |
| 195 } | 204 } |
| 196 | 205 |
| 197 void EnterpriseEnrollmentHelperImpl::OnTokenFetched( | 206 void EnterpriseEnrollmentHelperImpl::OnTokenFetched( |
| 198 bool is_additional_token, | 207 bool is_additional_token, |
| 199 const std::string& token, | 208 const std::string& token, |
| 200 const GoogleServiceAuthError& error) { | 209 const GoogleServiceAuthError& error) { |
| 201 if (error.state() != GoogleServiceAuthError::NONE) { | 210 if (error.state() != GoogleServiceAuthError::NONE) { |
| 202 ReportAuthStatus(error); | 211 ReportAuthStatus(error); |
| 203 finished_ = true; | 212 oauth_status_ = OAUTH_FINISHED; |
| 204 status_consumer()->OnAuthError(error); | 213 status_consumer()->OnAuthError(error); |
| 205 return; | 214 return; |
| 206 } | 215 } |
| 207 | 216 |
| 208 if (!is_additional_token) { | 217 if (!is_additional_token) { |
| 209 DoEnrollUsingToken(token); | 218 EnrollUsingToken(token); |
| 210 return; | 219 return; |
| 211 } | 220 } |
| 212 | 221 |
| 213 additional_token_ = token; | 222 additional_token_ = token; |
| 214 std::string refresh_token = oauth_fetcher_->OAuth2RefreshToken(); | 223 std::string refresh_token = oauth_fetcher_->OAuth2RefreshToken(); |
| 215 oauth_fetcher_.reset(policy::PolicyOAuth2TokenFetcher::CreateInstance()); | 224 oauth_fetcher_.reset(policy::PolicyOAuth2TokenFetcher::CreateInstance()); |
| 216 oauth_fetcher_->StartWithRefreshToken( | 225 oauth_fetcher_->StartWithRefreshToken( |
| 217 refresh_token, g_browser_process->system_request_context(), | 226 refresh_token, g_browser_process->system_request_context(), |
| 218 base::Bind(&EnterpriseEnrollmentHelperImpl::OnTokenFetched, | 227 base::Bind(&EnterpriseEnrollmentHelperImpl::OnTokenFetched, |
| 219 weak_ptr_factory_.GetWeakPtr(), | 228 weak_ptr_factory_.GetWeakPtr(), |
| 220 false /* is_additional_token */)); | 229 false /* is_additional_token */)); |
| 221 } | 230 } |
| 222 | 231 |
| 223 void EnterpriseEnrollmentHelperImpl::OnEnrollmentFinished( | 232 void EnterpriseEnrollmentHelperImpl::OnEnrollmentFinished( |
| 224 policy::EnrollmentStatus status) { | 233 policy::EnrollmentStatus status) { |
| 225 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. | 234 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. |
| 226 LOG(WARNING) << "Enrollment finished"; | 235 LOG(WARNING) << "Enrollment finished"; |
| 227 ReportEnrollmentStatus(status); | 236 ReportEnrollmentStatus(status); |
| 228 finished_ = true; | 237 if (oauth_status_ != OAUTH_NOT_STARTED) |
| 238 oauth_status_ = OAUTH_FINISHED; |
| 229 if (status.status() == policy::EnrollmentStatus::STATUS_SUCCESS) { | 239 if (status.status() == policy::EnrollmentStatus::STATUS_SUCCESS) { |
| 230 success_ = true; | 240 success_ = true; |
| 231 StartupUtils::MarkOobeCompleted(); | 241 StartupUtils::MarkOobeCompleted(); |
| 232 status_consumer()->OnDeviceEnrolled(additional_token_); | 242 status_consumer()->OnDeviceEnrolled(additional_token_); |
| 233 } else { | 243 } else { |
| 234 status_consumer()->OnEnrollmentError(status); | 244 status_consumer()->OnEnrollmentError(status); |
| 235 } | 245 } |
| 236 } | 246 } |
| 237 | 247 |
| 238 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUpdatePermission( | 248 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUpdatePermission( |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 break; | 421 break; |
| 412 } | 422 } |
| 413 } | 423 } |
| 414 | 424 |
| 415 void EnterpriseEnrollmentHelperImpl::UMA(policy::MetricEnrollment sample) { | 425 void EnterpriseEnrollmentHelperImpl::UMA(policy::MetricEnrollment sample) { |
| 416 EnrollmentUMA(sample, enrollment_config_.mode); | 426 EnrollmentUMA(sample, enrollment_config_.mode); |
| 417 } | 427 } |
| 418 | 428 |
| 419 void EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared( | 429 void EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared( |
| 420 const base::Closure& callback) { | 430 const base::Closure& callback) { |
| 421 auth_data_cleared_ = true; | 431 oauth_data_cleared_ = true; |
| 422 callback.Run(); | 432 callback.Run(); |
| 423 } | 433 } |
| 424 | 434 |
| 425 } // namespace chromeos | 435 } // namespace chromeos |
| OLD | NEW |