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"
15 // As defined in /chromeos/dbus/cryptohome_client.cc.
16 static const char kUserIdHashSuffix
[] = "-hash";
18 } // anonymous namespace
20 StubAuthenticator::StubAuthenticator(AuthStatusConsumer
* consumer
,
21 const UserContext
& expected_user_context
)
22 : Authenticator(consumer
),
23 expected_user_context_(expected_user_context
),
24 message_loop_(base::MessageLoopProxy::current()) {
27 void StubAuthenticator::CompleteLogin(content::BrowserContext
* context
,
28 const UserContext
& user_context
) {
29 authentication_context_
= context
;
30 if (expected_user_context_
!= user_context
)
35 void StubAuthenticator::AuthenticateToLogin(content::BrowserContext
* context
,
36 const UserContext
& user_context
) {
37 authentication_context_
= context
;
38 // Don't compare the entire |expected_user_context_| to |user_context| because
39 // during non-online re-auth |user_context| does not have a gaia id.
40 if (expected_user_context_
.GetUserID() == user_context
.GetUserID() &&
41 *expected_user_context_
.GetKey() == *user_context
.GetKey()) {
42 message_loop_
->PostTask(
43 FROM_HERE
, base::Bind(&StubAuthenticator::OnAuthSuccess
, this));
46 GoogleServiceAuthError
error(
47 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS
);
48 message_loop_
->PostTask(
49 FROM_HERE
, base::Bind(&StubAuthenticator::OnAuthFailure
, this,
50 AuthFailure::FromNetworkAuthFailure(error
)));
53 void StubAuthenticator::AuthenticateToUnlock(const UserContext
& user_context
) {
54 AuthenticateToLogin(NULL
/* not used */, user_context
);
57 void StubAuthenticator::LoginAsSupervisedUser(const UserContext
& user_context
) {
58 UserContext new_user_context
= user_context
;
59 new_user_context
.SetUserIDHash(user_context
.GetUserID() + kUserIdHashSuffix
);
60 consumer_
->OnAuthSuccess(new_user_context
);
63 void StubAuthenticator::LoginOffTheRecord() {
64 consumer_
->OnOffTheRecordAuthSuccess();
67 void StubAuthenticator::LoginAsPublicSession(const UserContext
& user_context
) {
68 UserContext logged_in_user_context
= user_context
;
69 logged_in_user_context
.SetIsUsingOAuth(false);
70 logged_in_user_context
.SetUserIDHash(logged_in_user_context
.GetUserID() +
72 consumer_
->OnAuthSuccess(logged_in_user_context
);
75 void StubAuthenticator::LoginAsKioskAccount(const std::string
& app_user_id
,
76 bool use_guest_mount
) {
77 UserContext
user_context(expected_user_context_
.GetUserID());
78 user_context
.SetIsUsingOAuth(false);
79 user_context
.SetUserIDHash(expected_user_context_
.GetUserID() +
81 consumer_
->OnAuthSuccess(user_context
);
84 void StubAuthenticator::OnAuthSuccess() {
85 // If we want to be more like the real thing, we could save the user ID
86 // in AuthenticateToLogin, but there's not much of a point.
87 UserContext
user_context(expected_user_context_
);
88 user_context
.SetUserIDHash(expected_user_context_
.GetUserID() +
90 consumer_
->OnAuthSuccess(user_context
);
93 void StubAuthenticator::OnAuthFailure(const AuthFailure
& failure
) {
94 consumer_
->OnAuthFailure(failure
);
97 void StubAuthenticator::RecoverEncryptedData(const std::string
& old_password
) {
100 void StubAuthenticator::ResyncEncryptedData() {
103 void StubAuthenticator::SetExpectedCredentials(
104 const UserContext
& user_context
) {
105 expected_user_context_
= user_context
;
108 StubAuthenticator::~StubAuthenticator() {
111 } // namespace chromeos