• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "useridm_stub.h"
17 #include <message_parcel.h>
18 #include "useridm_hilog_wrapper.h"
19 
20 namespace OHOS {
21 namespace UserIAM {
22 namespace UserIDM {
UserIDMStub()23 UserIDMStub::UserIDMStub()
24 {
25     m_handle_[static_cast<int32_t>(IUserIDM::USERIDM_OPEN_SESSION)]  = &UserIDMStub::OpenSessionStub;
26     m_handle_[static_cast<int32_t>(IUserIDM::USERIDM_CLOSE_SESSION)] = &UserIDMStub::CloseSessionStub;
27     m_handle_[static_cast<int32_t>(IUserIDM::USERIDM_GET_AUTH_INFO)] = &UserIDMStub::GetAuthInfoStub;
28     m_handle_[static_cast<int32_t>(IUserIDM::USERIDM_GET_AUTH_INFO_BY_ID)] = &UserIDMStub::GetAuthInfoByIdStub;
29     m_handle_[static_cast<int32_t>(IUserIDM::USERIDM_GET_SEC_INFO)]  = &UserIDMStub::GetSecInfoStub;
30     m_handle_[static_cast<int32_t>(IUserIDM::USERIDM_ADD_CREDENTIAL)] = &UserIDMStub::AddCredentialStub;
31     m_handle_[static_cast<int32_t>(IUserIDM::USERIDM_UPDATE_CREDENTIAL)] = &UserIDMStub::UpdateCredentialStub;
32     m_handle_[static_cast<int32_t>(IUserIDM::USERIDM_CANCEL)]  = &UserIDMStub::CancelStub;
33     m_handle_[static_cast<int32_t>(IUserIDM::USERIDM_ENFORCE_DELUSER)]  = &UserIDMStub::EnforceDelUserStub;
34     m_handle_[static_cast<int32_t>(IUserIDM::USERIDM_DELUSER)]  = &UserIDMStub::DelUserStub;
35     m_handle_[static_cast<int32_t>(IUserIDM::USERIDM_DELCRED)]  = &UserIDMStub::DelCredStub;
36 }
37 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)38 int32_t UserIDMStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
39 {
40     USERIDM_HILOGI(MODULE_SERVICE,
41         "UserIDMStub::OnRemoteRequest, cmd = %{public}u, flags= %{public}d", code, option.GetFlags());
42 
43     std::u16string descripter = UserIDMStub::GetDescriptor();
44     std::u16string remoteDescripter = data.ReadInterfaceToken();
45     if (descripter != remoteDescripter) {
46         USERIDM_HILOGE(MODULE_SERVICE, "UserIDMStub::OnRemoteRequest failed, descriptor is not matched");
47         return FAIL;
48     }
49     std::map<int32_t, PHandle>::const_iterator iter = m_handle_.find(code);
50     if (iter == m_handle_.end()) {
51         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
52     }
53     PHandle pFunction = iter->second;
54     return (this->*pFunction)(data, reply);
55 }
56 
OpenSessionStub(MessageParcel & data,MessageParcel & reply)57 int32_t UserIDMStub::OpenSessionStub(MessageParcel& data, MessageParcel& reply)
58 {
59     USERIDM_HILOGD(MODULE_SERVICE, "OpenSessionStub start");
60 
61     uint64_t ret = OpenSession();
62     if (!reply.WriteUint64(ret)) {
63         USERIDM_HILOGE(MODULE_SERVICE, "failed to WriteUint64(ret)");
64         return FAIL;
65     }
66 
67     return SUCCESS;
68 }
69 
CloseSessionStub(MessageParcel & data,MessageParcel & reply)70 int32_t UserIDMStub::CloseSessionStub(MessageParcel& data, MessageParcel& reply)
71 {
72     USERIDM_HILOGD(MODULE_SERVICE, "CloseSessionStub start");
73 
74     CloseSession();
75 
76     return SUCCESS;
77 }
78 
GetAuthInfoStub(MessageParcel & data,MessageParcel & reply)79 int32_t UserIDMStub::GetAuthInfoStub(MessageParcel& data, MessageParcel& reply)
80 {
81     USERIDM_HILOGD(MODULE_SERVICE, "GetAuthInfoStub start");
82 
83     AuthType authType = static_cast<AuthType>(data.ReadUint32());
84 
85     sptr<IGetInfoCallback> callback = iface_cast<IGetInfoCallback>(data.ReadRemoteObject());
86     if (callback == nullptr) {
87         USERIDM_HILOGE(MODULE_SERVICE, "callback is nullptr");
88         return ERR_INVALID_VALUE;
89     }
90 
91     int32_t ret = GetAuthInfo(authType, callback);
92     if (!reply.WriteInt32(ret)) {
93         USERIDM_HILOGE(MODULE_SERVICE, "failed to WriteInt32(ret)");
94         return FAIL;
95     }
96 
97     return SUCCESS;
98 }
99 
GetAuthInfoByIdStub(MessageParcel & data,MessageParcel & reply)100 int32_t UserIDMStub::GetAuthInfoByIdStub(MessageParcel& data, MessageParcel& reply)
101 {
102     USERIDM_HILOGD(MODULE_SERVICE, "GetAuthInfoByIdStub start");
103 
104     int32_t userId = data.ReadInt32();
105     AuthType authType = static_cast<AuthType>(data.ReadUint32());
106     sptr<IGetInfoCallback> callback = iface_cast<IGetInfoCallback>(data.ReadRemoteObject());
107     if (callback == nullptr) {
108         USERIDM_HILOGE(MODULE_SERVICE, "callback is nullptr");
109         return ERR_INVALID_VALUE;
110     }
111 
112     int32_t ret = GetAuthInfo(userId, authType, callback);
113     if (!reply.WriteInt32(ret)) {
114         USERIDM_HILOGE(MODULE_SERVICE, "failed to WriteInt32(ret)");
115         return FAIL;
116     }
117 
118     return SUCCESS;
119 }
120 
GetSecInfoStub(MessageParcel & data,MessageParcel & reply)121 int32_t UserIDMStub::GetSecInfoStub(MessageParcel& data, MessageParcel& reply)
122 {
123     USERIDM_HILOGD(MODULE_SERVICE, "GetSecInfoStub start");
124 
125     int32_t userId = data.ReadInt32();
126     sptr<IGetSecInfoCallback> callback = iface_cast<IGetSecInfoCallback>(data.ReadRemoteObject());
127     if (callback == nullptr) {
128         USERIDM_HILOGE(MODULE_SERVICE, "callback is nullptr");
129         return ERR_INVALID_VALUE;
130     }
131 
132     int32_t ret = GetSecInfo(userId, callback);
133     if (!reply.WriteInt32(ret)) {
134         USERIDM_HILOGE(MODULE_SERVICE, "failed to WriteInt32(ret)");
135         return FAIL;
136     }
137 
138     return SUCCESS;
139 }
140 
AddCredentialStub(MessageParcel & data,MessageParcel & reply)141 int32_t UserIDMStub::AddCredentialStub(MessageParcel& data, MessageParcel& reply)
142 {
143     USERIDM_HILOGD(MODULE_SERVICE, "AddCredentialStub start");
144 
145     AddCredInfo credInfo;
146     credInfo.authType = static_cast<AuthType>(data.ReadUint32());
147     credInfo.authSubType = static_cast<AuthSubType>(data.ReadUint64());
148     data.ReadUInt8Vector(&(credInfo.token));
149 
150     sptr<IIDMCallback> callback = iface_cast<IIDMCallback>(data.ReadRemoteObject());
151     if (callback == nullptr) {
152         USERIDM_HILOGE(MODULE_SERVICE, "callback is nullptr");
153         return FAIL;
154     }
155 
156     AddCredential(credInfo, callback);
157     return SUCCESS;
158 }
159 
UpdateCredentialStub(MessageParcel & data,MessageParcel & reply)160 int32_t UserIDMStub::UpdateCredentialStub(MessageParcel& data, MessageParcel& reply)
161 {
162     USERIDM_HILOGD(MODULE_SERVICE, "UpdateCredentialStub start");
163 
164     AddCredInfo credInfo;
165     credInfo.authType = static_cast<AuthType>(data.ReadUint32());
166     credInfo.authSubType = static_cast<AuthSubType>(data.ReadUint64());
167     data.ReadUInt8Vector(&(credInfo.token));
168 
169     sptr<IIDMCallback> callback = iface_cast<IIDMCallback>(data.ReadRemoteObject());
170     if (callback == nullptr) {
171         USERIDM_HILOGE(MODULE_SERVICE, "callback is nullptr");
172         return FAIL;
173     }
174 
175     UpdateCredential(credInfo, callback);
176     return SUCCESS;
177 }
178 
CancelStub(MessageParcel & data,MessageParcel & reply)179 int32_t UserIDMStub::CancelStub(MessageParcel& data, MessageParcel& reply)
180 {
181     USERIDM_HILOGD(MODULE_SERVICE, "CancelStub start");
182 
183     uint64_t challenge = data.ReadUint64();
184 
185     int32_t ret = Cancel(challenge);
186     if (!reply.WriteInt32(ret)) {
187         USERIDM_HILOGE(MODULE_SERVICE, "failed to WriteInt32(ret)");
188         return FAIL;
189     }
190 
191     return ret;
192 }
193 
EnforceDelUserStub(MessageParcel & data,MessageParcel & reply)194 int32_t UserIDMStub::EnforceDelUserStub(MessageParcel& data, MessageParcel& reply)
195 {
196     USERIDM_HILOGD(MODULE_SERVICE, "EnforceDelUserStub start");
197 
198     int32_t userId = data.ReadInt32();
199 
200     sptr<IIDMCallback> callback = iface_cast<IIDMCallback>(data.ReadRemoteObject());
201     if (callback == nullptr) {
202         USERIDM_HILOGE(MODULE_SERVICE, "callback is nullptr");
203         return FAIL;
204     }
205 
206     int32_t ret = EnforceDelUser(userId, callback);
207     if (!reply.WriteInt32(ret)) {
208         USERIDM_HILOGE(MODULE_SERVICE, "failed to WriteInt32(ret)");
209         return FAIL;
210     }
211     return ret;
212 }
213 
DelUserStub(MessageParcel & data,MessageParcel & reply)214 int32_t UserIDMStub::DelUserStub(MessageParcel& data, MessageParcel& reply)
215 {
216     USERIDM_HILOGD(MODULE_SERVICE, "DelUserStub start");
217 
218     std::vector<uint8_t> authToken;
219     data.ReadUInt8Vector(&authToken);
220 
221     sptr<IIDMCallback> callback = iface_cast<IIDMCallback>(data.ReadRemoteObject());
222     if (callback == nullptr) {
223         USERIDM_HILOGE(MODULE_SERVICE, "callback is nullptr");
224         return FAIL;
225     }
226 
227     DelUser(authToken, callback);
228     return SUCCESS;
229 }
230 
DelCredStub(MessageParcel & data,MessageParcel & reply)231 int32_t UserIDMStub::DelCredStub(MessageParcel& data, MessageParcel& reply)
232 {
233     USERIDM_HILOGD(MODULE_SERVICE, "DelCredStub start");
234 
235     uint64_t credentialId = data.ReadUint64();
236     std::vector<uint8_t> authToken;
237     data.ReadUInt8Vector(&authToken);
238     sptr<IIDMCallback> callback = iface_cast<IIDMCallback>(data.ReadRemoteObject());
239     if (callback == nullptr) {
240         USERIDM_HILOGE(MODULE_SERVICE, "callback is nullptr");
241         return FAIL;
242     }
243 
244     DelCred(credentialId, authToken, callback);
245     return SUCCESS;
246 }
247 }  // namespace UserIDM
248 }  // namespace UserIAM
249 }  // namespace OHOS
250