Leosac  0.7.0
OpenSourceAccessControl
PolymorphicCredentialSerializer.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 "PinCodeSerializer.hpp"
22 #include "RFIDCardSerializer.hpp"
23 #include "core/SecurityContext.hpp"
25 #include "tools/JSONUtils.hpp"
26 #include "tools/log.hpp"
27 
28 using namespace Leosac;
29 using namespace Leosac::Cred;
30 
31 // JSON
32 
34  const SecurityContext &sc)
35 {
36  HelperSerialize h(sc);
37  in.accept(h);
38  return h.result_;
39 }
40 
42  const json &in,
43  const SecurityContext &sc)
44 {
45  HelperUnserialize h(sc, in);
46  out.accept(h);
47 }
48 
49 std::string
51 {
53  in.accept(h);
54  ASSERT_LOG(h.result_.find("type") != h.result_.end(),
55  "The serializer didn't set a type.");
56  ASSERT_LOG(h.result_.at("type").is_string(), "Type is not a string.");
57  return h.result_.at("type");
58 }
59 
60 
61 // HELPERS
62 
64  const SecurityContext &sc, const json &payload)
65  : security_context_(sc)
66  , payload_(payload)
67 {
68 }
69 
71  Cred::IRFIDCard &t)
72 {
74 }
75 
77 {
79 }
80 
82  const SecurityContext &sc)
83  : security_context_(sc)
84 {
85 }
86 
88 {
90 }
91 
93 {
95 }
96 
97 
98 // JSONString
99 
100 
101 std::string
103  const SecurityContext &sc)
104 {
105  return PolymorphicCredentialJSONSerializer::serialize(in, sc).dump(4);
106 }
nlohmann::json json
static std::string type_name(const Cred::ICredential &in)
Returns the "type-name" of the credential.
This is the header file for a generated source file, GitSHA1.cpp.
virtual void accept(::Leosac::Tools::BaseVisitor &)=0
Accept a visitor that may mutate this.
static SecurityContext & instance()
Interface for RFIDCard credential.
Definition: IRFIDCard.hpp:32
Base interface for credential objects.
Definition: ICredential.hpp:35
static void unserialize(Cred::IRFIDCard &out, const json &in, const SecurityContext &sc)
static void unserialize(Cred::IPinCode &out, const json &in, const SecurityContext &sc)
const SecurityContext & security_context_
Reference to the security context.
Interface for PinCode credentials.
Definition: IPinCode.hpp:32
json result_
Store the result here because we can&#39;t return from the visit() method.
static json serialize(const Cred::IRFIDCard &in, const SecurityContext &sc)
static json serialize(const Cred::ICredential &in, const SecurityContext &sc)
static std::string serialize(const Cred::ICredential &in, const SecurityContext &sc)
static void unserialize(Cred::ICredential &out, const json &in, const SecurityContext &sc)
A SecurityContext is used to query permission while doing an operation.
#define ASSERT_LOG(cond, msg)
Definition: log.hpp:221
static json serialize(const Cred::IPinCode &in, const SecurityContext &sc)
const SecurityContext & security_context_
Reference to the security context.