Leosac  0.7.0
OpenSourceAccessControl
CredentialEventSerializer.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 
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  const SecurityContext &sc)
34 {
35  auto serialized = AuditJSON::serialize(in, sc);
36  // Now we override the type.
37  ASSERT_LOG(serialized.at("type").is_string(),
38  "Base audit serialization did something unexpected.");
39  serialized["type"] = "audit-credential-event";
40 
41  serialized["relationships"]["target"] = {
42  {{"id", in.target_id()}, {"type", "credential"}}};
43 
45  {
46  serialized["attributes"]["before"] = in.before();
47  serialized["attributes"]["after"] = in.after();
48  }
49 
50  return serialized;
51 }
52 }
53 }
54 }
nlohmann::json json
This is the header file for a generated source file, GitSHA1.cpp.
virtual void before(const std::string &repr)=0
An optional JSON representation of the object before the event took place.
Read the audit log and access additional information, such as the JSON "before" and "after" field...
static json serialize(const Audit::ICredentialEvent &in, const SecurityContext &sc)
virtual void after(const std::string &repr)=0
An optional JSON representation of the object after the event took place.
virtual bool check_permission(Action a, const ActionParam &ap) const
Check for the permission to perform action a with parameters ap.
A SecurityContext is used to query permission while doing an operation.
#define ASSERT_LOG(cond, msg)
Definition: log.hpp:221
virtual Cred::CredentialId target_id() const =0
static json serialize(const Audit::IAuditEntry &in, const SecurityContext &sc)
Audit interface to Credential related events.