Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion library/Director/Restriction/HostgroupRestriction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Icinga\Module\Director\Restriction;

use Icinga\Data\Filter\Filter;
use Icinga\Module\Director\Auth\Restriction;
use Icinga\Module\Director\Db\IcingaObjectFilterHelper;
use Icinga\Module\Director\Objects\HostApplyMatches;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaHostGroup;
use Icinga\Module\Director\Objects\IcingaObject;
Expand Down Expand Up @@ -59,7 +61,7 @@ public function allowsHost(IcingaHost $host)
// Hint: branched hosts have no id
if (! $host->hasBeenLoadedFromDb() || $host->hasModifiedGroups() || $host->get('id') === null) {
foreach ($this->listRestrictedHostgroups() as $group) {
if ($host->hasGroup($group)) {
if ($host->hasGroup($group) || $this->matchesHostGroupFilter($group, $host)) {
return true;
}
}
Expand All @@ -76,6 +78,21 @@ public function allowsHost(IcingaHost $host)
return (int) $this->db->fetchOne($query) === (int) $host->get('id');
}

/**
* Check if the given host matches the filter of given host group
*
* @param string $group
* @param IcingaHost $host
*
* @return bool
*/
private function matchesHostGroupFilter(string $group, IcingaHost $host): bool
{
return HostApplyMatches::prepare($host)->matchesFilter(
Filter::fromQueryString(IcingaHostGroup::load($group, $host->getConnection())->get('assign_filter'))
);
}

/**
* Whether access to the given hostgroup is allowed
*
Expand Down
Loading