|
13 | 13 | #include "ecflow/base/AbstractServer.hpp" |
14 | 14 | #include "ecflow/base/Algorithms.hpp" |
15 | 15 | #include "ecflow/core/Overload.hpp" |
| 16 | +#include "ecflow/core/WhiteListFile.hpp" |
16 | 17 |
|
17 | 18 | namespace ecf { |
18 | 19 |
|
19 | | -struct Rules |
| 20 | +/// |
| 21 | +/// NodeRules represent permissions derived from the nodes themselves (based on ECF_PERMISSIONS permissions) |
| 22 | +/// |
| 23 | +struct NodeRules |
20 | 24 | { |
21 | 25 | }; |
22 | 26 |
|
| 27 | +/// |
| 28 | +/// WhiteListRules represent permissions define by a white list file |
| 29 | +/// |
| 30 | +struct WhiteListRules |
| 31 | +{ |
| 32 | + WhiteListRules(const WhiteListFile& file) : file_(file) {} |
| 33 | + const WhiteListFile& file_; |
| 34 | +}; |
| 35 | + |
| 36 | +/// |
| 37 | +/// Unrestricted represent no restrictions at all |
| 38 | +/// |
23 | 39 | struct Unrestricted |
24 | 40 | { |
25 | 41 | }; |
26 | 42 |
|
27 | 43 | struct AuthorisationService::Impl |
28 | 44 | { |
29 | 45 | Impl() : permissions_(Unrestricted{}) {} |
30 | | - explicit Impl(Rules&& rules) : permissions_(std::move(rules)) {} |
| 46 | + explicit Impl(NodeRules&& rules) : permissions_(std::move(rules)) {} |
| 47 | + explicit Impl(WhiteListRules&& rules) : permissions_(std::move(rules)) {} |
31 | 48 |
|
32 | | - std::variant<Unrestricted, Rules> permissions_; |
| 49 | + std::variant<Unrestricted, NodeRules, WhiteListRules> permissions_; |
33 | 50 | }; |
34 | 51 |
|
35 | 52 | AuthorisationService::AuthorisationService() = default; |
@@ -83,7 +100,19 @@ bool AuthorisationService::allows(const Identity& identity, |
83 | 100 | // Dangerous, but backward compatible! |
84 | 101 | allowed = true; |
85 | 102 | }, |
86 | | - [&server, &identity, &paths, &permission, &allowed](const Rules& rules) { |
| 103 | + [&allowed, &identity, &paths, &permission](const WhiteListRules& rules) { |
| 104 | + // Apply white list rules |
| 105 | + if (permission == "read") { |
| 106 | + allowed = rules.file_.verify_read_access(identity.username(), paths); |
| 107 | + } |
| 108 | + else if (permission == "write") { |
| 109 | + allowed = rules.file_.verify_write_access(identity.username(), paths); |
| 110 | + } |
| 111 | + else { |
| 112 | + allowed = false; |
| 113 | + } |
| 114 | + }, |
| 115 | + [&server, &identity, &paths, &permission, &allowed](const NodeRules& rules) { |
87 | 116 | for (auto&& path : paths) { |
88 | 117 |
|
89 | 118 | auto u = identity.as_string(); |
@@ -132,7 +161,11 @@ bool AuthorisationService::allows(const Identity& identity, |
132 | 161 | } |
133 | 162 |
|
134 | 163 | AuthorisationService::result_t AuthorisationService::load_permissions_from_nodes() { |
135 | | - return result_t::success(AuthorisationService(std::make_unique<Impl>(Rules{}))); |
| 164 | + return result_t::success(AuthorisationService(std::make_unique<Impl>(NodeRules{}))); |
| 165 | +} |
| 166 | + |
| 167 | +AuthorisationService::result_t AuthorisationService::load_permissions_from_whitelist(const WhiteListFile& whitelist) { |
| 168 | + return result_t::success(AuthorisationService(std::make_unique<Impl>(WhiteListRules{whitelist}))); |
136 | 169 | } |
137 | 170 |
|
138 | 171 | } // namespace ecf |
0 commit comments