Leosac  0.8.0
Open Source Access Control
PolymorphicAuditSerializer.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 "LeosacFwd.hpp"
24 #include "tools/Visitor.hpp"
25 #include <nlohmann/json.hpp>
26 #include <string>
27 
28 namespace Leosac
29 {
30 using json = nlohmann::json;
31 
32 namespace Audit
33 {
34 namespace Serializer
35 {
50 {
54  static json serialize(const Audit::IAuditEntry &in, const SecurityContext &sc);
55 
61  static std::string type_name(const Audit::IAuditEntry &in);
62 
63  private:
67  struct HelperSerialize : public Tools::Visitor<Audit::IUserEvent>,
68  public Tools::Visitor<Audit::IWSAPICall>,
69  public Tools::Visitor<Audit::IScheduleEvent>,
70  public Tools::Visitor<Audit::IGroupEvent>,
71  public Tools::Visitor<Audit::ICredentialEvent>,
72  public Tools::Visitor<Audit::IDoorEvent>,
73  public Tools::Visitor<Audit::IUserGroupMembershipEvent>,
74  public Tools::Visitor<Audit::IUpdateEvent>,
75  public Tools::Visitor<Audit::IZoneEvent>
76  {
78 
79  virtual void visit(const Audit::IUserEvent &t) override;
80  virtual void visit(const Audit::IWSAPICall &t) override;
81  virtual void visit(const Audit::IScheduleEvent &t) override;
82  virtual void visit(const Audit::IGroupEvent &t) override;
83  virtual void visit(const Audit::ICredentialEvent &t) override;
84  virtual void visit(const Audit::IDoorEvent &t) override;
85  virtual void visit(const Audit::IUserGroupMembershipEvent &t) override;
86  virtual void visit(const Audit::IUpdateEvent &t) override;
87  virtual void visit(const Audit::IZoneEvent &t) override;
88 
94  virtual void cannot_visit(const Tools::IVisitable &visitable) override;
95 
101 
106  };
107 };
108 }
109 }
110 }
Leosac::json
nlohmann::json json
Definition: AuditSerializer.hpp:29
Leosac::Audit::IGroupEvent
Interface that describes an Audit object for group related event.
Definition: IGroupEvent.hpp:36
Leosac::Audit::IDoorEvent
Interface that describes an Audit object for door related event.
Definition: IDoorEvent.hpp:32
Leosac::Audit::Serializer::PolymorphicAuditJSON
A serializer that handle any type of Audit event and will try to perform deep serialization.
Definition: PolymorphicAuditSerializer.hpp:49
json
nlohmann::json json
Definition: WSServer.cpp:76
Leosac::Audit::ICredentialEvent
Audit interface to Credential related events.
Definition: ICredentialEvent.hpp:32
LeosacFwd.hpp
Leosac::Audit::Serializer::PolymorphicAuditJSON::HelperSerialize::result_
json result_
Store the result here because we can't return from the visit() method.
Definition: PolymorphicAuditSerializer.hpp:100
Leosac::Audit::IUserEvent
Interface that describes an Audit object when a user-related event happens.
Definition: IUserEvent.hpp:37
Leosac::Tools::Visitor
A Visitor object.
Definition: Visitor.hpp:64
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Audit::Serializer::PolymorphicAuditJSON::HelperSerialize
Non static helper that can visit a core audit object.
Definition: PolymorphicAuditSerializer.hpp:67
Leosac::Audit::Serializer::PolymorphicAuditJSON::HelperSerialize::visit
virtual void visit(const Audit::IUserEvent &t) override
Definition: PolymorphicAuditSerializer.cpp:67
Leosac::Audit::Serializer::PolymorphicAuditJSON::HelperSerialize::HelperSerialize
HelperSerialize(const SecurityContext &sc)
Definition: PolymorphicAuditSerializer.cpp:62
Visitor.hpp
Leosac::Tools::IVisitable
Base class to make an object visitable.
Definition: IVisitable.hpp:43
Leosac::Audit::IScheduleEvent
Audit interface to Schedule related events.
Definition: IScheduleEvent.hpp:32
Leosac::Audit::Serializer::PolymorphicAuditJSON::type_name
static std::string type_name(const Audit::IAuditEntry &in)
Returns the "type-name" of the audit entry.
Definition: PolymorphicAuditSerializer.cpp:52
Leosac::Audit::IAuditEntry
Base interface to Audit object.
Definition: IAuditEntry.hpp:47
Leosac::Audit::Serializer::PolymorphicAuditJSON::HelperSerialize::cannot_visit
virtual void cannot_visit(const Tools::IVisitable &visitable) override
Called when no "hardcoded" audit type match, this method will delegate to runtime-registered serializ...
Definition: PolymorphicAuditSerializer.cpp:113
Leosac::Audit::IZoneEvent
Interface that describes an Audit object for zone related event.
Definition: IZoneEvent.hpp:32
Leosac::Audit::IUpdateEvent
Interface for update-related event.
Definition: IUpdateEvent.hpp:32
IAuditEntry.hpp
Leosac::Audit::Serializer::PolymorphicAuditJSON::serialize
static json serialize(const Audit::IAuditEntry &in, const SecurityContext &sc)
Perform deep serialization of the AuditEntry in.
Definition: PolymorphicAuditSerializer.cpp:44
Leosac::Audit::Serializer::PolymorphicAuditJSON::HelperSerialize::security_context_
const SecurityContext & security_context_
Reference to the security context.
Definition: PolymorphicAuditSerializer.hpp:105
Leosac::Audit::IUserGroupMembershipEvent
Interface to audit object that take care of tracking user/group membership change.
Definition: IUserGroupMembershipEvent.hpp:33
Leosac::SecurityContext
A SecurityContext is used to query permission while doing an operation.
Definition: SecurityContext.hpp:40
Leosac::Audit::IWSAPICall
An audit entry dedicated to tracing API call.
Definition: IWSAPICall.hpp:39