Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: chromeos/login/auth/login_performer.h

Issue 614973002: Extract LoginPerformer to chromeos/auth (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_LOGIN_PERFORMER_H_ 5 #ifndef CHROMEOS_LOGIN_AUTH_LOGIN_PERFORMER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_LOGIN_PERFORMER_H_ 6 #define CHROMEOS_LOGIN_AUTH_LOGIN_PERFORMER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/chromeos/policy/wildcard_login_checker.h" 14 #include "chromeos/chromeos_export.h"
14 #include "chromeos/login/auth/auth_status_consumer.h" 15 #include "chromeos/login/auth/auth_status_consumer.h"
15 #include "chromeos/login/auth/authenticator.h" 16 #include "chromeos/login/auth/authenticator.h"
16 #include "chromeos/login/auth/extended_authenticator.h" 17 #include "chromeos/login/auth/extended_authenticator.h"
17 #include "chromeos/login/auth/online_attempt_host.h" 18 #include "chromeos/login/auth/online_attempt_host.h"
18 #include "chromeos/login/auth/user_context.h" 19 #include "chromeos/login/auth/user_context.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "google_apis/gaia/google_service_auth_error.h" 20 #include "google_apis/gaia/google_service_auth_error.h"
22 21
22 namespace net {
23 class URLRequestContextGetter;
24 }
25
23 namespace policy { 26 namespace policy {
24 class WildcardLoginChecker; 27 class WildcardLoginChecker;
25 } 28 }
26 29
30 class Profile;
Nikita (slow) 2014/10/06 14:55:33 use BrowserContext instead.
31
27 namespace chromeos { 32 namespace chromeos {
28 33
29 // This class encapsulates sign in operations. 34 // This class encapsulates sign in operations.
30 // Sign in is performed in a way that offline auth is executed first. 35 // Sign in is performed in a way that offline auth is executed first.
31 // Once offline auth is OK - user homedir is mounted, UI is launched. 36 // Once offline auth is OK - user homedir is mounted, UI is launched.
32 // At this point LoginPerformer |delegate_| is destroyed and it releases 37 // At this point LoginPerformer |delegate_| is destroyed and it releases
33 // LP instance ownership. LP waits for online login result. 38 // LP instance ownership. LP waits for online login result.
34 // If auth is succeeded, cookie fetcher is executed, LP instance deletes itself. 39 // If auth is succeeded, cookie fetcher is executed, LP instance deletes itself.
35 // 40 //
36 // If |delegate_| is not NULL it will handle error messages, password input. 41 // If |delegate_| is not NULL it will handle error messages, password input.
37 class LoginPerformer : public AuthStatusConsumer, 42 class CHROMEOS_EXPORT LoginPerformer : public AuthStatusConsumer,
38 public OnlineAttemptHost::Delegate { 43 public OnlineAttemptHost::Delegate {
39 public: 44 public:
40 typedef enum AuthorizationMode { 45 typedef enum AuthorizationMode {
41 // Authorization performed internally by Chrome. 46 // Authorization performed internally by Chrome.
42 AUTH_MODE_INTERNAL, 47 AUTH_MODE_INTERNAL,
43 // Authorization performed by an extension. 48 // Authorization performed by an extension.
44 AUTH_MODE_EXTENSION 49 AUTH_MODE_EXTENSION
45 } AuthorizationMode; 50 } AuthorizationMode;
46 51
47 // Delegate class to get notifications from the LoginPerformer. 52 // Delegate class to get notifications from the LoginPerformer.
48 class Delegate : public AuthStatusConsumer { 53 class Delegate : public AuthStatusConsumer {
49 public: 54 public:
50 virtual ~Delegate() {} 55 virtual ~Delegate() {}
51 virtual void WhiteListCheckFailed(const std::string& email) = 0; 56 virtual void WhiteListCheckFailed(const std::string& email) = 0;
52 virtual void PolicyLoadFailed() = 0; 57 virtual void PolicyLoadFailed() = 0;
53 virtual void OnOnlineChecked(const std::string& email, bool success) = 0; 58 virtual void OnOnlineChecked(const std::string& email, bool success) = 0;
54 }; 59 };
55 60
56 explicit LoginPerformer(Delegate* delegate); 61 LoginPerformer(scoped_refptr<base::TaskRunner> task_runner,
62 Delegate* delegate);
57 virtual ~LoginPerformer(); 63 virtual ~LoginPerformer();
58 64
59 // AuthStatusConsumer implementation:
60 virtual void OnAuthFailure(const AuthFailure& error) override;
61 virtual void OnRetailModeAuthSuccess(
62 const UserContext& user_context) override;
63 virtual void OnAuthSuccess(const UserContext& user_context) override;
64 virtual void OnOffTheRecordAuthSuccess() override;
65 virtual void OnPasswordChangeDetected() override;
66
67 // Performs a login for |user_context|. 65 // Performs a login for |user_context|.
68 // If auth_mode is AUTH_MODE_EXTENSION, there are no further auth checks, 66 // If auth_mode is AUTH_MODE_EXTENSION, there are no further auth checks,
69 // AUTH_MODE_INTERNAL will perform auth checks. 67 // AUTH_MODE_INTERNAL will perform auth checks.
70 void PerformLogin(const UserContext& user_context, 68 void PerformLogin(const UserContext& user_context,
71 AuthorizationMode auth_mode); 69 AuthorizationMode auth_mode);
72 70
73 // Performs supervised user login with a given |user_context|. 71 // Performs supervised user login with a given |user_context|.
74 void LoginAsSupervisedUser(const UserContext& user_context); 72 void LoginAsSupervisedUser(const UserContext& user_context);
75 73
76 // Performs retail mode login. 74 // Performs retail mode login.
77 void LoginRetailMode(); 75 void LoginRetailMode();
78 76
79 // Performs actions to prepare guest mode login. 77 // Performs actions to prepare guest mode login.
80 void LoginOffTheRecord(); 78 void LoginOffTheRecord();
81 79
82 // Performs public session login with a given |user_context|. 80 // Performs public session login with a given |user_context|.
83 void LoginAsPublicSession(const UserContext& user_context); 81 void LoginAsPublicSession(const UserContext& user_context);
84 82
85 // Performs a login into the kiosk mode account with |app_user_id|. 83 // Performs a login into the kiosk mode account with |app_user_id|.
86 void LoginAsKioskAccount(const std::string& app_user_id, 84 void LoginAsKioskAccount(const std::string& app_user_id,
87 bool use_guest_mount); 85 bool use_guest_mount);
88 86
87 // AuthStatusConsumer implementation:
88 virtual void OnAuthFailure(const AuthFailure& error) OVERRIDE;
89 virtual void OnRetailModeAuthSuccess(
90 const UserContext& user_context) OVERRIDE;
91 virtual void OnAuthSuccess(const UserContext& user_context) OVERRIDE;
92 virtual void OnOffTheRecordAuthSuccess() OVERRIDE;
93 virtual void OnPasswordChangeDetected() OVERRIDE;
94
89 // Migrates cryptohome using |old_password| specified. 95 // Migrates cryptohome using |old_password| specified.
90 void RecoverEncryptedData(const std::string& old_password); 96 void RecoverEncryptedData(const std::string& old_password);
91 97
92 // Reinitializes cryptohome with the new password. 98 // Reinitializes cryptohome with the new password.
93 void ResyncEncryptedData(); 99 void ResyncEncryptedData();
94 100
95 // Returns latest auth error. 101 // Returns latest auth error.
96 const GoogleServiceAuthError& error() const { 102 const GoogleServiceAuthError& error() const {
97 return last_login_failure_.error(); 103 return last_login_failure_.error();
98 } 104 }
99 105
100 // True if password change has been detected. 106 // True if password change has been detected.
101 bool password_changed() { return password_changed_; } 107 bool password_changed() { return password_changed_; }
102 108
103 // Number of times we've been called with OnPasswordChangeDetected(). 109 // Number of times we've been called with OnPasswordChangeDetected().
104 // If user enters incorrect old password, same LoginPerformer instance will 110 // If user enters incorrect old password, same LoginPerformer instance will
105 // be called so callback count makes it possible to distinguish initial 111 // be called so callback count makes it possible to distinguish initial
106 // "password changed detected" event from further attempts to enter old 112 // "password changed detected" event from further attempts to enter old
107 // password for cryptohome migration (when > 1). 113 // password for cryptohome migration (when > 1).
108 int password_changed_callback_count() { 114 int password_changed_callback_count() {
109 return password_changed_callback_count_; 115 return password_changed_callback_count_;
110 } 116 }
111 117
112 void set_delegate(Delegate* delegate) { delegate_ = delegate; } 118 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
113 119
114 AuthorizationMode auth_mode() const { return auth_mode_; } 120 AuthorizationMode auth_mode() const { return auth_mode_; }
115 121
116 protected: 122 protected:
117 // Implements OnlineAttemptHost::Delegate. 123 // Implements OnlineAttemptHost::Delegate.
118 virtual void OnChecked(const std::string& username, bool success) override; 124 virtual void OnChecked(const std::string& username, bool success) OVERRIDE;
Nikita (slow) 2014/10/06 15:02:30 nit: username > user_id here and through this clas
125
126 // Platform-dependant methods do be implemented by concrete class.
Nikita (slow) 2014/10/06 15:02:30 nit: to be
127
128 // Run trusted check for platform. If trusted check have to be performed
Nikita (slow) 2014/10/06 15:02:30 nit: for a platform
129 // asynchronously,
Nikita (slow) 2014/10/06 15:02:30 nit: please combine with the next line looks stran
130 // |false| will be returned, and either delegate's PolicyLoadFailed() or
131 // |callback| will be
132 // called upon actual check.
Nikita (slow) 2014/10/06 15:02:31 nit: last two lines may be combined
133 virtual bool RunTrustedCheck(const base::Closure& callback) = 0;
134 // Check if user is allowed to sign in on device. |wildcard_match| will
Nikita (slow) 2014/10/06 15:02:31 nit: insert extra empty line before comment.
135 // contain
Nikita (slow) 2014/10/06 15:02:30 nit: Please combine with the next line.
136 // additional information whether this user is explicitly listed or not (may
137 // be relevant for
Nikita (slow) 2014/10/06 15:02:30 nit: combine two last lines.
138 // extension-based sign-in).
139 virtual bool IsUserWhitelisted(const std::string& username,
140 bool* wildcard_match) = 0;
141 // This method should run addional online check if user can sign in on device.
Nikita (slow) 2014/10/06 15:02:31 nit: Insert empty line before comment.
142 // Either |success_callback| or |failure_callback| should be called upon this
143 // check.
144 virtual void RunOnlineWhitelistCheck(
145 const std::string& username,
146 bool wildcard_match,
147 const base::Closure& success_callback,
148 const base::Closure& failure_callback) = 0;
149
150 // Supervised users-related methods.
151
152 // Check if supervised users are allowed on this device.
153 virtual bool AreSupervisedUsersAllowed() = 0;
154
155 // Check which authenticator should be used for supervised user.
156 virtual bool UseExtendedAuthenticatorForSupervisedUser(
157 const UserContext& user_context) = 0;
158
159 // Probably transform supervised user's authentication key.
160 virtual UserContext TransformSupervisedKey(const UserContext& context) = 0;
161
162 // Set up sign-in flow for supervised user.
163 virtual void SetupSupervisedUserFlow(const std::string& user_id) = 0;
164
165 // Run policy check for user. If something is wrong, delegate's
Nikita (slow) 2014/10/06 15:02:30 nit: for |user_id|
166 // PolicyLoadFailed is called.
167 virtual bool CheckPolicyForUser(const std::string& username) = 0;
Nikita (slow) 2014/10/06 15:02:30 nit: username > user_id
168
169 // Look up profile to use during signin.
170 virtual Profile* GetSigninProfile() = 0;
Nikita (slow) 2014/10/06 15:02:30 nit: Should not use Profile here thus rename metho
171
172 // Get implementation of RequestContext.
Nikita (slow) 2014/10/06 15:02:30 nit: Get RequestContext used for sign in.
173 virtual net::URLRequestContextGetter* GetSigninRequestContext() = 0;
174
175 // Create authenticator implementation.
176 virtual scoped_refptr<Authenticator> CreateAuthenticator() = 0;
177
178 void set_authenticator(scoped_refptr<Authenticator> authenticator);
179
180 // Notifications receiver.
181 Delegate* delegate_;
119 182
120 private: 183 private:
121 // Starts login completion of externally authenticated user. 184 // Starts login completion of externally authenticated user.
122 void StartLoginCompletion(); 185 void StartLoginCompletion();
123 186
124 // Starts authentication. 187 // Starts authentication.
125 void StartAuthentication(); 188 void StartAuthentication();
189 void NotifyWhitelistCheckFailure();
126 190
127 // Completion callback for the online wildcard login check for enterprise 191 // Makes sure that authenticator is created.
128 // devices. Continues the login process or signals whitelist check failure 192 void EnsureAuthenticator();
129 // depending on the value of |result|. 193 void EnsureExtendedAuthenticator();
130 void OnlineWildcardLoginCheckCompleted( 194
131 policy::WildcardLoginChecker::Result result); 195 // Actual implementantion of PeformLogin that is run after trusted values
196 // check.
197 void DoPerformLogin(const UserContext& user_context,
198 AuthorizationMode auth_mode);
199
200 scoped_refptr<base::TaskRunner> task_runner_;
132 201
133 // Used for logging in. 202 // Used for logging in.
134 scoped_refptr<Authenticator> authenticator_; 203 scoped_refptr<Authenticator> authenticator_;
204
205 // Used for logging in.
135 scoped_refptr<ExtendedAuthenticator> extended_authenticator_; 206 scoped_refptr<ExtendedAuthenticator> extended_authenticator_;
136 207
137 // Used to make auxiliary online check. 208 // Used to make auxiliary online check.
138 OnlineAttemptHost online_attempt_host_; 209 OnlineAttemptHost online_attempt_host_;
139 210
140 // Represents last login failure that was encountered when communicating to 211 // Represents last login failure that was encountered when communicating to
141 // sign-in server. AuthFailure.LoginFailureNone() by default. 212 // sign-in server. AuthFailure.LoginFailureNone() by default.
142 AuthFailure last_login_failure_; 213 AuthFailure last_login_failure_;
143 214
144 // User credentials for the current login attempt. 215 // User credentials for the current login attempt.
145 UserContext user_context_; 216 UserContext user_context_;
146 217
147 // Notifications receiver.
148 Delegate* delegate_;
149
150 // True if password change has been detected. 218 // True if password change has been detected.
151 // Once correct password is entered homedir migration is executed. 219 // Once correct password is entered homedir migration is executed.
152 bool password_changed_; 220 bool password_changed_;
153 int password_changed_callback_count_; 221 int password_changed_callback_count_;
154 222
155 // Authorization mode type. 223 // Authorization mode type.
156 AuthorizationMode auth_mode_; 224 AuthorizationMode auth_mode_;
157 225
158 // Used to verify logins that matched wildcard on the login whitelist.
159 scoped_ptr<policy::WildcardLoginChecker> wildcard_login_checker_;
160
161 base::WeakPtrFactory<LoginPerformer> weak_factory_; 226 base::WeakPtrFactory<LoginPerformer> weak_factory_;
162
163 DISALLOW_COPY_AND_ASSIGN(LoginPerformer); 227 DISALLOW_COPY_AND_ASSIGN(LoginPerformer);
164 }; 228 };
165 229
166 } // namespace chromeos 230 } // namespace chromeos
167 231
168 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_LOGIN_PERFORMER_H_ 232 #endif // CHROMEOS_LOGIN_AUTH_LOGIN_PERFORMER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698