• 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 #ifndef DISTRIBUTEDDATAMGR_AUTH_DELEGATE_H
17 #define DISTRIBUTEDDATAMGR_AUTH_DELEGATE_H
18 
19 #include <string>
20 
21 #include "metadata/user_meta_data.h"
22 #include "serializable/serializable.h"
23 namespace OHOS::DistributedData {
24 enum AUTH_GROUP_TYPE {
25     ALL_GROUP = 0,
26     IDENTICAL_ACCOUNT_GROUP = 1,
27     PEER_TO_PEER_GROUP = 256,
28     COMPATIBLE_GROUP = 512,
29     ACROSS_ACCOUNT_AUTHORIZE_GROUP = 1282
30 };
31 
32 class AuthHandler {
33 public:
34     virtual bool CheckAccess(
35         int localUserId, int peerUserId, const std::string &peerDeviceId, const std::string &appId);
36     virtual int32_t GetGroupType(
37         int localUserId, int peerUserId, const std::string &peerDeviceId, const std::string &appId);
38     virtual std::vector<std::string> GetTrustedDevicesByType(
39         AUTH_GROUP_TYPE type, int32_t localUserId, const std::string &appId);
40 
41 private:
42     struct RelatedGroup final : public Serializable {
43         int32_t groupType = -1;
44         std::string groupId;
RelatedGroupfinal45         RelatedGroup()
46         {
47         }
~RelatedGroupfinal48         ~RelatedGroup()
49         {
50         }
51         RelatedGroup(const RelatedGroup &) = default;
52         RelatedGroup &operator=(const RelatedGroup &) = default;
Marshalfinal53         bool Marshal(json &node) const override
54         {
55             SetValue(node[GET_NAME(groupType)], groupType);
56             SetValue(node[GET_NAME(groupId)], groupId);
57             return true;
58         }
59 
Unmarshalfinal60         bool Unmarshal(const json &node) override
61         {
62             GetValue(node, GET_NAME(groupType), groupType);
63             GetValue(node, GET_NAME(groupId), groupId);
64             return true;
65         }
66     };
67 
68     struct TrustDevice final : public Serializable {
69         std::string authId; // udid
70         TrustDevice() = default;
71         TrustDevice(const TrustDevice &) = default;
72         TrustDevice &operator=(const TrustDevice &) = default;
Marshalfinal73         bool Marshal(json &node) const override
74         {
75             SetValue(node[GET_NAME(authId)], authId);
76             return true;
77         }
78 
Unmarshalfinal79         bool Unmarshal(const json &node) override
80         {
81             GetValue(node, GET_NAME(authId), authId);
82             return true;
83         }
84     };
85     static RelatedGroup GetGroupInfo(int32_t localUserId, const std::string &appId, const std::string &peerDeviceId);
86 };
87 
88 class AuthDelegate {
89 public:
90     API_EXPORT static AuthHandler *GetInstance();
91 };
92 } // namespace OHOS::DistributedData
93 #endif // DISTRIBUTEDDATAMGR_AUTH_DELEGATE_H
94