Leosac  0.8.0
Open Source Access Control
UserGroupMembershipSerializer.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 
22 #include "tools/JSONUtils.hpp"
23 #include "tools/log.hpp"
24 
25 using namespace Leosac;
26 using namespace Leosac::Auth;
27 
29  const Auth::UserGroupMembership &membership, const SecurityContext &)
30 {
31  json serialized{};
32 
33  auto timestamp = boost::posix_time::to_time_t(membership.timestamp());
34  serialized["id"] = membership.id();
35  serialized["type"] = "user-group-membership";
36  serialized["attributes"] = {{"rank", static_cast<int>(membership.rank())},
37  {"timestamp", timestamp}};
38  serialized["relationships"]["user"] = {
39  {"data", {{"id", membership.user_id()}, {"type", "user"}}}};
40  serialized["relationships"]["group"] = {
41  {"data", {{"id", membership.group_id()}, {"type", "group"}}}};
42 
43  return serialized;
44 }
45 
47  const json &,
48  const SecurityContext &)
49 {
50  ASSERT_LOG(false, "Not implemented.");
51 }
52 
54  const Auth::UserGroupMembership &in, const SecurityContext &sc)
55 {
56  return UserGroupMembershipJSONSerializer::serialize(in, sc).dump(4);
57 }
58 
60  Auth::UserGroupMembership &out, const std::string &in, const SecurityContext &sc)
61 {
62  auto tmp = json::parse(in);
64 }
Leosac::Auth
Holds classes relevant to the Authentication and Authorization subsystem.
Definition: AccessPoint.hpp:27
Leosac::json
nlohmann::json json
Definition: AuditSerializer.hpp:29
UserGroupMembershipSerializer.hpp
Leosac::Auth::UserGroupMembership::group_id
GroupId group_id() const
Definition: UserGroupMembership.cpp:81
ASSERT_LOG
#define ASSERT_LOG(cond, msg)
Definition: log.hpp:190
Leosac::Auth::UserGroupMembership::user_id
UserId user_id() const
Definition: UserGroupMembership.cpp:76
UserGroupMembership.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::UserGroupMembershipJSONSerializer::unserialize
static void unserialize(Auth::UserGroupMembership &out, const json &in, const SecurityContext &sc)
Definition: UserGroupMembershipSerializer.cpp:46
Leosac::UserGroupMembershipJSONStringSerializer::serialize
static std::string serialize(const Auth::UserGroupMembership &in, const SecurityContext &sc)
Definition: UserGroupMembershipSerializer.cpp:53
JSONUtils.hpp
Leosac::Auth::UserGroupMembership::timestamp
const boost::posix_time::ptime & timestamp() const
Definition: UserGroupMembership.cpp:61
Leosac::UserGroupMembershipJSONStringSerializer::unserialize
static void unserialize(Auth::UserGroupMembership &out, const std::string &in, const SecurityContext &sc)
Definition: UserGroupMembershipSerializer.cpp:59
Leosac::Auth::UserGroupMembership::rank
GroupRank rank() const
Definition: UserGroupMembership.cpp:66
log.hpp
Leosac::SecurityContext
A SecurityContext is used to query permission while doing an operation.
Definition: SecurityContext.hpp:40
Leosac::UserGroupMembershipJSONSerializer::serialize
static json serialize(const Auth::UserGroupMembership &ugm, const SecurityContext &sc)
Definition: UserGroupMembershipSerializer.cpp:28
Leosac::Auth::UserGroupMembership
Describe the membership of an User with regroup to a Group.
Definition: UserGroupMembership.hpp:39
Leosac::Auth::UserGroupMembership::id
const UserGroupMembershipId & id() const
Definition: UserGroupMembership.cpp:36