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 if (user_context
== expected_user_context_
) {
39 message_loop_
->PostTask(
40 FROM_HERE
, base::Bind(&StubAuthenticator::OnAuthSuccess
, this));
43 GoogleServiceAuthError
error(
44 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS
);
45 message_loop_
->PostTask(
46 FROM_HERE
, base::Bind(&StubAuthenticator::OnAuthFailure
, this,
47 AuthFailure::FromNetworkAuthFailure(error
)));
50 void StubAuthenticator::AuthenticateToUnlock(const UserContext
& user_context
) {
51 AuthenticateToLogin(NULL
/* not used */, user_context
);
54 void StubAuthenticator::LoginAsSupervisedUser(const UserContext
& user_context
) {
55 UserContext new_user_context
= user_context
;
56 new_user_context
.SetUserIDHash(user_context
.GetUserID() + kUserIdHashSuffix
);
57 consumer_
->OnAuthSuccess(new_user_context
);
60 void StubAuthenticator::LoginOffTheRecord() {
61 consumer_
->OnOffTheRecordAuthSuccess();
64 void StubAuthenticator::LoginAsPublicSession(const UserContext
& user_context
) {
65 UserContext logged_in_user_context
= user_context
;
66 logged_in_user_context
.SetIsUsingOAuth(false);
67 logged_in_user_context
.SetUserIDHash(logged_in_user_context
.GetUserID() +
69 consumer_
->OnAuthSuccess(logged_in_user_context
);
72 void StubAuthenticator::LoginAsKioskAccount(const std::string
& app_user_id
,
73 bool use_guest_mount
) {
74 UserContext
user_context(expected_user_context_
.GetUserID());
75 user_context
.SetIsUsingOAuth(false);
76 user_context
.SetUserIDHash(expected_user_context_
.GetUserID() +
78 consumer_
->OnAuthSuccess(user_context
);
81 void StubAuthenticator::OnAuthSuccess() {
82 // If we want to be more like the real thing, we could save the user ID
83 // in AuthenticateToLogin, but there's not much of a point.
84 UserContext
user_context(expected_user_context_
);
85 user_context
.SetUserIDHash(expected_user_context_
.GetUserID() +
87 consumer_
->OnAuthSuccess(user_context
);
90 void StubAuthenticator::OnAuthFailure(const AuthFailure
& failure
) {
91 consumer_
->OnAuthFailure(failure
);
94 void StubAuthenticator::RecoverEncryptedData(const std::string
& old_password
) {
97 void StubAuthenticator::ResyncEncryptedData() {
100 void StubAuthenticator::SetExpectedCredentials(
101 const UserContext
& user_context
) {
102 expected_user_context_
= user_context
;
105 StubAuthenticator::~StubAuthenticator() {
108 } // namespace chromeos