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 "query/database_manager.h"
30 #include "functions/action.h"
31 #include "security/permission.h"
32 #include "tools/route.h"
33 #include "tools/output_logger.h"
34 
35 namespace NAF
36 {
37  namespace Security
38  {
39  class PermissionsManager;
40  }
41 }
42 
43 using namespace Poco;
44 
45 
47 {
48  public:
49  using PermissionToLoad = Poco::Tuple<std::string, std::string, std::string, int, std::string, bool, bool>;
50 
52 
53  static std::list<Permission>& get_permissions()
54  {
55  auto& var = permissions_;
56  return var;
57  }
58  static std::map<std::string, ActionType>& get_action_type_map()
59  {
60  auto& var = action_type_map_;
61  return var;
62  }
63  static Query::DatabaseManager::Credentials& get_credentials()
64  {
65  auto& var = credentials_;
66  return var;
67  }
68 
69  static void LoadPermissions_();
70  static std::_List_iterator<Permission> FindPermission_(Tools::Route& route, int id_user, std::string action_type);
71  static bool VerifyPermission_(Tools::Route& requested_route, User& user, std::_List_iterator<Permission> found_permission);
72 
73  protected:
74  static void FillActionTypeMap_();
75 
76  private:
77  static std::mutex mutex_;
78  static std::list<Permission> permissions_;
79  static std::map<std::string, ActionType> action_type_map_;
80  static Query::DatabaseManager::Credentials credentials_;
81 };
82 
83 
84 #endif // PERMISSIONS_MANAGER
Definition: permissions_manager.h:47
Definition: user.h:37
Definition: route.h:49
Definition: database_manager.h:51