permissions_manager.h
1 /*
2 * <one line to give the program's name and a brief idea of what it does.>
3 * Copyright (C) 2021 <copyright holder> <email>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 #ifndef PERMISSIONS_MANAGER
21 #define PERMISSIONS_MANAGER
22 
23 
24 #include <string>
25 #include <list>
26 #include <algorithm>
27 #include <mutex>
28 
29 #include "functions/action.h"
30 #include "security/permission.h"
31 #include "tools/route.h"
32 #include "tools/output_logger.h"
33 
34 namespace NAF
35 {
36  namespace Security
37  {
38  class PermissionsManager;
39  }
40 }
41 
42 using namespace Poco;
43 
44 
46 {
47  public:
48  using PermissionToLoad = Poco::Tuple<std::string, std::string, std::string, int, std::string, bool, bool>;
49 
51 
52  std::list<Permission>& get_permissions()
53  {
54  auto& var = permissions_;
55  return var;
56  }
57  std::map<std::string, ActionType>& get_action_type_map()
58  {
59  auto& var = action_type_map_;
60  return var;
61  }
62 
63  static void LoadPermissions_();
64  static std::_List_iterator<Permission> FindPermission_(Tools::Route& route, std::string user, std::string action_type);
65  static bool VerifyPermission_(Tools::Route& requested_route, User& user, std::_List_iterator<Permission> found_permission);
66 
67  protected:
68  static void FillActionTypeMap_();
69 
70  private:
71  static std::mutex mutex_;
72  static std::list<Permission> permissions_;
73  static std::map<std::string, ActionType> action_type_map_;
74 };
75 
76 
77 #endif // PERMISSIONS_MANAGER
Definition: permissions_manager.h:46
Definition: user.h:37
Definition: route.h:49