Implemented SecureEntityChecker

This commit is contained in:
Kevin Frantz
2019-01-27 02:50:01 +01:00
parent 412b26d639
commit b47003bb52
4 changed files with 128 additions and 1 deletions

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Domain\SecureManagement;
use App\Domain\RequestManagement\Right\RequestedRightInterface;
use Doctrine\ORM\EntityManagerInterface;
use App\Domain\RightManagement\RightTransformerServiceInterface;
/**
* @author kevinfrantz
*/
final class SecureEntityChecker implements SecureEntityCheckerInterface
{
/**
* @var RightTransformerServiceInterface
*/
private $rightTransformerService;
/**
* @param EntityManagerInterface $entityManager
*/
public function __construct(RightTransformerServiceInterface $rightTransformerService)
{
$this->rightTransformerService = $rightTransformerService;
}
public function check(RequestedRightInterface $requestedRight): bool
{
$source = $requestedRight->getSource();
$secureSourceChecker = new SecureSourceChecker($source);
$transformedRequestedRight = $this->rightTransformerService->transform($requestedRight);
return $secureSourceChecker->hasPermission($transformedRequestedRight);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Domain\SecureManagement;
use App\Domain\RequestManagement\Right\RequestedRightInterface;
/**
* Allows to check if a RequestedRight is valid.
*
* @author kevinfrantz
*/
interface SecureEntityCheckerInterface
{
/**
* @param RequestedRightInterface $requestedRight
*
* @return bool If Permission granted true
*/
public function check(RequestedRightInterface $requestedRight): bool;
}