Move action_runner.py out of actions folder prior to moving actions to internal.
[chromium-blink-merge.git] / chromeos / login / auth / login_performer.h
blob0f81d04057b1d88a58329693ab8e3cea4387f6f6
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 #ifndef CHROMEOS_LOGIN_AUTH_LOGIN_PERFORMER_H_
6 #define CHROMEOS_LOGIN_AUTH_LOGIN_PERFORMER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/login/auth/auth_status_consumer.h"
16 #include "chromeos/login/auth/authenticator.h"
17 #include "chromeos/login/auth/extended_authenticator.h"
18 #include "chromeos/login/auth/online_attempt_host.h"
19 #include "chromeos/login/auth/user_context.h"
20 #include "google_apis/gaia/google_service_auth_error.h"
22 namespace net {
23 class URLRequestContextGetter;
26 namespace policy {
27 class WildcardLoginChecker;
30 namespace content {
31 class BrowserContext;
34 namespace chromeos {
36 // This class encapsulates sign in operations.
37 // Sign in is performed in a way that offline auth is executed first.
38 // Once offline auth is OK - user homedir is mounted, UI is launched.
39 // At this point LoginPerformer |delegate_| is destroyed and it releases
40 // LP instance ownership. LP waits for online login result.
41 // If auth is succeeded, cookie fetcher is executed, LP instance deletes itself.
43 // If |delegate_| is not NULL it will handle error messages, password input.
44 class CHROMEOS_EXPORT LoginPerformer : public AuthStatusConsumer,
45 public OnlineAttemptHost::Delegate {
46 public:
47 typedef enum AuthorizationMode {
48 // Authorization performed internally by Chrome.
49 AUTH_MODE_INTERNAL,
50 // Authorization performed by an extension.
51 AUTH_MODE_EXTENSION
52 } AuthorizationMode;
54 // Delegate class to get notifications from the LoginPerformer.
55 class Delegate : public AuthStatusConsumer {
56 public:
57 ~Delegate() override {}
58 virtual void WhiteListCheckFailed(const std::string& email) = 0;
59 virtual void PolicyLoadFailed() = 0;
60 virtual void OnOnlineChecked(const std::string& email, bool success) = 0;
63 LoginPerformer(scoped_refptr<base::TaskRunner> task_runner,
64 Delegate* delegate);
65 ~LoginPerformer() override;
67 // Performs a login for |user_context|.
68 // If auth_mode is AUTH_MODE_EXTENSION, there are no further auth checks,
69 // AUTH_MODE_INTERNAL will perform auth checks.
70 void PerformLogin(const UserContext& user_context,
71 AuthorizationMode auth_mode);
73 // Performs supervised user login with a given |user_context|.
74 void LoginAsSupervisedUser(const UserContext& user_context);
76 // Performs actions to prepare guest mode login.
77 void LoginOffTheRecord();
79 // Performs public session login with a given |user_context|.
80 void LoginAsPublicSession(const UserContext& user_context);
82 // Performs a login into the kiosk mode account with |app_user_id|.
83 void LoginAsKioskAccount(const std::string& app_user_id,
84 bool use_guest_mount);
86 // AuthStatusConsumer implementation:
87 void OnAuthFailure(const AuthFailure& error) override;
88 void OnAuthSuccess(const UserContext& user_context) override;
89 void OnOffTheRecordAuthSuccess() override;
90 void OnPasswordChangeDetected() override;
92 // Migrates cryptohome using |old_password| specified.
93 void RecoverEncryptedData(const std::string& old_password);
95 // Reinitializes cryptohome with the new password.
96 void ResyncEncryptedData();
98 // Returns latest auth error.
99 const GoogleServiceAuthError& error() const {
100 return last_login_failure_.error();
103 // True if password change has been detected.
104 bool password_changed() { return password_changed_; }
106 // Number of times we've been called with OnPasswordChangeDetected().
107 // If user enters incorrect old password, same LoginPerformer instance will
108 // be called so callback count makes it possible to distinguish initial
109 // "password changed detected" event from further attempts to enter old
110 // password for cryptohome migration (when > 1).
111 int password_changed_callback_count() {
112 return password_changed_callback_count_;
115 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
117 AuthorizationMode auth_mode() const { return auth_mode_; }
119 protected:
120 // Implements OnlineAttemptHost::Delegate.
121 void OnChecked(const std::string& user_id, bool success) override;
123 // Platform-dependant methods to be implemented by concrete class.
125 // Run trusted check for a platform. If trusted check have to be performed
126 // asynchronously, |false| will be returned, and either delegate's
127 // PolicyLoadFailed() or |callback| will be called upon actual check.
128 virtual bool RunTrustedCheck(const base::Closure& callback) = 0;
130 // Check if user is allowed to sign in on device. |wildcard_match| will
131 // contain additional information whether this user is explicitly listed or
132 // not (may be relevant for extension-based sign-in).
133 virtual bool IsUserWhitelisted(const std::string& user_id,
134 bool* wildcard_match) = 0;
136 // This method should run addional online check if user can sign in on device.
137 // Either |success_callback| or |failure_callback| should be called upon this
138 // check.
139 virtual void RunOnlineWhitelistCheck(
140 const std::string& user_id,
141 bool wildcard_match,
142 const base::Closure& success_callback,
143 const base::Closure& failure_callback) = 0;
145 // Supervised users-related methods.
147 // Check if supervised users are allowed on this device.
148 virtual bool AreSupervisedUsersAllowed() = 0;
150 // Check which authenticator should be used for supervised user.
151 virtual bool UseExtendedAuthenticatorForSupervisedUser(
152 const UserContext& user_context) = 0;
154 // Probably transform supervised user's authentication key.
155 virtual UserContext TransformSupervisedKey(const UserContext& context) = 0;
157 // Set up sign-in flow for supervised user.
158 virtual void SetupSupervisedUserFlow(const std::string& user_id) = 0;
160 // Set up sign-in flow for Easy Unlock.
161 virtual void SetupEasyUnlockUserFlow(const std::string& user_id) = 0;
163 // Run policy check for |user_id|. If something is wrong, delegate's
164 // PolicyLoadFailed is called.
165 virtual bool CheckPolicyForUser(const std::string& user_id) = 0;
167 // Look up browser context to use during signin.
168 virtual content::BrowserContext* GetSigninContext() = 0;
170 // Get RequestContext used for sign in.
171 virtual net::URLRequestContextGetter* GetSigninRequestContext() = 0;
173 // Create authenticator implementation.
174 virtual scoped_refptr<Authenticator> CreateAuthenticator() = 0;
176 void set_authenticator(scoped_refptr<Authenticator> authenticator);
178 // Notifications receiver.
179 Delegate* delegate_;
181 private:
182 // Starts login completion of externally authenticated user.
183 void StartLoginCompletion();
185 // Starts authentication.
186 void StartAuthentication();
187 void NotifyWhitelistCheckFailure();
189 // Makes sure that authenticator is created.
190 void EnsureAuthenticator();
191 void EnsureExtendedAuthenticator();
193 // Actual implementation of LoginAsSupervisedUser that is run after trusted
194 // values check.
195 void TrustedLoginAsSupervisedUser(const UserContext& user_context);
197 // Actual implementantion of PeformLogin that is run after trusted values
198 // check.
199 void DoPerformLogin(const UserContext& user_context,
200 AuthorizationMode auth_mode);
202 scoped_refptr<base::TaskRunner> task_runner_;
204 // Used for logging in.
205 scoped_refptr<Authenticator> authenticator_;
207 // Used for logging in.
208 scoped_refptr<ExtendedAuthenticator> extended_authenticator_;
210 // Used to make auxiliary online check.
211 OnlineAttemptHost online_attempt_host_;
213 // Represents last login failure that was encountered when communicating to
214 // sign-in server. AuthFailure.LoginFailureNone() by default.
215 AuthFailure last_login_failure_;
217 // User credentials for the current login attempt.
218 UserContext user_context_;
220 // True if password change has been detected.
221 // Once correct password is entered homedir migration is executed.
222 bool password_changed_;
223 int password_changed_callback_count_;
225 // Authorization mode type.
226 AuthorizationMode auth_mode_;
228 base::WeakPtrFactory<LoginPerformer> weak_factory_;
229 DISALLOW_COPY_AND_ASSIGN(LoginPerformer);
232 } // namespace chromeos
234 #endif // CHROMEOS_LOGIN_AUTH_LOGIN_PERFORMER_H_