OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "chromeos/login/auth/stub_authenticator.h" | 5 #include "chromeos/login/auth/stub_authenticator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 if (expected_user_context_ != user_context) | 31 if (expected_user_context_ != user_context) |
32 NOTREACHED(); | 32 NOTREACHED(); |
33 OnAuthSuccess(); | 33 OnAuthSuccess(); |
34 } | 34 } |
35 | 35 |
36 void StubAuthenticator::AuthenticateToLogin(content::BrowserContext* context, | 36 void StubAuthenticator::AuthenticateToLogin(content::BrowserContext* context, |
37 const UserContext& user_context) { | 37 const UserContext& user_context) { |
38 authentication_context_ = context; | 38 authentication_context_ = context; |
39 // Don't compare the entire |expected_user_context_| to |user_context| because | 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. | 40 // during non-online re-auth |user_context| does not have a gaia id. |
41 if (expected_user_context_.GetAccountId() == user_context.GetAccountId() && | 41 if (expected_user_context_.GetUserID() == user_context.GetUserID() && |
42 *expected_user_context_.GetKey() == *user_context.GetKey()) { | 42 *expected_user_context_.GetKey() == *user_context.GetKey()) { |
43 task_runner_->PostTask(FROM_HERE, | 43 task_runner_->PostTask(FROM_HERE, |
44 base::Bind(&StubAuthenticator::OnAuthSuccess, this)); | 44 base::Bind(&StubAuthenticator::OnAuthSuccess, this)); |
45 return; | 45 return; |
46 } | 46 } |
47 GoogleServiceAuthError error( | 47 GoogleServiceAuthError error( |
48 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 48 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
49 task_runner_->PostTask( | 49 task_runner_->PostTask( |
50 FROM_HERE, base::Bind(&StubAuthenticator::OnAuthFailure, this, | 50 FROM_HERE, base::Bind(&StubAuthenticator::OnAuthFailure, this, |
51 AuthFailure::FromNetworkAuthFailure(error))); | 51 AuthFailure::FromNetworkAuthFailure(error))); |
52 } | 52 } |
53 | 53 |
54 void StubAuthenticator::AuthenticateToUnlock(const UserContext& user_context) { | 54 void StubAuthenticator::AuthenticateToUnlock(const UserContext& user_context) { |
55 AuthenticateToLogin(NULL /* not used */, user_context); | 55 AuthenticateToLogin(NULL /* not used */, user_context); |
56 } | 56 } |
57 | 57 |
58 void StubAuthenticator::LoginAsSupervisedUser(const UserContext& user_context) { | 58 void StubAuthenticator::LoginAsSupervisedUser(const UserContext& user_context) { |
59 UserContext new_user_context = user_context; | 59 UserContext new_user_context = user_context; |
60 new_user_context.SetUserIDHash(user_context.GetAccountId().GetUserEmail() + | 60 new_user_context.SetUserIDHash(user_context.GetUserID() + kUserIdHashSuffix); |
61 kUserIdHashSuffix); | |
62 consumer_->OnAuthSuccess(new_user_context); | 61 consumer_->OnAuthSuccess(new_user_context); |
63 } | 62 } |
64 | 63 |
65 void StubAuthenticator::LoginOffTheRecord() { | 64 void StubAuthenticator::LoginOffTheRecord() { |
66 consumer_->OnOffTheRecordAuthSuccess(); | 65 consumer_->OnOffTheRecordAuthSuccess(); |
67 } | 66 } |
68 | 67 |
69 void StubAuthenticator::LoginAsPublicSession(const UserContext& user_context) { | 68 void StubAuthenticator::LoginAsPublicSession(const UserContext& user_context) { |
70 UserContext logged_in_user_context = user_context; | 69 UserContext logged_in_user_context = user_context; |
71 logged_in_user_context.SetIsUsingOAuth(false); | 70 logged_in_user_context.SetIsUsingOAuth(false); |
72 logged_in_user_context.SetUserIDHash( | 71 logged_in_user_context.SetUserIDHash(logged_in_user_context.GetUserID() + |
73 logged_in_user_context.GetAccountId().GetUserEmail() + kUserIdHashSuffix); | 72 kUserIdHashSuffix); |
74 consumer_->OnAuthSuccess(logged_in_user_context); | 73 consumer_->OnAuthSuccess(logged_in_user_context); |
75 } | 74 } |
76 | 75 |
77 void StubAuthenticator::LoginAsKioskAccount( | 76 void StubAuthenticator::LoginAsKioskAccount(const std::string& app_user_id, |
78 const std::string& /* app_user_id */, | 77 bool use_guest_mount) { |
79 bool use_guest_mount) { | 78 UserContext user_context(expected_user_context_.GetUserID()); |
80 UserContext user_context(expected_user_context_.GetAccountId()); | |
81 user_context.SetIsUsingOAuth(false); | 79 user_context.SetIsUsingOAuth(false); |
82 user_context.SetUserIDHash( | 80 user_context.SetUserIDHash(expected_user_context_.GetUserID() + |
83 expected_user_context_.GetAccountId().GetUserEmail() + kUserIdHashSuffix); | 81 kUserIdHashSuffix); |
84 consumer_->OnAuthSuccess(user_context); | 82 consumer_->OnAuthSuccess(user_context); |
85 } | 83 } |
86 | 84 |
87 void StubAuthenticator::OnAuthSuccess() { | 85 void StubAuthenticator::OnAuthSuccess() { |
88 // If we want to be more like the real thing, we could save the user ID | 86 // If we want to be more like the real thing, we could save the user ID |
89 // in AuthenticateToLogin, but there's not much of a point. | 87 // in AuthenticateToLogin, but there's not much of a point. |
90 UserContext user_context(expected_user_context_); | 88 UserContext user_context(expected_user_context_); |
91 user_context.SetUserIDHash( | 89 user_context.SetUserIDHash(expected_user_context_.GetUserID() + |
92 expected_user_context_.GetAccountId().GetUserEmail() + kUserIdHashSuffix); | 90 kUserIdHashSuffix); |
93 consumer_->OnAuthSuccess(user_context); | 91 consumer_->OnAuthSuccess(user_context); |
94 } | 92 } |
95 | 93 |
96 void StubAuthenticator::OnAuthFailure(const AuthFailure& failure) { | 94 void StubAuthenticator::OnAuthFailure(const AuthFailure& failure) { |
97 consumer_->OnAuthFailure(failure); | 95 consumer_->OnAuthFailure(failure); |
98 } | 96 } |
99 | 97 |
100 void StubAuthenticator::RecoverEncryptedData(const std::string& old_password) { | 98 void StubAuthenticator::RecoverEncryptedData(const std::string& old_password) { |
101 } | 99 } |
102 | 100 |
103 void StubAuthenticator::ResyncEncryptedData() { | 101 void StubAuthenticator::ResyncEncryptedData() { |
104 } | 102 } |
105 | 103 |
106 void StubAuthenticator::SetExpectedCredentials( | 104 void StubAuthenticator::SetExpectedCredentials( |
107 const UserContext& user_context) { | 105 const UserContext& user_context) { |
108 expected_user_context_ = user_context; | 106 expected_user_context_ = user_context; |
109 } | 107 } |
110 | 108 |
111 StubAuthenticator::~StubAuthenticator() { | 109 StubAuthenticator::~StubAuthenticator() { |
112 } | 110 } |
113 | 111 |
114 } // namespace chromeos | 112 } // namespace chromeos |
OLD | NEW |