Leosac  0.8.0
Open Source Access Control
ZoneEventSerializer.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 "ZoneEventSerializer.hpp"
21 #include "AuditSerializer.hpp"
22 #include "core/SecurityContext.hpp"
24 #include "tools/log.hpp"
25 
26 namespace Leosac
27 {
28 namespace Audit
29 {
30 namespace Serializer
31 {
33 {
34  auto serialized = AuditJSON::serialize(in, sc);
35  // Now we override the type.
36  ASSERT_LOG(serialized.at("type").is_string(),
37  "Base audit serialization did something unexpected.");
38  serialized["type"] = "audit-zone-event";
39 
40  serialized["relationships"]["target"] = {
41  {{"id", in.target_id()}, {"type", "zone"}}};
42 
44  {
45  serialized["attributes"]["before"] = in.before();
46  serialized["attributes"]["after"] = in.after();
47  }
48 
49  return serialized;
50 }
51 }
52 }
53 }
Leosac::json
nlohmann::json json
Definition: AuditSerializer.hpp:29
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::Audit::IZoneEvent::before
virtual void before(const std::string &repr)=0
An optional JSON representation of the object before the event took place.
AuditSerializer.hpp
ASSERT_LOG
#define ASSERT_LOG(cond, msg)
Definition: log.hpp:190
Leosac::Audit::Serializer::ZoneEventJSON::serialize
static json serialize(const Audit::IZoneEvent &in, const SecurityContext &sc)
Definition: ZoneEventSerializer.cpp:32
IZoneEvent.hpp
ZoneEventSerializer.hpp
SecurityContext.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Audit::Serializer::AuditJSON::serialize
static json serialize(const Audit::IAuditEntry &in, const SecurityContext &sc)
Definition: AuditSerializer.cpp:30
Leosac::Audit::IZoneEvent::after
virtual void after(const std::string &repr)=0
An optional JSON representation of the object after the event took place.
log.hpp
Leosac::Audit::IZoneEvent
Interface that describes an Audit object for zone related event.
Definition: IZoneEvent.hpp:32
Leosac::Audit::IZoneEvent::target_id
virtual Auth::ZoneId target_id() const =0
Leosac::SecurityContext::Action::AUDIT_READ_FULL
@ AUDIT_READ_FULL
Read the audit log and access additional information, such as the JSON "before" and "after" field.
Leosac::SecurityContext
A SecurityContext is used to query permission while doing an operation.
Definition: SecurityContext.hpp:40