Leosac  0.8.0
Open Source Access Control
AccessPointSerializer.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 "DoorSerializer.hpp"
23 #include "tools/JSONUtils.hpp"
24 
25 using namespace Leosac;
26 using namespace Leosac::Auth;
27 
29  const SecurityContext &)
30 {
31  // todo: type probably needs to be runtime-generated
32  // based on the controller-module value
33  json serialized = {{"id", ap.id()},
34  {"type", "access-point"},
35  {"attributes",
36  {
37  {"alias", ap.alias()},
38  {"description", ap.description()},
39  {"controller-module", ap.controller_module()},
40  }}};
41 
42  if (ap.door_id())
43  {
44  serialized["relationships"]["door"] = {
45  {"data", {{"id", ap.door_id()}, {"type", "door"}}}};
46  }
47  return serialized;
48 }
49 
51  const SecurityContext &)
52 {
53  using namespace Leosac::JSONUtil;
54 
55  out.alias(extract_with_default(in, "alias", out.alias()));
56  out.description(extract_with_default(in, "description", out.description()));
57 }
58 
60  const SecurityContext &sc)
61 {
62  return AccessPointJSONSerializer::serialize(in, sc).dump(4);
63 }
64 
66  const std::string &in,
67  const SecurityContext &sc)
68 {
69  auto tmp = json::parse(in);
71 }
Leosac::Auth
Holds classes relevant to the Authentication and Authorization subsystem.
Definition: AccessPoint.hpp:27
AccessPointSerializer.hpp
DoorSerializer.hpp
Leosac::json
nlohmann::json json
Definition: AuditSerializer.hpp:29
Leosac::AccessPointJSONStringSerializer::unserialize
static void unserialize(Auth::IAccessPoint &out, const std::string &in, const SecurityContext &sc)
Definition: AccessPointSerializer.cpp:65
Leosac::JSONUtil
Add a few useful extraction functions.
Definition: JSONUtils.cpp:27
Leosac::JSONUtil::extract_with_default
std::chrono::system_clock::time_point extract_with_default(const nlohmann::json &obj, const std::string &key, const std::chrono::system_clock::time_point &tp)
Extract an ISO 8601 datetime string from a json object.
Definition: JSONUtils.cpp:45
Leosac::Auth::IAccessPoint::controller_module
virtual void controller_module(const std::string &ctrl_mod)=0
IAccessPoint.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Auth::IAccessPoint::id
virtual AccessPointId id() const =0
Leosac::AccessPointJSONStringSerializer::serialize
static std::string serialize(const Auth::IAccessPoint &in, const SecurityContext &sc)
Definition: AccessPointSerializer.cpp:59
Leosac::Auth::IAccessPoint::alias
virtual const std::string & alias() const =0
Leosac::AccessPointJSONSerializer::serialize
static json serialize(const Auth::IAccessPoint &ap, const SecurityContext &sc)
Definition: AccessPointSerializer.cpp:28
JSONUtils.hpp
Leosac::AccessPointJSONSerializer::unserialize
static void unserialize(Auth::IAccessPoint &out, const json &in, const SecurityContext &sc)
Definition: AccessPointSerializer.cpp:50
Leosac::Auth::IAccessPoint::door_id
virtual DoorId door_id() const =0
Leosac::Auth::IAccessPoint
An interface for access point.
Definition: IAccessPoint.hpp:35
Leosac::Auth::IAccessPoint::description
virtual const std::string & description() const =0
Leosac::SecurityContext
A SecurityContext is used to query permission while doing an operation.
Definition: SecurityContext.hpp:40