The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ
blueroses.hu project repository
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

57 lines
1.7 KiB

<?php
namespace KekRozsak\SecurityBundle\Service;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
use Symfony\Bridge\Doctrine\RegistryInterface;
class RoleHierarchy implements RoleHierarchyInterface
{
private $hierarchy;
private $roleRepo;
private $map;
public function __construct(RegistryInterface $doctrine)
{
$this->hierarchy = array();
$this->roleRepo = $doctrine->getRepository('KekRozsakSecurityBundle:Role');
$this->buildRoleMap();
}
public function getReachableRoles(array $roles)
{
$reachableRoles = array();
foreach ($roles as $role) {
if (!isset($this->map[$role->getRole()])) {
continue;
}
foreach ($this->map[$role->getRole()] as $r) {
if (($childRole = $this->roleRepo->findOneByName($r)) !== null) {
$reachableRoles[] = $childRole;
}
}
}
return $reachableRoles;
}
private function buildRoleMap()
{
$this->map = array();
$roles = $this->roleRepo->findAll();
foreach ($roles as $mainRole) {
$main = $mainRole->getRole();
$this->map[$main] = array();
foreach ($mainRole->getInheritedRoles() as $childRole) {
$this->map[$main][] = $childRole->getRole();
// TODO: This is one-level only. Get as deep as possible.
// BEWARE OF RECURSIVE NESTING!
foreach ($childRole->getInheritedRoles() as $grandchildRole) {
$this->map[$main][] = $grandchildRole->getRole();
}
}
}
}
}