1 /*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "domain_account_manager_service.h"
17
18 #include "account_log_wrapper.h"
19 #include "inner_domain_account_manager.h"
20 #include "ipc_skeleton.h"
21
22 namespace OHOS {
23 namespace AccountSA {
24 namespace {
25 constexpr int32_t START_USER_ID = 100;
26 const std::set<uint32_t> UID_WHITELIST_FOR_SET { 3057 };
27 }
28
DomainAccountManagerService()29 DomainAccountManagerService::DomainAccountManagerService()
30 {}
31
~DomainAccountManagerService()32 DomainAccountManagerService::~DomainAccountManagerService()
33 {}
34
RegisterPlugin(const sptr<IDomainAccountPlugin> & plugin)35 ErrCode DomainAccountManagerService::RegisterPlugin(const sptr<IDomainAccountPlugin> &plugin)
36 {
37 return InnerDomainAccountManager::GetInstance().RegisterPlugin(plugin);
38 }
39
UnregisterPlugin()40 ErrCode DomainAccountManagerService::UnregisterPlugin()
41 {
42 InnerDomainAccountManager::GetInstance().UnregisterPlugin();
43 return ERR_OK;
44 }
45
HasDomainAccount(const DomainAccountInfo & info,const sptr<IDomainAccountCallback> & callback)46 ErrCode DomainAccountManagerService::HasDomainAccount(
47 const DomainAccountInfo &info, const sptr<IDomainAccountCallback> &callback)
48 {
49 return InnerDomainAccountManager::GetInstance().HasDomainAccount(info, callback);
50 }
51
GetAccessToken(const DomainAccountInfo & info,const AAFwk::WantParams & parameters,const sptr<IDomainAccountCallback> & callback)52 ErrCode DomainAccountManagerService::GetAccessToken(
53 const DomainAccountInfo &info, const AAFwk::WantParams ¶meters, const sptr<IDomainAccountCallback> &callback)
54 {
55 return InnerDomainAccountManager::GetInstance().GetAccessToken(info, parameters, callback);
56 }
57
UpdateAccountToken(const DomainAccountInfo & info,const std::vector<uint8_t> & token)58 ErrCode DomainAccountManagerService::UpdateAccountToken(
59 const DomainAccountInfo &info, const std::vector<uint8_t> &token)
60 {
61 return InnerDomainAccountManager::GetInstance().UpdateAccountToken(info, token);
62 }
63
CheckManageExpiryThresholdWhiteList()64 static bool CheckManageExpiryThresholdWhiteList()
65 {
66 return UID_WHITELIST_FOR_SET.find(IPCSkeleton::GetCallingUid()) != UID_WHITELIST_FOR_SET.end();
67 }
68
IsAuthenticationExpired(const DomainAccountInfo & info,bool & isExpired)69 ErrCode DomainAccountManagerService::IsAuthenticationExpired(const DomainAccountInfo &info, bool &isExpired)
70 {
71 return InnerDomainAccountManager::GetInstance().IsAuthenticationExpired(info, isExpired);
72 }
73
SetAccountPolicy(const DomainAccountPolicy & policy)74 ErrCode DomainAccountManagerService::SetAccountPolicy(const DomainAccountPolicy &policy)
75 {
76 // check EDM uid
77 if (!CheckManageExpiryThresholdWhiteList()) {
78 ACCOUNT_LOGE("Permission denied, callingUid=%{public}d.", IPCSkeleton::GetCallingUid());
79 return ERR_ACCOUNT_COMMON_PERMISSION_DENIED;
80 }
81 return InnerDomainAccountManager::GetInstance().SetAccountPolicy(policy);
82 }
83
Auth(const DomainAccountInfo & info,const std::vector<uint8_t> & password,const sptr<IDomainAccountCallback> & callback)84 ErrCode DomainAccountManagerService::Auth(const DomainAccountInfo &info, const std::vector<uint8_t> &password,
85 const sptr<IDomainAccountCallback> &callback)
86 {
87 return InnerDomainAccountManager::GetInstance().Auth(info, password, callback);
88 }
89
AuthUser(int32_t userId,const std::vector<uint8_t> & password,const sptr<IDomainAccountCallback> & callback)90 ErrCode DomainAccountManagerService::AuthUser(int32_t userId, const std::vector<uint8_t> &password,
91 const sptr<IDomainAccountCallback> &callback)
92 {
93 if (userId < START_USER_ID) {
94 ACCOUNT_LOGE("invalid userId");
95 return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
96 }
97 return InnerDomainAccountManager::GetInstance().AuthUser(userId, password, callback);
98 }
99
AuthWithPopup(int32_t userId,const sptr<IDomainAccountCallback> & callback)100 ErrCode DomainAccountManagerService::AuthWithPopup(int32_t userId, const sptr<IDomainAccountCallback> &callback)
101 {
102 if (userId < 0) {
103 ACCOUNT_LOGE("invalid userId");
104 return ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR;
105 }
106 return InnerDomainAccountManager::GetInstance().AuthWithPopup(userId, callback);
107 }
108
GetAccountStatus(const DomainAccountInfo & info,DomainAccountStatus & status)109 ErrCode DomainAccountManagerService::GetAccountStatus(const DomainAccountInfo &info, DomainAccountStatus &status)
110 {
111 return InnerDomainAccountManager::GetInstance().GetAccountStatus(info, status);
112 }
113
GetDomainAccountInfo(const DomainAccountInfo & info,const sptr<IDomainAccountCallback> & callback)114 ErrCode DomainAccountManagerService::GetDomainAccountInfo(
115 const DomainAccountInfo &info, const sptr<IDomainAccountCallback> &callback)
116 {
117 return InnerDomainAccountManager::GetInstance().GetDomainAccountInfo(info, callback);
118 }
119
UpdateAccountInfo(const DomainAccountInfo & oldAccountInfo,const DomainAccountInfo & newAccountInfo)120 ErrCode DomainAccountManagerService::UpdateAccountInfo(
121 const DomainAccountInfo &oldAccountInfo, const DomainAccountInfo &newAccountInfo)
122 {
123 return InnerDomainAccountManager::GetInstance().UpdateAccountInfo(oldAccountInfo, newAccountInfo);
124 }
125
RegisterAccountStatusListener(const sptr<IDomainAccountCallback> & listener)126 ErrCode DomainAccountManagerService::RegisterAccountStatusListener(const sptr<IDomainAccountCallback> &listener)
127 {
128 return InnerDomainAccountManager::GetInstance().RegisterAccountStatusListener(listener);
129 }
130
UnregisterAccountStatusListener(const sptr<IDomainAccountCallback> & listener)131 ErrCode DomainAccountManagerService::UnregisterAccountStatusListener(const sptr<IDomainAccountCallback> &listener)
132 {
133 return InnerDomainAccountManager::GetInstance().UnregisterAccountStatusListener(listener);
134 }
135
AddServerConfig(const std::string & parameters,DomainServerConfig & config)136 ErrCode DomainAccountManagerService::AddServerConfig(const std::string ¶meters, DomainServerConfig &config)
137 {
138 return InnerDomainAccountManager::GetInstance().AddServerConfig(parameters, config);
139 }
140
RemoveServerConfig(const std::string & configId)141 ErrCode DomainAccountManagerService::RemoveServerConfig(const std::string &configId)
142 {
143 return InnerDomainAccountManager::GetInstance().RemoveServerConfig(configId);
144 }
145
GetAccountServerConfig(const DomainAccountInfo & info,DomainServerConfig & config)146 ErrCode DomainAccountManagerService::GetAccountServerConfig(const DomainAccountInfo &info, DomainServerConfig &config)
147 {
148 return InnerDomainAccountManager::GetInstance().GetAccountServerConfig(info, config);
149 }
150 } // namespace AccountSA
151 } // namespace OHOS
152