| #include "resource_uri_override.h" |
| |
| #include <algorithm> |
| #include <string> |
| |
| #include "absl/strings/str_cat.h" |
| #include "absl/strings/string_view.h" |
| #include "authorizer_enums.h" |
| #include "override.h" |
| |
| namespace milotic::authz { |
| |
| // This is applicable if the operation is contained in the operation_map |
| // and if uri is found in override_targets |
| bool ResourceUriOverride::IsApplicable(absl::string_view uri, |
| ecclesia::Operation operation) const { |
| if (uri.empty() || !operation_map_.contains(operation)) { |
| return false; |
| } |
| |
| // We need to check both uris that end in a / and uris that don't. |
| // '/redfish/v1' should be treated the same as '/redfish/v1/' |
| std::string other_uri; |
| if (uri.back() == '/') { |
| other_uri = uri.substr(0, uri.size() - 1); |
| } else { |
| other_uri = absl::StrCat(uri, "/"); |
| } |
| |
| // If either uri or other uri is found, return true |
| return std::find(override_targets_.begin(), override_targets_.end(), uri) != |
| override_targets_.end() || |
| std::find(override_targets_.begin(), override_targets_.end(), |
| other_uri) != override_targets_.end(); |
| } |
| |
| Override::Type ResourceUriOverride::GetOverrideType() const { |
| return Override::kResourceUriOverride; |
| } |
| |
| } // namespace milotic::authz |