Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / messaging / ExchangeACL.h
1 /*
2  *
3  *    Copyright (c) 2021 Project CHIP Authors
4  *
5  *    Licensed under the Apache License, Version 2.0 (the "License");
6  *    you may not use this file except in compliance with the License.
7  *    You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *    Unless required by applicable law or agreed to in writing, software
12  *    distributed under the License is distributed on an "AS IS" BASIS,
13  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *    See the License for the specific language governing permissions and
15  *    limitations under the License.
16  */
17
18 #pragma once
19
20 #include <app/util/basic-types.h>
21 #include <transport/AdminPairingTable.h>
22
23 namespace chip {
24 namespace Messaging {
25
26 /**
27  * @brief Defines a class that encapsulates ACL target information (cluster and endpoint ID).
28  *        The class can be extended to add other parameters to the ACL target.
29  */
30 class DLL_EXPORT ACLTarget
31 {
32 public:
33     ACLTarget(ClusterId clusterId, EndpointId endpoint) : mClusterId(clusterId), mEndpoint(endpoint) {}
34     virtual ~ACLTarget() {}
35
36     ClusterId GetClusterId() { return mClusterId; }
37     EndpointId GetEndpointId() { return mEndpoint; }
38
39 private:
40     ClusterId mClusterId;
41     EndpointId mEndpoint;
42 };
43
44 /**
45  * @brief Defines a class that encapsulates ACL subject information (e.g. NodeId for CASE session).
46  *        The class can be extended to add parameters to the ACL Subject.
47  */
48 class DLL_EXPORT ACLSubject
49 {
50 public:
51     virtual ~ACLSubject() {}
52
53 private:
54 };
55
56 /**
57  * @brief Defines the common interface for PASE/CASE/GroupID based ACL permissions check.
58  */
59 class DLL_EXPORT ExchangeACL
60 {
61 public:
62     enum class PermissionLevel
63     {
64         kNone,
65         kView,
66         kOperate,
67         kManage,
68         kAdminister,
69     };
70
71     virtual ~ExchangeACL() {}
72
73     /**
74      * @brief
75      *   Check access permissions for the message received from subject (sender) that
76      *   are trying to access the target (e.g. cluster and endpoint).
77      *
78      * @param subject    The subject of the access check (e.g. source node ID)
79      * @param target     The target of the message (i.e. cluster and endpoint)
80      *
81      * @return Permissions granted by the configured ACLs
82      */
83     virtual PermissionLevel GetPermissionLevel(const ACLSubject & subject, const ACLTarget & target) = 0;
84 };
85
86 class DLL_EXPORT CASEACLSubject
87 {
88 public:
89     CASEACLSubject(NodeId id) : mNodeId(id) {}
90     virtual ~CASEACLSubject() {}
91
92     NodeId GetNodeId() { return mNodeId; }
93
94 private:
95     NodeId mNodeId;
96 };
97
98 /**
99  * @brief Specialized class that can perform ACL permissions check on messages that are
100  *        exchanged on a CASE session.
101  */
102 class DLL_EXPORT CASEExchangeACL : public ExchangeACL
103 {
104 public:
105     CASEExchangeACL(Transport::AdminPairingInfo * info) : mAdminInfo(info) {}
106     virtual ~CASEExchangeACL() {}
107
108     PermissionLevel GetPermissionLevel(const ACLSubject & subject, const ACLTarget & target) override
109     {
110         // TODO: Lookup the ACL corresponding to the subject, and the target,
111         //       and enforce it.
112
113         ReturnErrorCodeIf(mAdminInfo == nullptr, PermissionLevel::kNone);
114
115         return PermissionLevel::kOperate;
116     }
117
118 private:
119     Transport::AdminPairingInfo * mAdminInfo;
120 };
121
122 } // namespace Messaging
123 } // namespace chip