ObjectQueryHandler: Check user permissions on joined relations

This commit is contained in:
Yonas Habteab 2022-10-05 17:51:13 +02:00
parent 1bb2d65a8d
commit 607f7ab5ca
1 changed files with 26 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include "base/configtype.hpp"
#include <boost/algorithm/string/case_conv.hpp>
#include <set>
#include <unordered_map>
using namespace icinga;
@ -189,6 +190,8 @@ bool ObjectQueryHandler::HandleRequest(
joinAttrs.insert(field.Name);
}
std::unordered_map<Type*, std::pair<bool, Expression::Ptr>> typePermissions;
for (const ConfigObject::Ptr& obj : objs) {
DictionaryData result1{
{ "name", obj->GetName() },
@ -257,6 +260,29 @@ bool ObjectQueryHandler::HandleRequest(
if (!joinedObj)
continue;
Type::Ptr reflectionType = joinedObj->GetReflectionType();
Expression::Ptr permissionFilter;
auto it = typePermissions.find(reflectionType.get());
bool granted;
if (it == typePermissions.end()) {
String permission = "objects/query/" + reflectionType->GetName();
Expression *filter = nullptr;
granted = FilterUtility::HasPermission(user, permission, &filter);
permissionFilter = filter;
typePermissions.insert({reflectionType.get(), std::make_pair(granted, permissionFilter)});
} else {
std::tie(granted, permissionFilter) = it->second;
}
if (!granted) {
// Not authorized
continue;
}
String prefix = field.NavigationName;
try {