Leosac  0.7.0
OpenSourceAccessControl
SecurityContext.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "core/audit/AuditFwd.hpp"
23 #include "core/auth/AuthFwd.hpp"
25 #include "hardware/HardwareFwd.hpp"
26 #include "tools/ToolsFwd.hpp"
27 #include "tools/db/db_fwd.hpp"
28 
29 namespace Leosac
30 {
41 {
42  public:
43  // Forward declare the union so we can write cast operator.
44  union ActionParam;
45  enum class Action
46  {
50  IS_ADMIN,
54  IS_MANAGER,
55 
56 
58  USER_READ,
63 
74 
76  GROUP_READ,
80 
90 
95 
101 
102  DOOR_READ,
103  DOOR_UPDATE,
104  DOOR_CREATE,
105  DOOR_DELETE,
106  DOOR_SEARCH,
107 
113 
114  ZONE_READ,
115  ZONE_UPDATE,
116  ZONE_CREATE,
117  ZONE_DELETE,
118  ZONE_SEARCH,
119 
129 
130  LOG_READ,
131 
135  AUDIT_READ,
141 
146 
151 
163  };
164 
166  {
168 
169  operator ActionParam();
170  };
171 
173  {
175 
176  operator ActionParam();
177  };
178 
180  {
182 
183  operator ActionParam();
184  };
185 
187  {
189  Auth::GroupId group_id; // for create/delete
190  Auth::UserId user_id; // for create/delete
191  Auth::GroupRank rank; // for create
192 
193  operator ActionParam();
194  };
195 
197  {
199 
200  operator ActionParam();
201  };
202 
204  {
206 
207  operator ActionParam();
208  };
209 
211  {
213 
214  operator ActionParam();
215  };
216 
218  {
220 
221  operator ActionParam();
222  };
223 
225  {
227 
228  operator ActionParam();
229  };
230 
231  union ActionParam {
241  };
242 
243  explicit SecurityContext(DBServicePtr dbsrv);
244  virtual ~SecurityContext() = default;
245 
252  virtual bool check_permission(Action a, const ActionParam &ap) const;
253 
258  bool check_permission(Action a) const;
259 
264  void enforce_permission(Action a, const ActionParam &ap) const;
265 
270  void enforce_permission(Action a) const;
271 
272  protected:
274 
275  private:
279  virtual bool check_permission_impl(Action a, const ActionParam &ap) const = 0;
280 };
281 
288 {
289  public:
290  explicit SystemSecurityContext(DBServicePtr dbsrv);
291 
292  static SecurityContext &instance();
293  virtual bool check_permission_impl(Action a,
294  const ActionParam &ap) const override;
295 };
296 
302 {
303  explicit ExecutionContext(SecurityContext &sc);
304 
306 
307 
312 
318 };
319 
321 {
323 };
324 }
SecurityContext(DBServicePtr dbsrv)
unsigned long AccessPointId
Definition: AuthFwd.hpp:128
This is the header file for a generated source file, GitSHA1.cpp.
Audit::IAuditEntryPtr audit
An optional audit object that would act as parent for the audit trail.
unsigned long UserGroupMembershipId
Definition: AuthFwd.hpp:82
A security context for system operation.
Read the audit log and access additional information, such as the JSON "before" and "after" field...
std::shared_ptr< IAuditEntry > IAuditEntryPtr
Definition: AuditFwd.hpp:40
virtual ~SecurityContext()=default
unsigned long GroupId
Definition: AuthFwd.hpp:41
unsigned long UserId
Definition: AuthFwd.hpp:34
unsigned long DoorId
Definition: AuthFwd.hpp:107
virtual bool check_permission(Action a, const ActionParam &ap) const
Check for the permission to perform action a with parameters ap.
A workaround permission that requires the user to be administrator.
Thin wrapper around boost::uuids::uuid.
Definition: Uuid.hpp:35
Permissions for hardware devices.
std::shared_ptr< DBService > DBServicePtr
Definition: db_fwd.hpp:34
GroupRank
The rank of an User inside a Group.
Definition: AuthFwd.hpp:49
A SecurityContext is used to query permission while doing an operation.
Requires that the user be at least manager.
unsigned long ScheduleId
Definition: ToolsFwd.hpp:33
unsigned long ZoneId
Definition: AuthFwd.hpp:119
SecurityContext & sec
The SecurityContext of the caller.
unsigned long CredentialId
Perform to restart the Leosac server.
Can we enable/disable the user or change its validity period ?
void enforce_permission(Action a, const ActionParam &ap) const
Similar to check_permission(), but throws is the permission is denied.
Overview of users/doors access permission.
An ExecutionContext is passed around to service so they have context about who is making the call and...
Editing rank means being able to become administrator.
virtual bool check_permission_impl(Action a, const ActionParam &ap) const =0
Reimplement this method to provide permission checking.