| #include "override.h" |
| |
| #include <string> |
| |
| #include "absl/strings/string_view.h" |
| #include "authorizer_enums.h" |
| #include "nlohmann/json.hpp" |
| #include "redfish_privileges.h" |
| |
| namespace milotic::authz { |
| |
| bool Override::IsPeerAuthorized( |
| absl::string_view uri, ecclesia::Operation operation, |
| const RedfishPrivileges& peer_privileges) const { |
| if (!IsApplicable(uri, operation)) { |
| return false; |
| } |
| |
| for (const RedfishPrivileges& privilegeSet : operation_map_.at(operation)) { |
| if (peer_privileges.IsSupersetOf(privilegeSet)) { |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| nlohmann::json::object_t Override::ToJson() const { |
| nlohmann::json::object_t json; |
| |
| json["Targets"] = nlohmann::json::array_t(); |
| for (const std::string& target : override_targets_) { |
| json["Targets"].push_back(target); |
| } |
| |
| for (const auto& it : operation_map_) { |
| json["OperationMap"][ecclesia::OperationToString(it.first)] = |
| nlohmann::json::array_t(); |
| for (const RedfishPrivileges& privilege_set : it.second) { |
| json["OperationMap"][ecclesia::OperationToString(it.first)].push_back( |
| privilege_set.ToJson()); |
| } |
| } |
| |
| return json; |
| } |
| } // namespace milotic::authz |