From 878eae62dba208394779499b2899071d15bc4714 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Tue, 1 Jan 2019 19:07:35 +0100 Subject: [PATCH] Refactored code to SecureSourceChecker --- .../SecureSourceLoader.php | 14 +++----- .../SecureManagement/SecureSourceChecker.php | 33 +++++++++++++++++++ .../SecureSourceCheckerInterface.php | 18 ++++++++++ .../src/Exception/SourceAccessDenied.php | 9 +++++ 4 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 application/src/Domain/SecureManagement/SecureSourceChecker.php create mode 100644 application/src/Domain/SecureManagement/SecureSourceCheckerInterface.php create mode 100644 application/src/Exception/SourceAccessDenied.php diff --git a/application/src/Domain/SecureLoadManagement/SecureSourceLoader.php b/application/src/Domain/SecureLoadManagement/SecureSourceLoader.php index 81b0965..fef0caf 100644 --- a/application/src/Domain/SecureLoadManagement/SecureSourceLoader.php +++ b/application/src/Domain/SecureLoadManagement/SecureSourceLoader.php @@ -4,9 +4,9 @@ namespace App\Domain\SecureLoadManagement; use App\Entity\Source\SourceInterface; use App\Entity\Meta\RightInterface; -use App\Domain\LawManagement\LawPermissionCheckerService; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Doctrine\Common\Persistence\ObjectRepository; +use App\Domain\SecureManagement\SecureSourceChecker; /** * @author kevinfrantz @@ -52,14 +52,6 @@ final class SecureSourceLoader implements SecureSourceLoaderInterface } } - private function hasPermission(SourceInterface $source): bool - { - $requestedRight = $this->getClonedRightWithModifiedSource($source); - $law = new LawPermissionCheckerService($source->getLaw()); - - return $law->hasPermission($requestedRight); - } - public function __construct(ObjectRepository $sourceRepository, RightInterface $requestedRight) { $this->sourceRepository = $sourceRepository; @@ -74,7 +66,9 @@ final class SecureSourceLoader implements SecureSourceLoaderInterface public function getSource(): SourceInterface { $source = $this->loadSource(); - if ($this->hasPermission($source)) { + $requestedRight = $this->getClonedRightWithModifiedSource($source); + $secureSourceChecker = new SecureSourceChecker($source); + if ($secureSourceChecker->hasPermission($requestedRight)) { return $source; } throw new AccessDeniedHttpException(); diff --git a/application/src/Domain/SecureManagement/SecureSourceChecker.php b/application/src/Domain/SecureManagement/SecureSourceChecker.php new file mode 100644 index 0000000..90ebd9f --- /dev/null +++ b/application/src/Domain/SecureManagement/SecureSourceChecker.php @@ -0,0 +1,33 @@ +source = $source; + } + + public function hasPermission(RightInterface $requestedRight): bool + { + $law = new LawPermissionCheckerService($this->source->getLaw()); + + return $law->hasPermission($requestedRight); + } +} diff --git a/application/src/Domain/SecureManagement/SecureSourceCheckerInterface.php b/application/src/Domain/SecureManagement/SecureSourceCheckerInterface.php new file mode 100644 index 0000000..4738901 --- /dev/null +++ b/application/src/Domain/SecureManagement/SecureSourceCheckerInterface.php @@ -0,0 +1,18 @@ +