Leosac  0.8.0
Open Source Access Control
AuditFactory.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 
23 #include "core/audit/DoorEvent.hpp"
27 #include "core/audit/UserEvent.hpp"
29 #include "core/audit/WSAPICall.hpp"
30 #include "core/audit/ZoneEvent.hpp"
32 #include "core/auth/Door.hpp"
33 #include "core/auth/Group.hpp"
34 #include "core/auth/IZone.hpp"
35 #include "core/auth/User.hpp"
36 #include "core/update/IUpdate.hpp"
37 #include "tools/AssertCast.hpp"
38 #include "tools/log.hpp"
39 
40 using namespace Leosac;
41 using namespace Leosac::Audit;
42 
43 IUserEventPtr Factory::UserEvent(const DBPtr &database, Auth::UserPtr target_user,
44  IAuditEntryPtr parent)
45 {
46  ASSERT_LOG(database, "Database cannot be null.");
47  ASSERT_LOG(target_user, "Target user must be non null.");
48  ASSERT_LOG(target_user->id(), "Target user must be already persisted.");
49  ASSERT_LOG(parent, "Parent must be non null.");
50  ASSERT_LOG(parent->id(), "Parent must be already persisted.");
51 
52  AuditEntryPtr parent_odb = std::dynamic_pointer_cast<AuditEntry>(parent);
53  ASSERT_LOG(parent_odb, "Parent object was not an instance of AuditEntry");
54 
55  return Audit::UserEvent::create(database, target_user, parent_odb);
56 }
57 
59  Auth::GroupPtr target_group,
60  IAuditEntryPtr parent)
61 {
62  ASSERT_LOG(database, "Database cannot be null.");
63  ASSERT_LOG(target_group, "Target group must be non null.");
64  ASSERT_LOG(target_group->id(), "Target group must be already persisted.");
65  ASSERT_LOG(parent, "Parent must be non null.");
66  ASSERT_LOG(parent->id(), "Parent must be already persisted.");
67 
68  AuditEntryPtr parent_odb = std::dynamic_pointer_cast<AuditEntry>(parent);
69  ASSERT_LOG(parent_odb, "Parent object was not an instance of AuditEntry");
70 
71  return Audit::GroupEvent::create(database, target_group, parent_odb);
72 }
73 
75 {
76  ASSERT_LOG(database, "Database cannot be null.");
77 
78  return Audit::WSAPICall::create(database);
79 }
80 
83  Auth::UserPtr target_user, IAuditEntryPtr parent)
84 {
85  ASSERT_LOG(database, "Database cannot be null.");
86  ASSERT_LOG(target_group, "Group shall not be null.");
87  ASSERT_LOG(target_group->id(), "Group must be already persisted.");
88  ASSERT_LOG(target_user, "User shall not be null.");
89  ASSERT_LOG(target_user->id(), "User must be already persisted.");
90 
91  AuditEntryPtr parent_odb = std::dynamic_pointer_cast<AuditEntry>(parent);
92  ASSERT_LOG(parent_odb, "Parent object was not an instance of AuditEntry");
93 
94  return Audit::UserGroupMembershipEvent::create(database, target_group,
95  target_user, parent_odb);
96 }
97 
99  Cred::ICredentialPtr target_cred,
100  IAuditEntryPtr parent)
101 {
102  ASSERT_LOG(database, "Database cannot be null.");
103  ASSERT_LOG(target_cred, "Credential shall not be null.");
104  ASSERT_LOG(target_cred->id(), "Credential must be already persisted.");
105 
106  AuditEntryPtr parent_odb = std::dynamic_pointer_cast<AuditEntry>(parent);
107  ASSERT_LOG(parent_odb, "Parent object was not an instance of AuditEntry");
108 
109  return Audit::CredentialEvent::create(database, target_cred, parent_odb);
110 }
111 
113  Tools::ISchedulePtr target_sched,
114  IAuditEntryPtr parent)
115 {
116  ASSERT_LOG(database, "Database cannot be null.");
117  ASSERT_LOG(target_sched, "Schedule shall not be null.");
118  ASSERT_LOG(target_sched->id(), "Schedule must be already persisted.");
119 
120  auto parent_odb = assert_cast<AuditEntryPtr>(parent);
121  return Audit::ScheduleEvent::create(database, target_sched, parent_odb);
122 }
123 
125  IAuditEntryPtr parent)
126 {
127  ASSERT_LOG(database, "Database cannot be null.");
128  ASSERT_LOG(target_door, "Target door must be non null.");
129  ASSERT_LOG(target_door->id(), "Target door must be already persisted.");
130  ASSERT_LOG(parent, "Parent must be non null.");
131  ASSERT_LOG(parent->id(), "Parent must be already persisted.");
132 
133  AuditEntryPtr parent_odb = std::dynamic_pointer_cast<AuditEntry>(parent);
134  ASSERT_LOG(parent_odb, "Parent object was not an instance of AuditEntry");
135 
136  return Audit::DoorEvent::create(database, target_door, parent_odb);
137 }
138 
140  Auth::IAccessPointPtr target_ap,
141  IAuditEntryPtr parent)
142 {
143  ASSERT_LOG(database, "Database cannot be null.");
144  ASSERT_LOG(target_ap, "Target AccessPoint must be non null.");
145  ASSERT_LOG(target_ap->id(), "Target AccessPoint must be already persisted.");
146  ASSERT_LOG(parent, "Parent must be non null.");
147  ASSERT_LOG(parent->id(), "Parent must be already persisted.");
148 
149  AuditEntryPtr parent_odb = std::dynamic_pointer_cast<AuditEntry>(parent);
150  ASSERT_LOG(parent_odb, "Parent object was not an instance of AuditEntry");
151 
152  return Audit::AccessPointEvent::create(database, target_ap, parent_odb);
153 }
154 
156  update::IUpdatePtr target_update,
157  IAuditEntryPtr parent)
158 {
159  ASSERT_LOG(database, "Database cannot be null.");
160  ASSERT_LOG(target_update, "Target AccessPoint must be non null.");
161  ASSERT_LOG(target_update->id(), "Target AccessPoint must be already persisted.");
162  ASSERT_LOG(parent, "Parent must be non null.");
163  ASSERT_LOG(parent->id(), "Parent must be already persisted.");
164 
165  AuditEntryPtr parent_odb = std::dynamic_pointer_cast<AuditEntry>(parent);
166  ASSERT_LOG(parent_odb, "Parent object was not an instance of AuditEntry");
167 
168  return Audit::UpdateEvent::create(database, target_update, parent_odb);
169 }
170 
172  IAuditEntryPtr parent)
173 {
174  ASSERT_LOG(database, "Database cannot be null.");
175  ASSERT_LOG(target_zone, "Target zone must be non null.");
176  ASSERT_LOG(target_zone->id(), "Target zone must be already persisted.");
177  ASSERT_LOG(parent, "Parent must be non null.");
178  ASSERT_LOG(parent->id(), "Parent must be already persisted.");
179 
180  AuditEntryPtr parent_odb = std::dynamic_pointer_cast<AuditEntry>(parent);
181  ASSERT_LOG(parent_odb, "Parent object was not an instance of AuditEntry");
182 
183  return Audit::ZoneEvent::create(database, target_zone, parent_odb);
184 }
AccessPoint.hpp
AuditFactory.hpp
Leosac::Tools::ISchedulePtr
std::shared_ptr< ISchedule > ISchedulePtr
Definition: ToolsFwd.hpp:37
Leosac::Audit::Factory::AccessPointEvent
static IAccessPointEventPtr AccessPointEvent(const DBPtr &database, Auth::IAccessPointPtr target_ap, IAuditEntryPtr parent)
Definition: AuditFactory.cpp:139
IUpdate.hpp
Leosac::Audit::AuditEntryPtr
std::shared_ptr< AuditEntry > AuditEntryPtr
Definition: AuditFwd.hpp:81
IZone.hpp
ZoneEvent.hpp
Leosac::Audit::WSAPICall::create
static WSAPICallPtr create(const DBPtr &database)
Definition: WSAPICall.cpp:35
Leosac::Audit::UserEvent::create
static std::shared_ptr< UserEvent > create(const DBPtr &database, Auth::UserPtr target_user, AuditEntryPtr parent)
Definition: UserEvent.cpp:30
Leosac::Audit::IAccessPointEventPtr
std::shared_ptr< IAccessPointEvent > IAccessPointEventPtr
Definition: AuditFwd.hpp:67
ASSERT_LOG
#define ASSERT_LOG(cond, msg)
Definition: log.hpp:190
Leosac::Auth::UserPtr
std::shared_ptr< User > UserPtr
Definition: AuthFwd.hpp:31
User.hpp
Leosac::update::IUpdatePtr
std::shared_ptr< IUpdate > IUpdatePtr
Definition: UpdateFwd.hpp:42
Leosac::Audit::Factory::DoorEvent
static IDoorEventPtr DoorEvent(const DBPtr &database, Auth::IDoorPtr target_door, IAuditEntryPtr parent)
Definition: AuditFactory.cpp:124
Leosac::DBPtr
std::shared_ptr< odb::database > DBPtr
Definition: db_fwd.hpp:31
Leosac::Audit::IZoneEventPtr
std::shared_ptr< IZoneEvent > IZoneEventPtr
Definition: AuditFwd.hpp:73
Leosac::Audit::IAuditEntryPtr
std::shared_ptr< IAuditEntry > IAuditEntryPtr
Definition: AuditFwd.hpp:40
Leosac::Auth::IAccessPointPtr
std::shared_ptr< IAccessPoint > IAccessPointPtr
Definition: AuthFwd.hpp:127
CredentialEvent.hpp
Door.hpp
Leosac::Audit::Factory::ZoneEvent
static IZoneEventPtr ZoneEvent(const DBPtr &database, Auth::IZonePtr target_zone, IAuditEntryPtr parent)
Definition: AuditFactory.cpp:171
WSAPICall.hpp
UpdateEvent.hpp
Leosac::Audit
The Audit namespace provides classes and facilities to keep track of what's happening on the Leosac d...
Definition: AccessPointEvent.hpp:27
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Audit::GroupEvent::create
static std::shared_ptr< GroupEvent > create(const DBPtr &database, Auth::GroupPtr target_group, AuditEntryPtr parent)
Definition: GroupEvent.cpp:30
Leosac::Audit::UserGroupMembershipEvent::create
static UserGroupMembershipEventPtr create(const DBPtr &database, Auth::GroupPtr target_group, Auth::UserPtr target_user, AuditEntryPtr parent)
Definition: UserGroupMembershipEvent.cpp:42
Leosac::Audit::IUserEventPtr
std::shared_ptr< IUserEvent > IUserEventPtr
Definition: AuditFwd.hpp:46
DoorEvent.hpp
Group.hpp
Leosac::Audit::DoorEvent::create
static std::shared_ptr< DoorEvent > create(const DBPtr &database, Auth::IDoorPtr target_door, AuditEntryPtr parent)
Definition: DoorEvent.cpp:38
AccessPointEvent.hpp
Leosac::Auth::IDoorPtr
std::shared_ptr< IDoor > IDoorPtr
Definition: AuthFwd.hpp:104
Leosac::Auth::GroupPtr
std::shared_ptr< Group > GroupPtr
Definition: AuthFwd.hpp:37
ScheduleEvent.hpp
Leosac::Audit::IDoorEventPtr
std::shared_ptr< IDoorEvent > IDoorEventPtr
Definition: AuditFwd.hpp:64
UserEvent.hpp
Leosac::Audit::IWSAPICallPtr
std::shared_ptr< IWSAPICall > IWSAPICallPtr
Definition: AuditFwd.hpp:52
Leosac::Audit::ScheduleEvent::create
static std::shared_ptr< ScheduleEvent > create(const DBPtr &database, Tools::ISchedulePtr target_sched, AuditEntryPtr parent)
Definition: ScheduleEvent.cpp:33
Leosac::Audit::IScheduleEventPtr
std::shared_ptr< IScheduleEvent > IScheduleEventPtr
Definition: AuditFwd.hpp:61
Leosac::Audit::UpdateEvent::create
static std::shared_ptr< UpdateEvent > create(const DBPtr &database, update::IUpdatePtr target_update, AuditEntryPtr parent)
Definition: UpdateEvent.cpp:31
Leosac::Audit::Factory::UserEvent
static IUserEventPtr UserEvent(const DBPtr &database, Auth::UserPtr target_user, IAuditEntryPtr parent)
Definition: AuditFactory.cpp:43
Leosac::Audit::Factory::GroupEvent
static IGroupEventPtr GroupEvent(const DBPtr &database, Auth::GroupPtr target_group, IAuditEntryPtr parent)
Definition: AuditFactory.cpp:58
Leosac::Audit::AccessPointEvent::create
static std::shared_ptr< AccessPointEvent > create(const DBPtr &database, Auth::IAccessPointPtr target_ap, AuditEntryPtr parent)
Definition: AccessPointEvent.cpp:37
Leosac::Audit::ICredentialEventPtr
std::shared_ptr< ICredentialEvent > ICredentialEventPtr
Definition: AuditFwd.hpp:58
Leosac::Cred::ICredentialPtr
std::shared_ptr< ICredential > ICredentialPtr
Definition: CredentialFwd.hpp:32
log.hpp
Leosac::Auth::IZonePtr
std::shared_ptr< IZone > IZonePtr
Definition: AuthFwd.hpp:116
Leosac::Audit::CredentialEvent::create
static std::shared_ptr< CredentialEvent > create(const DBPtr &database, Cred::ICredentialPtr target_cred, AuditEntryPtr parent)
Definition: CredentialEvent.cpp:33
UserGroupMembershipEvent.hpp
Leosac::Audit::ZoneEvent::create
static std::shared_ptr< ZoneEvent > create(const DBPtr &database, Auth::IZonePtr target_zone, AuditEntryPtr parent)
Definition: ZoneEvent.cpp:37
Leosac::Audit::Factory::ScheduleEvent
static IScheduleEventPtr ScheduleEvent(const DBPtr &database, Tools::ISchedulePtr target_sched, IAuditEntryPtr parent)
Definition: AuditFactory.cpp:112
GroupEvent.hpp
Leosac::Audit::IUserGroupMembershipEventPtr
std::shared_ptr< IUserGroupMembershipEvent > IUserGroupMembershipEventPtr
Definition: AuditFwd.hpp:55
Leosac::Audit::Factory::WSAPICall
static IWSAPICallPtr WSAPICall(const DBPtr &database)
Definition: AuditFactory.cpp:74
Leosac::Audit::IGroupEventPtr
std::shared_ptr< IGroupEvent > IGroupEventPtr
Definition: AuditFwd.hpp:49
Leosac::Audit::Factory::UpdateEvent
static IUpdateEventPtr UpdateEvent(const DBPtr &database, update::IUpdatePtr target_update, IAuditEntryPtr parent)
Definition: AuditFactory.cpp:155
AssertCast.hpp
Leosac::Audit::IUpdateEventPtr
std::shared_ptr< IUpdateEvent > IUpdateEventPtr
Definition: AuditFwd.hpp:70
Leosac::Audit::Factory::UserGroupMembershipEvent
static IUserGroupMembershipEventPtr UserGroupMembershipEvent(const DBPtr &database, Auth::GroupPtr target_group, Auth::UserPtr target_user, IAuditEntryPtr parent)
Definition: AuditFactory.cpp:82
Leosac::Audit::Factory::CredentialEventPtr
static ICredentialEventPtr CredentialEventPtr(const DBPtr &database, Cred::ICredentialPtr target_cred, IAuditEntryPtr parent)
Definition: AuditFactory.cpp:98