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
3 // found in the LICENSE file.
5 #include "chromeos/login/auth/stub_authenticator.h"
8 #include "base/location.h"
9 #include "base/logging.h"
10 #include "base/thread_task_runner_handle.h"
16 // As defined in /chromeos/dbus/cryptohome_client.cc.
17 static const char kUserIdHashSuffix
[] = "-hash";
19 } // anonymous namespace
21 StubAuthenticator::StubAuthenticator(AuthStatusConsumer
* consumer
,
22 const UserContext
& expected_user_context
)
23 : Authenticator(consumer
),
24 expected_user_context_(expected_user_context
),
25 task_runner_(base::ThreadTaskRunnerHandle::Get()) {
28 void StubAuthenticator::CompleteLogin(content::BrowserContext
* context
,
29 const UserContext
& user_context
) {
30 authentication_context_
= context
;
31 if (expected_user_context_
!= user_context
)
36 void StubAuthenticator::AuthenticateToLogin(content::BrowserContext
* context
,
37 const UserContext
& user_context
) {
38 authentication_context_
= context
;
39 // Don't compare the entire |expected_user_context_| to |user_context| because
40 // during non-online re-auth |user_context| does not have a gaia id.
41 if (expected_user_context_
.GetUserID() == user_context
.GetUserID() &&
42 *expected_user_context_
.GetKey() == *user_context
.GetKey()) {
43 task_runner_
->PostTask(FROM_HERE
,
44 base::Bind(&StubAuthenticator::OnAuthSuccess
, this));
47 GoogleServiceAuthError
error(
48 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS
);
49 task_runner_
->PostTask(
50 FROM_HERE
, base::Bind(&StubAuthenticator::OnAuthFailure
, this,
51 AuthFailure::FromNetworkAuthFailure(error
)));
54 void StubAuthenticator::AuthenticateToUnlock(const UserContext
& user_context
) {
55 AuthenticateToLogin(NULL
/* not used */, user_context
);
58 void StubAuthenticator::LoginAsSupervisedUser(const UserContext
& user_context
) {
59 UserContext new_user_context
= user_context
;
60 new_user_context
.SetUserIDHash(user_context
.GetUserID() + kUserIdHashSuffix
);
61 consumer_
->OnAuthSuccess(new_user_context
);
64 void StubAuthenticator::LoginOffTheRecord() {
65 consumer_
->OnOffTheRecordAuthSuccess();
68 void StubAuthenticator::LoginAsPublicSession(const UserContext
& user_context
) {
69 UserContext logged_in_user_context
= user_context
;
70 logged_in_user_context
.SetIsUsingOAuth(false);
71 logged_in_user_context
.SetUserIDHash(logged_in_user_context
.GetUserID() +
73 consumer_
->OnAuthSuccess(logged_in_user_context
);
76 void StubAuthenticator::LoginAsKioskAccount(const std::string
& app_user_id
,
77 bool use_guest_mount
) {
78 UserContext
user_context(expected_user_context_
.GetUserID());
79 user_context
.SetIsUsingOAuth(false);
80 user_context
.SetUserIDHash(expected_user_context_
.GetUserID() +
82 consumer_
->OnAuthSuccess(user_context
);
85 void StubAuthenticator::OnAuthSuccess() {
86 // If we want to be more like the real thing, we could save the user ID
87 // in AuthenticateToLogin, but there's not much of a point.
88 UserContext
user_context(expected_user_context_
);
89 user_context
.SetUserIDHash(expected_user_context_
.GetUserID() +
91 consumer_
->OnAuthSuccess(user_context
);
94 void StubAuthenticator::OnAuthFailure(const AuthFailure
& failure
) {
95 consumer_
->OnAuthFailure(failure
);
98 void StubAuthenticator::RecoverEncryptedData(const std::string
& old_password
) {
101 void StubAuthenticator::ResyncEncryptedData() {
104 void StubAuthenticator::SetExpectedCredentials(
105 const UserContext
& user_context
) {
106 expected_user_context_
= user_context
;
109 StubAuthenticator::~StubAuthenticator() {
112 } // namespace chromeos