Leosac  0.7.0
OpenSourceAccessControl
AccessPointService.hpp
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 
20 #pragma once
21 
22 #include "LeosacFwd.hpp"
23 #include "core/audit/AuditFwd.hpp"
24 #include "tools/AssertCast.hpp"
25 #include "tools/JSONUtils.hpp"
26 #include "tools/log.hpp"
28 #include <boost/type_index.hpp>
29 #include <map>
30 #include <type_traits>
31 
32 namespace Leosac
33 {
34 namespace Auth
35 {
36 
44 {
46  const json &req, IAccessPointPtr ap) = 0;
47 
49  const json &req) = 0;
50 
52  const json &req, IAccessPointPtr ap) = 0;
53 };
54 
70  : public ExtensibleSerializer<json, Auth::IAccessPoint, const SecurityContext &>
71 {
72  public:
79  void register_backend(const std::string &controller_module,
80  AccessPointBackend *backend)
81  {
82  std::lock_guard<std::mutex> lg(mutex_);
83 
84  ASSERT_LOG(backends_.count(controller_module) == 0,
85  "A backend for this module is already registered.");
86  backends_[controller_module] = backend;
87  }
88 
89  void unregister_backend(const std::string &controller_module)
90  {
91  std::lock_guard<std::mutex> lg(mutex_);
92 
93  backends_.erase(controller_module);
94  }
95 
101  AccessPointBackend *get_backend(const std::string &controller_module);
102 
103  private:
104  mutable std::mutex mutex_;
105 
110  std::map<std::string, AccessPointBackend *> backends_;
111 };
112 }
113 }
nlohmann::json json
void register_backend(const std::string &controller_module, AccessPointBackend *backend)
Register an AccessPointBackend for controller_module.
This is the header file for a generated source file, GitSHA1.cpp.
Provides dynamic serializers management for a given object&#39;s hierarchy.
virtual json update(SecurityContext &sec_ctx, Audit::IAuditEntryPtr, const json &req, IAccessPointPtr ap)=0
std::shared_ptr< IAuditEntry > IAuditEntryPtr
Definition: AuditFwd.hpp:40
std::shared_ptr< IAccessPoint > IAccessPointPtr
Definition: AuthFwd.hpp:127
An AccessPointBackend object is used for module to provide implementation for access point CRUD opera...
This service lets various AccessPoint backend register and provide implementation to use by the Acces...
A SecurityContext is used to query permission while doing an operation.
void unregister_backend(const std::string &controller_module)
#define ASSERT_LOG(cond, msg)
Definition: log.hpp:221
virtual json create(SecurityContext &sec_ctx, Audit::IAuditEntryPtr, const json &req)=0
virtual json erase(SecurityContext &sec_ctx, Audit::IAuditEntryPtr, const json &req, IAccessPointPtr ap)=0
std::map< std::string, AccessPointBackend * > backends_
The various backend for various type of AccessPoint.