|
1 | 1 | /**
|
2 | 2 | * This file is part of the EGIL SCIM client.
|
3 | 3 | *
|
4 |
| - * Copyright (C) 2017-2019 Föreningen Sambruk |
| 4 | + * Copyright (C) 2017-2024 Föreningen Sambruk |
5 | 5 | *
|
6 | 6 | * This program is free software: you can redistribute it and/or modify
|
7 | 7 | * it under the terms of the GNU Affero General Public License as
|
|
25 | 25 |
|
26 | 26 | namespace pt = boost::property_tree;
|
27 | 27 |
|
| 28 | +namespace { |
| 29 | + std::shared_ptr<load_limiter> user_blacklist; |
| 30 | +} |
| 31 | + |
| 32 | +void set_user_blacklist(const std::string &filename, |
| 33 | + const std::string &attribute) { |
| 34 | + user_blacklist = std::make_shared<not_limiter>(std::make_shared<list_limiter>(filename, attribute)); |
| 35 | +} |
| 36 | + |
| 37 | +/** If there is a user blacklist set, this function will return a new limiter based on the |
| 38 | + * passed in limiter. The returned limiter will work like the passed in limiter except that |
| 39 | + * it will exclude users from the blacklist. |
| 40 | + * |
| 41 | + * If no user blacklist is set the limiter will be returned as it is. |
| 42 | + * |
| 43 | +*/ |
| 44 | +std::shared_ptr<load_limiter> combine_with_user_blacklist(std::shared_ptr<load_limiter> limiter) { |
| 45 | + if (user_blacklist == nullptr) { |
| 46 | + return limiter; |
| 47 | + } |
| 48 | + else { |
| 49 | + return std::make_shared<and_limiter>(std::vector<std::shared_ptr<load_limiter>>{limiter, user_blacklist}); |
| 50 | + } |
| 51 | +} |
| 52 | + |
28 | 53 | std::shared_ptr<load_limiter> create_limiter_from_json(const pt::ptree& root);
|
29 | 54 |
|
30 | 55 | std::vector<std::shared_ptr<load_limiter>> create_limiters_from_json_array(const pt::ptree& root) {
|
@@ -62,6 +87,13 @@ std::shared_ptr<load_limiter> create_limiter_from_json(const pt::ptree& root) {
|
62 | 87 | }
|
63 | 88 | }
|
64 | 89 |
|
| 90 | +/** Returns the limiter for a specific type, or for the SCIM endpoint |
| 91 | + * if there's no type specific limiter (or a null_limiter if there's |
| 92 | + * no endpoint limiter). |
| 93 | + * Note that if there's a user blacklist, it is not created here, the |
| 94 | + * caller of this function is expected to combine the limiter with |
| 95 | + * the user blacklist if the type is a user type. |
| 96 | + */ |
65 | 97 | std::shared_ptr<load_limiter> create_limiter(const std::string& type) {
|
66 | 98 | config_file &conf = config_file::instance();
|
67 | 99 |
|
@@ -118,7 +150,15 @@ std::shared_ptr<load_limiter> get_limiter(const std::string& type) {
|
118 | 150 | }
|
119 | 151 |
|
120 | 152 | if (limiters.find(type) == limiters.end()) {
|
121 |
| - limiters[type] = create_limiter(type); |
| 153 | + auto l = create_limiter(type); |
| 154 | + |
| 155 | + // Figure out if we should add the user blacklist to the limiter |
| 156 | + auto endpoint_variable = type + "-scim-url-endpoint"; |
| 157 | + if (conf.has(endpoint_variable) && conf.get(endpoint_variable) == "Users") { |
| 158 | + limiters[type] = combine_with_user_blacklist(l); |
| 159 | + } else { |
| 160 | + limiters[type] = l; |
| 161 | + } |
122 | 162 | }
|
123 | 163 | return limiters[type];
|
124 | 164 | }
|
0 commit comments