• 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 /**
17  * @file user_idm_client.h
18  *
19  * @brief The definition of idm client.
20  * @since 3.1
21  * @version 3.2
22  */
23 
24 #ifndef USER_IDM_CLIENT_H
25 #define USER_IDM_CLIENT_H
26 
27 #include <memory>
28 #include <optional>
29 #include <vector>
30 
31 #include "iam_common_defines.h"
32 #include "user_idm_client_callback.h"
33 #include "user_idm_client_defines.h"
34 
35 namespace OHOS {
36 namespace UserIam {
37 namespace UserAuth {
38 class UserIdmClient {
39 public:
40     /**
41      * @brief Get userIdm client's instance.
42      *
43      * @return UserIdmClient's instance.
44      */
45     static UserIdmClient &GetInstance();
46 
47     /**
48      * @brief Deconstructor.
49      */
50     virtual ~UserIdmClient() = default;
51 
52     /**
53      * @brief Open session with user identity management.
54      *
55      * User identity Management can be used only after the session is open,
56      * and the session is valid for ten minutes.
57      * @param userId System userId, generated by account subsystem.
58      * @return Return the challenge.
59      */
60     virtual std::vector<uint8_t> OpenSession(int32_t userId) = 0;
61 
62     /**
63      * @brief Open session with user identity management.
64      *
65      * @param userId System userId, generated by account subsystem.
66      */
67     virtual void CloseSession(int32_t userId) = 0;
68 
69     /**
70      * @brief Add user credential information.
71      *
72      * @param userId System userId, generated by account subsystem.
73      * @param para Include authType, pinSubType and token.
74      * @param callback Callback of add credential result.
75      */
76     virtual void AddCredential(int32_t userId, const CredentialParameters &para,
77         const std::shared_ptr<UserIdmClientCallback> &callback) = 0;
78 
79     /**
80      * @brief Update user credential information.
81      *
82      * @param userId System userId, generated by account subsystem.
83      * @param para Include authType, pinSubType and token(PIN).
84      * @param callback Callback of update credential result.
85      */
86     virtual void UpdateCredential(int32_t userId, const CredentialParameters &para,
87         const std::shared_ptr<UserIdmClientCallback> &callback) = 0;
88 
89     /**
90      * @brief Cancel add user credential.
91      *
92      * @param userId System userId, generated by account subsystem.
93      * @return Return Cancel result(0:success; other:failed).
94      */
95     virtual int32_t Cancel(int32_t userId) = 0;
96 
97     /**
98      * @brief Delete user's credential according to credentialId.
99      *
100      * Only support to delete non-password credentials.
101      *
102      * @param userId System userId, generated by account subsystem.
103      * @param credentialId User credentialId.
104      * @param authToken PIN auth token.
105      * @param callback Callback of delete credential result.
106      */
107     virtual void DeleteCredential(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken,
108         const std::shared_ptr<UserIdmClientCallback> &callback) = 0;
109 
110     /**
111      * @brief Delete user's PIN.
112      *
113      * When deleting user's PIN, all credentials of the user will be deleted.
114      *
115      * @param userId System userId, generated by account subsystem.
116      * @param authToken PIN auth token.
117      * @param callback Callback of delete user's credential result.
118      */
119     virtual void DeleteUser(int32_t userId, const std::vector<uint8_t> &authToken,
120         const std::shared_ptr<UserIdmClientCallback> &callback) = 0;
121 
122     /**
123      * @brief Erase user.
124      *
125      * This method is used for administrators to delete user and
126      * delete all credentials of the user at the same time.
127      *
128      * @param userId System userId, generated by account subsystem.
129      * @param callback Callback of erase user result.
130      * @return Return erase user success or not(0:success; other:failed).
131      */
132     virtual int32_t EraseUser(int32_t userId, const std::shared_ptr<UserIdmClientCallback> &callback) = 0;
133 
134     /**
135      * @brief get user's credential information.
136      *
137      * @param userId System userId, generated by account subsystem.
138      * @param authType Authtype supported by executor.
139      * @param callback Callback of get credentialInfo result.
140      * @return Return get credentialInfo success or not(0:success; other:failed).
141      */
142     virtual int32_t GetCredentialInfo(int32_t userId, AuthType authType,
143         const std::shared_ptr<GetCredentialInfoCallback> &callback) = 0;
144 
145     /**
146      * @brief get security user information.
147      *
148      * @param userId System userId, generated by account subsystem.
149      * @param callback Return get security userInfo result.
150      * @return Return get security userInfo success or not(0:success; other:failed).
151      */
152     virtual int32_t GetSecUserInfo(int32_t userId, const std::shared_ptr<GetSecUserInfoCallback> &callback) = 0;
153 };
154 } // namespace UserAuth
155 } // namespace UserIam
156 } // namespace OHOS
157 #endif // USER_IDM_CLIENT_H