diff --git a/application/symfony/src/Domain/SecureManagement/SecureEntityChecker.php b/application/symfony/src/Domain/SecureManagement/SecureEntityChecker.php new file mode 100644 index 0000000..df3eec5 --- /dev/null +++ b/application/symfony/src/Domain/SecureManagement/SecureEntityChecker.php @@ -0,0 +1,35 @@ +rightTransformerService = $rightTransformerService; + } + + public function check(RequestedRightInterface $requestedRight): bool + { + $source = $requestedRight->getSource(); + $secureSourceChecker = new SecureSourceChecker($source); + $transformedRequestedRight = $this->rightTransformerService->transform($requestedRight); + + return $secureSourceChecker->hasPermission($transformedRequestedRight); + } +} diff --git a/application/symfony/src/Domain/SecureManagement/SecureEntityCheckerInterface.php b/application/symfony/src/Domain/SecureManagement/SecureEntityCheckerInterface.php new file mode 100644 index 0000000..cce5f19 --- /dev/null +++ b/application/symfony/src/Domain/SecureManagement/SecureEntityCheckerInterface.php @@ -0,0 +1,20 @@ +setSource($source); + $right->setLayer($layer); + $right->setCrud($crud); + $right->setReciever($reciever); + $source->getLaw()->getRights()->add($right); + $requestedRight = new RequestedRight(); + $requestedRight->setCrud($crud); + $requestedRight->setLayer($layer); + $requestedRight->setReciever($reciever); + $requestedEntity = $this->createMock(RequestedEntityInterface::class); + $requestedEntity->method('hasId')->willReturn(true); + $requestedEntity->method('getEntity')->willReturn($source); + $requestedRight->setRequestedEntity($requestedEntity); + $rightTransformerService = new RightTransformerService(); + $secureEntityChecker = new SecureEntityChecker($rightTransformerService); + $result = $secureEntityChecker->check($requestedRight); + $this->assertTrue($result); + } + + public function testNotGranted(): void + { + $reciever = new class() extends AbstractSource { + }; + $layer = LayerType::SOURCE; + $crud = CRUDType::READ; + $source = new class() extends AbstractSource { + }; + $right = new Right(); + $right->setSource($source); + $right->setLayer($layer); + $right->setCrud(CRUDType::CREATE); + $right->setReciever($reciever); + $source->getLaw()->getRights()->add($right); + $requestedRight = new RequestedRight(); + $requestedRight->setCrud($crud); + $requestedRight->setLayer($layer); + $requestedRight->setReciever($reciever); + $requestedEntity = $this->createMock(RequestedEntityInterface::class); + $requestedEntity->method('hasId')->willReturn(true); + $requestedEntity->method('getEntity')->willReturn($source); + $requestedRight->setRequestedEntity($requestedEntity); + $rightTransformerService = new RightTransformerService(); + $secureEntityChecker = new SecureEntityChecker($rightTransformerService); + $result = $secureEntityChecker->check($requestedRight); + $this->assertFalse($result); + } +} diff --git a/application/symfony/tests/Unit/Domain/SecureSourceManagement/SecureSourceCheckerTest.php b/application/symfony/tests/Unit/Domain/SecureManagement/SecureSourceCheckerTest.php similarity index 98% rename from application/symfony/tests/Unit/Domain/SecureSourceManagement/SecureSourceCheckerTest.php rename to application/symfony/tests/Unit/Domain/SecureManagement/SecureSourceCheckerTest.php index 08ad6f4..88649e9 100644 --- a/application/symfony/tests/Unit/Domain/SecureSourceManagement/SecureSourceCheckerTest.php +++ b/application/symfony/tests/Unit/Domain/SecureManagement/SecureSourceCheckerTest.php @@ -1,6 +1,6 @@