Leosac  0.7.0
OpenSourceAccessControl
CRUDResourceHandler.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 
25 #include <boost/optional.hpp>
26 #include <json.hpp>
27 #include <vector>
28 
29 namespace Leosac
30 {
31 namespace Module
32 {
33 namespace WebSockAPI
34 {
35 using json = nlohmann::json;
36 
41 {
42  public:
43  enum class Verb
44  {
45  CREATE,
46  READ,
47  UPDATE,
48  DELETE
49  };
50  boost::optional<json> process(const ClientMessage &msg);
51 
52  protected:
56  using ActionActionParam =
57  std::pair<SecurityContext::Action, SecurityContext::ActionParam>;
58 
62  virtual UserSecurityContext &security_context() const = 0;
63 
64  private:
65  virtual std::vector<ActionActionParam>
66  required_permission(Verb verb, const json &req) const = 0;
67 
68  virtual boost::optional<json> create_impl(const json &req) = 0;
69 
70  virtual boost::optional<json> read_impl(const json &req) = 0;
71 
72  virtual boost::optional<json> update_impl(const json &req) = 0;
73 
74  virtual boost::optional<json> delete_impl(const json &req) = 0;
75 
76  void enforce_permission(const std::vector<ActionActionParam> &);
77 
78  static Verb verb_from_request_type(const std::string &);
79 };
80 
85 {
86  protected:
88 
89  public:
91 
92  static CRUDResourceHandlerUPtr instanciate(RequestContext);
93 
94  protected:
96 
97  virtual UserSecurityContext &security_context() const override;
98 };
99 
104 {
105  public:
107 
108 
109  protected:
111 
113 
114  virtual UserSecurityContext &security_context() const override;
115 };
116 }
117 }
118 }
CRUDResourceHandlerUPtr(*)(RequestContext) Factory
virtual std::vector< ActionActionParam > required_permission(Verb verb, const json &req) const =0
This is the header file for a generated source file, GitSHA1.cpp.
virtual boost::optional< json > update_impl(const json &req)=0
std::unique_ptr< ExternalCRUDResourceHandler > ExternalCRUDResourceHandlerUPtr
Definition: WebSockFwd.hpp:42
virtual boost::optional< json > create_impl(const json &req)=0
A request context dedicated for websocket request that are handled by other modules.
std::unique_ptr< CRUDResourceHandler > CRUDResourceHandlerUPtr
Definition: WebSockFwd.hpp:39
static Verb verb_from_request_type(const std::string &)
boost::optional< json > process(const ClientMessage &msg)
std::pair< SecurityContext::Action, SecurityContext::ActionParam > ActionActionParam
A pair of Action and a generic ActionParam union.
Base CRUD handler for use within the websocket module.
nlohmann::json json
Definition: WSServer.cpp:76
A message sent by a client to Leosac.
Definition: Messages.hpp:54
ExternalCRUDResourceHandlerUPtr(*)(ModuleRequestContext) Factory
virtual UserSecurityContext & security_context() const =0
Helper function that returns the security context.
virtual boost::optional< json > delete_impl(const json &req)=0
Holds valuable pointer to provide context to a request.
A SecurityContext object for users.
virtual boost::optional< json > read_impl(const json &req)=0
void enforce_permission(const std::vector< ActionActionParam > &)