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 CHROME_BROWSER_SUPERVISED_USER_CHROMEOS_MANAGER_PASSWORD_SERVICE_H_
6 #define CHROME_BROWSER_SUPERVISED_USER_CHROMEOS_MANAGER_PASSWORD_SERVICE_H_
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service.h"
14 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h"
15 #include "chrome/browser/supervised_user/supervised_users.h"
16 #include "chromeos/login/auth/extended_authenticator.h"
17 #include "components/keyed_service/core/keyed_service.h"
23 // Handles supervised user password change that is detected while manager is
25 // It uses manager's master key to authorize update of supervised user's key.
26 // Edge case: Pre-M35 supervised users don't have correct labels for keys.
27 // After new supervised user key is added, migration is done in following way:
28 // 1) Master key is added with correct label
29 // 2) Old supervised user's key is deleted.
30 // 3) Old master key is deleted.
31 class ManagerPasswordService
32 : public KeyedService
,
33 public chromeos::ExtendedAuthenticator::NewAuthStatusConsumer
{
35 ManagerPasswordService();
36 ~ManagerPasswordService() override
;
38 void Shutdown() override
;
40 void Init(const std::string
& user_id
,
41 SupervisedUserSyncService
* user_service
,
42 SupervisedUserSharedSettingsService
* service
);
44 // chromeos::ExtendedAuthenticator::AuthStatusConsumer overrides:
45 void OnAuthenticationFailure(ExtendedAuthenticator::AuthState state
) override
;
48 void OnSharedSettingsChange(const std::string
& su_id
, const std::string
& key
);
49 void GetSupervisedUsersCallback(
50 const std::string
& sync_su_id
,
51 const std::string
& user_id
,
52 scoped_ptr
<base::DictionaryValue
> password_data
,
53 const base::DictionaryValue
* supervised_users
);
54 void OnAddKeySuccess(const UserContext
& master_key_context
,
55 const std::string
& user_id
,
56 scoped_ptr
<base::DictionaryValue
> password_data
);
57 void OnKeyTransformedIfNeeded(const UserContext
& master_key_context
);
58 void OnNewManagerKeySuccess(const UserContext
& master_key_context
);
59 void OnOldSupervisedUserKeyDeleted(const UserContext
& master_key_context
);
60 void OnOldManagerKeyDeleted(const UserContext
& master_key_context
);
62 // Cached value from Init().
63 // User id of currently logged in user, that have supervised users on device.
65 SupervisedUserSyncService
* user_service_
;
66 SupervisedUserSharedSettingsService
* settings_service_
;
68 scoped_ptr
<SupervisedUserSharedSettingsService::ChangeCallbackList::
70 settings_service_subscription_
;
72 scoped_refptr
<ExtendedAuthenticator
> authenticator_
;
74 base::WeakPtrFactory
<ManagerPasswordService
> weak_ptr_factory_
;
76 DISALLOW_COPY_AND_ASSIGN(ManagerPasswordService
);
79 } // namespace chromeos
80 #endif // CHROME_BROWSER_SUPERVISED_USER_CHROMEOS_MANAGER_PASSWORD_SERVICE_H_