Leosac  0.8.0
Open Source Access Control
SecurityContext.cpp
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 #include "core/SecurityContext.hpp"
22 
23 using namespace Leosac;
24 
26  : dbsrv_(dbsrv)
27 {
28 }
29 
31  const ActionParam &ap) const
32 {
33  return check_permission_impl(a, ap);
34 }
35 
38 {
39  if (!check_permission(a, ap))
40  throw PermissionDenied();
41 }
42 
44 {
45  return check_permission(a, {});
46 }
47 
49 {
50  return enforce_permission(a, {});
51 }
52 
54  : SecurityContext(dbsrv)
55 {
56 }
57 
60 {
61  return true;
62 }
63 
65 {
66  static SystemSecurityContext ssc(nullptr);
67  return ssc;
68 }
69 
70 SecurityContext::GroupActionParam::operator ActionParam()
71 {
73  result.group = *this;
74  return result;
75 }
76 
77 SecurityContext::UserActionParam::operator ActionParam()
78 {
80  result.user = *this;
81  return result;
82 }
83 
84 SecurityContext::MembershipActionParam::operator ActionParam()
85 {
87  result.membership = *this;
88  return result;
89 }
90 
91 SecurityContext::CredentialActionParam::operator ActionParam()
92 {
94  result.cred = *this;
95  return result;
96 }
97 
98 SecurityContext::ScheduleActionParam::operator ActionParam()
99 {
101  result.sched = *this;
102  return result;
103 }
104 
105 SecurityContext::DoorActionParam::operator ActionParam()
106 {
108  result.door = *this;
109  return result;
110 }
111 
112 SecurityContext::AccessPointActionParam::operator ActionParam()
113 {
115  result.access_point = *this;
116  return result;
117 }
118 
119 SecurityContext::ZoneActionParam::operator ActionParam()
120 {
122  result.zone = *this;
123  return result;
124 }
125 
126 SecurityContext::HardwareDeviceActionParam::operator ActionParam()
127 {
129  result.device = *this;
130  return result;
131 }
132 
134  : sec(sc)
135 {
136 }
137 
139  const Audit::IAuditEntryPtr &audit)
140  : sec(sc)
141  , audit(audit)
142 {
143 }
144 
147 {
148 }
Leosac::SystemSecurityContext::instance
static SecurityContext & instance()
Definition: SecurityContext.cpp:64
Leosac::SecurityContext::ActionParam::sched
ScheduleActionParam sched
Definition: SecurityContext.hpp:236
Leosac::SecurityContext::check_permission
virtual bool check_permission(Action a, const ActionParam &ap) const
Check for the permission to perform action a with parameters ap.
Definition: SecurityContext.cpp:30
Leosac::SystemSecurityContext
A security context for system operation.
Definition: SecurityContext.hpp:287
Leosac::SecurityContext::ActionParam::access_point
AccessPointActionParam access_point
Definition: SecurityContext.hpp:238
Leosac::SecurityContext::ActionParam::group
GroupActionParam group
Definition: SecurityContext.hpp:232
Leosac::Audit::IAuditEntryPtr
std::shared_ptr< IAuditEntry > IAuditEntryPtr
Definition: AuditFwd.hpp:40
Leosac::SecurityContext::ActionParam
Definition: SecurityContext.hpp:231
Leosac::SystemSecurityContext::check_permission_impl
virtual bool check_permission_impl(Action a, const ActionParam &ap) const override
Reimplement this method to provide permission checking.
Definition: SecurityContext.cpp:58
Leosac::SecurityContext::check_permission_impl
virtual bool check_permission_impl(Action a, const ActionParam &ap) const =0
Reimplement this method to provide permission checking.
SecurityContext.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::ExecutionContext
An ExecutionContext is passed around to service so they have context about who is making the call and...
Definition: SecurityContext.hpp:301
PermissionDenied.hpp
Leosac::DBServicePtr
std::shared_ptr< DBService > DBServicePtr
Definition: db_fwd.hpp:34
Leosac::SecurityContext::ActionParam::zone
ZoneActionParam zone
Definition: SecurityContext.hpp:239
Leosac::SecurityContext::ActionParam::membership
MembershipActionParam membership
Definition: SecurityContext.hpp:233
Leosac::SecurityContext::ActionParam::device
HardwareDeviceActionParam device
Definition: SecurityContext.hpp:240
Leosac::SecurityContext::Action
Action
Definition: SecurityContext.hpp:45
Leosac::SecurityContext::ActionParam::door
DoorActionParam door
Definition: SecurityContext.hpp:237
Leosac::SecurityContext::enforce_permission
void enforce_permission(Action a, const ActionParam &ap) const
Similar to check_permission(), but throws is the permission is denied.
Definition: SecurityContext.cpp:36
Leosac::SecurityContext::SecurityContext
SecurityContext(DBServicePtr dbsrv)
Definition: SecurityContext.cpp:25
Leosac::SystemExecutionContext::SystemExecutionContext
SystemExecutionContext()
Definition: SecurityContext.cpp:145
Leosac::SecurityContext::ActionParam::cred
CredentialActionParam cred
Definition: SecurityContext.hpp:235
Leosac::SecurityContext
A SecurityContext is used to query permission while doing an operation.
Definition: SecurityContext.hpp:40
Leosac::ExecutionContext::ExecutionContext
ExecutionContext(SecurityContext &sc)
Definition: SecurityContext.cpp:133
PermissionDenied
An exception that can be throw when the permission for a given operation is denied.
Definition: PermissionDenied.hpp:28
Leosac::SystemSecurityContext::SystemSecurityContext
SystemSecurityContext(DBServicePtr dbsrv)
Definition: SecurityContext.cpp:53
Leosac::SecurityContext::ActionParam::user
UserActionParam user
Definition: SecurityContext.hpp:234