Leosac  0.7.0
OpenSourceAccessControl
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 }
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
nlohmann::json json
This is the header file for a generated source file, GitSHA1.cpp.
An interface for access point.
Add a few useful extraction functions.
Definition: JSONUtils.cpp:27
virtual AccessPointId id() const =0
virtual DoorId door_id() const =0
Holds classes relevant to the Authentication and Authorization subsystem.
Definition: AccessPoint.hpp:27
static json serialize(const Auth::IAccessPoint &ap, const SecurityContext &sc)
virtual const std::string & alias() const =0
A SecurityContext is used to query permission while doing an operation.
static void unserialize(Auth::IAccessPoint &out, const json &in, const SecurityContext &sc)
static std::string serialize(const Auth::IAccessPoint &in, const SecurityContext &sc)
virtual const std::string & description() const =0
static void unserialize(Auth::IAccessPoint &out, const std::string &in, const SecurityContext &sc)
virtual void controller_module(const std::string &ctrl_mod)=0