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

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

Powered by Google App Engine
This is Rietveld 408576698