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

Side by Side Diff: chrome/browser/chromeos/arc/arc_auth_service.cc

Issue 2655873002: Get enrollment token from DMServer when an Active Directory user uses ARC (Closed)
Patch Set: Fix Luis's comments Created 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/arc/arc_auth_service.h" 5 #include "chrome/browser/chromeos/arc/arc_auth_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
12 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" 11 #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
13 #include "chrome/browser/chromeos/arc/arc_session_manager.h" 12 #include "chrome/browser/chromeos/arc/arc_session_manager.h"
14 #include "chrome/browser/chromeos/arc/auth/arc_auth_code_fetcher.h" 13 #include "chrome/browser/chromeos/arc/auth/arc_active_directory_enrollment_token _fetcher.h"
14 #include "chrome/browser/chromeos/arc/auth/arc_auth_info_fetcher.h"
15 #include "chrome/browser/chromeos/arc/auth/arc_background_auth_code_fetcher.h" 15 #include "chrome/browser/chromeos/arc/auth/arc_background_auth_code_fetcher.h"
16 #include "chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.h" 16 #include "chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.h"
17 #include "chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher.h" 17 #include "chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher.h"
18 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" 18 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h"
19 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/lifetime/application_lifetime.h" 20 #include "chrome/browser/lifetime/application_lifetime.h"
20 #include "chromeos/chromeos_switches.h" 21 #include "chromeos/chromeos_switches.h"
21 #include "components/arc/arc_bridge_service.h" 22 #include "components/arc/arc_bridge_service.h"
22 #include "components/arc/arc_features.h" 23 #include "components/arc/arc_features.h"
23 #include "components/arc/arc_util.h" 24 #include "components/arc/arc_util.h"
25 #include "components/user_manager/user_manager.h"
24 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
25 27
26 namespace arc { 28 namespace arc {
27 namespace { 29 namespace {
28 30
29 ArcAuthService* g_arc_auth_service = nullptr; 31 ArcAuthService* g_arc_auth_service = nullptr;
30 32
31 // Convers mojom::ArcSignInFailureReason into ProvisiningResult. 33 // Convers mojom::ArcSignInFailureReason into ProvisiningResult.
32 ProvisioningResult ConvertArcSignInFailureReasonToProvisioningResult( 34 ProvisioningResult ConvertArcSignInFailureReasonToProvisioningResult(
33 mojom::ArcSignInFailureReason reason) { 35 mojom::ArcSignInFailureReason reason) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 explicit AccountInfoNotifier( 81 explicit AccountInfoNotifier(
80 const GetAuthCodeAndAccountTypeDeprecatedCallback& auth_account_callback) 82 const GetAuthCodeAndAccountTypeDeprecatedCallback& auth_account_callback)
81 : callback_type_(CallbackType::AUTH_CODE_AND_ACCOUNT), 83 : callback_type_(CallbackType::AUTH_CODE_AND_ACCOUNT),
82 auth_account_callback_(auth_account_callback) {} 84 auth_account_callback_(auth_account_callback) {}
83 85
84 explicit AccountInfoNotifier(const AccountInfoCallback& account_info_callback) 86 explicit AccountInfoNotifier(const AccountInfoCallback& account_info_callback)
85 : callback_type_(CallbackType::ACCOUNT_INFO), 87 : callback_type_(CallbackType::ACCOUNT_INFO),
86 account_info_callback_(account_info_callback) {} 88 account_info_callback_(account_info_callback) {}
87 89
88 void Notify(bool is_enforced, 90 void Notify(bool is_enforced,
89 const std::string& auth_code, 91 const std::string& auth_info,
90 mojom::ChromeAccountType account_type, 92 mojom::ChromeAccountType account_type,
91 bool is_managed) { 93 bool is_managed) {
92 switch (callback_type_) { 94 switch (callback_type_) {
93 case CallbackType::AUTH_CODE: 95 case CallbackType::AUTH_CODE:
94 DCHECK(!auth_callback_.is_null()); 96 DCHECK(!auth_callback_.is_null());
95 auth_callback_.Run(auth_code, is_enforced); 97 auth_callback_.Run(auth_info, is_enforced);
96 break; 98 break;
97 case CallbackType::AUTH_CODE_AND_ACCOUNT: 99 case CallbackType::AUTH_CODE_AND_ACCOUNT:
98 DCHECK(!auth_account_callback_.is_null()); 100 DCHECK(!auth_account_callback_.is_null());
99 auth_account_callback_.Run(auth_code, is_enforced, account_type); 101 auth_account_callback_.Run(auth_info, is_enforced, account_type);
100 break; 102 break;
101 case CallbackType::ACCOUNT_INFO: 103 case CallbackType::ACCOUNT_INFO:
102 DCHECK(!account_info_callback_.is_null()); 104 DCHECK(!account_info_callback_.is_null());
103 mojom::AccountInfoPtr account_info = mojom::AccountInfo::New(); 105 mojom::AccountInfoPtr account_info = mojom::AccountInfo::New();
104 if (!is_enforced) { 106 if (account_type ==
105 account_info->auth_code = base::nullopt; 107 mojom::ChromeAccountType::ACTIVE_DIRECTORY_ACCOUNT) {
108 account_info->enrollment_token = auth_info;
106 } else { 109 } else {
107 account_info->auth_code = auth_code; 110 if (!is_enforced)
111 account_info->auth_code = base::nullopt;
112 else
113 account_info->auth_code = auth_info;
108 } 114 }
109 account_info->account_type = account_type; 115 account_info->account_type = account_type;
110 account_info->is_managed = is_managed; 116 account_info->is_managed = is_managed;
111 account_info_callback_.Run(std::move(account_info)); 117 account_info_callback_.Run(std::move(account_info));
112 break; 118 break;
113 } 119 }
114 } 120 }
115 121
116 private: 122 private:
117 enum class CallbackType { AUTH_CODE, AUTH_CODE_AND_ACCOUNT, ACCOUNT_INFO }; 123 enum class CallbackType { AUTH_CODE, AUTH_CODE_AND_ACCOUNT, ACCOUNT_INFO };
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 if (IsArcOptInVerificationDisabled()) { 222 if (IsArcOptInVerificationDisabled()) {
217 notifier->Notify( 223 notifier->Notify(
218 false /* = is_enforced */, std::string(), GetAccountType(), 224 false /* = is_enforced */, std::string(), GetAccountType(),
219 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); 225 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile()));
220 return; 226 return;
221 } 227 }
222 228
223 // Hereafter asynchronous operation. Remember the notifier. 229 // Hereafter asynchronous operation. Remember the notifier.
224 notifier_ = std::move(notifier); 230 notifier_ = std::move(notifier);
225 231
232 Profile* profile = ArcSessionManager::Get()->profile();
233 const user_manager::User* user = nullptr;
234 if (profile)
235 user = chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
236 if (user && user->IsActiveDirectoryUser()) {
237 // For Active Directory enrolled devices, we get an enrollment token for a
238 // managed Google Play account from DMServer.
239 fetcher_ = base::MakeUnique<ArcActiveDirectoryEnrollmentTokenFetcher>();
240 fetcher_->Fetch(base::Bind(&ArcAuthService::OnEnrollmentTokenFetched,
241 weak_ptr_factory_.GetWeakPtr()));
242 return;
243 }
244 // For non-AD enrolled devices an auth code is fetched.
226 if (IsArcKioskMode()) { 245 if (IsArcKioskMode()) {
227 // In Kiosk mode, use Robot auth code fetching. 246 // In Kiosk mode, use Robot auth code fetching.
228 fetcher_ = base::MakeUnique<ArcRobotAuthCodeFetcher>(); 247 fetcher_ = base::MakeUnique<ArcRobotAuthCodeFetcher>();
229 } else if (base::FeatureList::IsEnabled(arc::kArcUseAuthEndpointFeature)) { 248 } else if (base::FeatureList::IsEnabled(arc::kArcUseAuthEndpointFeature)) {
230 // Optionally retrieve auth code in silent mode. 249 // Optionally retrieve auth code in silent mode.
250 DCHECK(profile);
231 fetcher_ = base::MakeUnique<ArcBackgroundAuthCodeFetcher>( 251 fetcher_ = base::MakeUnique<ArcBackgroundAuthCodeFetcher>(
232 ArcSessionManager::Get()->profile(), 252 profile, ArcSessionManager::Get()->auth_context());
233 ArcSessionManager::Get()->auth_context());
234 } else { 253 } else {
235 // Report that silent auth code is not activated. All other states are 254 // Report that silent auth code is not activated. All other states are
236 // reported in ArcBackgroundAuthCodeFetcher. 255 // reported in ArcBackgroundAuthCodeFetcher.
237 UpdateSilentAuthCodeUMA(OptInSilentAuthCode::DISABLED); 256 UpdateSilentAuthCodeUMA(OptInSilentAuthCode::DISABLED);
238 // Otherwise, show LSO page and let user click "Sign in" button. 257 // Otherwise, show LSO page and let user click "Sign in" button.
239 // Here, support_host should be available always. The case support_host is 258 // Here, support_host should be available always. The case support_host is
240 // not created is when 1) IsArcOptInVerificationDisabled() is true or 2) 259 // not created is when 1) IsArcOptInVerificationDisabled() is true or 2)
241 // IsArcKioskMode() is true. Both cases are handled above. 260 // IsArcKioskMode() is true. Both cases are handled above.
242 fetcher_ = base::MakeUnique<ArcManualAuthCodeFetcher>( 261 fetcher_ = base::MakeUnique<ArcManualAuthCodeFetcher>(
243 ArcSessionManager::Get()->auth_context(), 262 ArcSessionManager::Get()->auth_context(),
244 ArcSessionManager::Get()->support_host()); 263 ArcSessionManager::Get()->support_host());
245 } 264 }
246 fetcher_->Fetch(base::Bind(&ArcAuthService::OnAuthCodeFetched, 265 fetcher_->Fetch(base::Bind(&ArcAuthService::OnAuthCodeFetched,
247 weak_ptr_factory_.GetWeakPtr())); 266 weak_ptr_factory_.GetWeakPtr()));
248 } 267 }
249 268
269 void ArcAuthService::OnEnrollmentTokenFetched(
270 const std::string& enrollment_token) {
271 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
272 fetcher_.reset();
273
274 if (enrollment_token.empty()) {
275 ArcSessionManager::Get()->OnProvisioningFinished(
276 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR);
277 return;
278 }
279
280 notifier_->Notify(true /*is_enforced*/, enrollment_token,
281 mojom::ChromeAccountType::ACTIVE_DIRECTORY_ACCOUNT, true);
282 notifier_.reset();
283 }
284
250 void ArcAuthService::OnAuthCodeFetched(const std::string& auth_code) { 285 void ArcAuthService::OnAuthCodeFetched(const std::string& auth_code) {
251 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 286 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
252 fetcher_.reset(); 287 fetcher_.reset();
253 288
254 if (auth_code.empty()) { 289 if (auth_code.empty()) {
255 ArcSessionManager::Get()->OnProvisioningFinished( 290 ArcSessionManager::Get()->OnProvisioningFinished(
256 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); 291 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR);
257 return; 292 return;
258 } 293 }
259 294
260 notifier_->Notify( 295 notifier_->Notify(
261 !IsArcOptInVerificationDisabled(), auth_code, GetAccountType(), 296 !IsArcOptInVerificationDisabled(), auth_code, GetAccountType(),
262 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); 297 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile()));
263 notifier_.reset(); 298 notifier_.reset();
264 } 299 }
265 300
266 } // namespace arc 301 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.h ('k') | chrome/browser/chromeos/arc/arc_session_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698