diff --git a/application/symfony/src/Domain/ResponseManagement/SourceRESTResponseManager.php b/application/symfony/src/Domain/ResponseManagement/SourceRESTResponseManager.php index 6f8b96a..cbd3e7e 100644 --- a/application/symfony/src/Domain/ResponseManagement/SourceRESTResponseManager.php +++ b/application/symfony/src/Domain/ResponseManagement/SourceRESTResponseManager.php @@ -9,14 +9,16 @@ use App\Entity\Meta\RightInterface; use App\Domain\UserManagement\UserIdentityManager; use FOS\RestBundle\View\ViewHandlerInterface; use App\Entity\Source\SourceInterface; -use App\Domain\SecureLoadManagement\SecureSourceLoader; use FOS\RestBundle\View\View; use App\Exception\AllreadyDefinedException; +use App\Domain\SecureCRUDManagement\CRUD\Read\SecureSourceReadService; /** * @author kevinfrantz + * + * @todo Implement as a service! */ -class SourceRESTResponseManager implements SourceRESTResponseManagerInterface +final class SourceRESTResponseManager implements SourceRESTResponseManagerInterface { /** * @var UserInterface @@ -64,14 +66,14 @@ class SourceRESTResponseManager implements SourceRESTResponseManagerInterface $this->setView(); } - protected function setView(): void + private function setView(): void { $this->view = new View($this->loadedSource, 200); } private function setLoadedSource(): void { - $secureSourceLoader = new SecureSourceLoader($this->entityManager, $this->requestedRight); + $secureSourceLoader = new SecureSourceReadService($this->entityManager, $this->requestedRight); $this->loadedSource = $secureSourceLoader->getSource(); } @@ -100,6 +102,11 @@ class SourceRESTResponseManager implements SourceRESTResponseManagerInterface } } + /** + * {@inheritdoc} + * + * @see \App\Domain\ResponseManagement\SourceRESTResponseManagerInterface::getResponse() + */ public function getResponse(): Response { return $this->viewHandler->handle($this->view); diff --git a/application/symfony/src/Domain/SecureCRUDManagement/AbstractSecureCRUDService.php b/application/symfony/src/Domain/SecureCRUDManagement/AbstractSecureCRUDService.php new file mode 100644 index 0000000..9beaab9 --- /dev/null +++ b/application/symfony/src/Domain/SecureCRUDManagement/AbstractSecureCRUDService.php @@ -0,0 +1,40 @@ +requestStack = $requestStack; + $this->security = $security; + $this->entityManager = $entityManager; + } +} diff --git a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/AbstractSecureCRUD.php b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/AbstractSecureCRUD.php deleted file mode 100644 index b809845..0000000 --- a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/AbstractSecureCRUD.php +++ /dev/null @@ -1,10 +0,0 @@ -requestedRight; + $requestedRight = clone $requestedRight; $requestedRight->setSource($source); return $requestedRight; @@ -54,21 +51,26 @@ final class SecureSourceLoader implements SecureSourceLoaderInterface } } - public function __construct(EntityManagerInterface $entityManager, RightInterface $requestedRight) - { - $this->sourceRepository = $entityManager->getRepository(AbstractSource::class); - $this->requestedRight = $requestedRight; - } - /** * {@inheritdoc} * - * @see \App\Domain\SecureLoadManagement\SecureSourceLoaderInterface::getSource() + * @see \App\Domain\SecureCRUDManagement\AbstractSecureCRUDService::__construct() */ - public function getSource(): SourceInterface + public function __construct(RequestStack $requestStack, Security $security, EntityManagerInterface $entityManager) + { + $this->sourceRepository = $entityManager->getRepository(AbstractSource::class); + parent::__construct($requestStack, $security, $entityManager); + } + + /** + * @param RightInterface $requestedRight + * + * @return EntityInterface + */ + public function read(RightInterface $requestedRight): EntityInterface { $source = $this->loadSource(); - $requestedRight = $this->getClonedRightWithModifiedSource($source); + $requestedRight = $this->getClonedRightWithModifiedSource($source, $requestedRight); $secureSourceChecker = new SecureSourceChecker($source); if ($secureSourceChecker->hasPermission($requestedRight)) { return $source; diff --git a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Read/SecureSourceReadServiceInterface.php b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Read/SecureSourceReadServiceInterface.php new file mode 100644 index 0000000..6e62b64 --- /dev/null +++ b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Read/SecureSourceReadServiceInterface.php @@ -0,0 +1,10 @@ +getCrud($crud).'\\'.$this->getClassName($layer, $crud); - } - - public function __construct(RequestStack $requestStack, Security $security, EntityManagerInterface $entityManager) - { - $this->request = $requestStack->getCurrentRequest(); - $this->security = $security; - $this->entityManager = $entityManager; + return 'App\\Domain\\SecureCRUDManagement\\CRUD\\'.$this->getCrud($crud).'\\'.$this->getClassName($layer, $crud).'Service'; } /** @@ -74,10 +49,10 @@ final class SecureCRUDFactoryService implements SecureCRUDFactoryServiceInterfac * * @see \App\Domain\SecureCRUDManagement\Factory\SecureCRUDFactoryServiceInterface::create() */ - public function create(RightInterface $requestedRight): SecureCRUDInterface + public function create(RightInterface $requestedRight): SecureCRUDServiceInterface { $namespace = $this->getCRUDNamespace($requestedRight->getLayer(), $requestedRight->getType()); - return new $namespace($this->request, $this->security, $this->entityManager); + return new $namespace($this->requestStack, $this->security, $this->entityManager); } } diff --git a/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceInterface.php b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceInterface.php index 9661e64..af57ed5 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceInterface.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceInterface.php @@ -3,7 +3,7 @@ namespace App\Domain\SecureCRUDManagement\Factory; use App\Entity\Meta\RightInterface; -use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDInterface; +use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDServiceInterface; /** * @author kevinfrantz @@ -11,7 +11,7 @@ use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDInterface; interface SecureCRUDFactoryServiceInterface { /** - * @return SecureCRUDInterface + * @return SecureCRUDServiceInterface */ - public function create(RightInterface $requestedRight): SecureCRUDInterface; + public function create(RightInterface $requestedRight): SecureCRUDServiceInterface; } diff --git a/application/symfony/src/Domain/SecureLoadManagement/SecureSourceLoaderInterface.php b/application/symfony/src/Domain/SecureLoadManagement/SecureSourceLoaderInterface.php deleted file mode 100644 index 09c00a6..0000000 --- a/application/symfony/src/Domain/SecureLoadManagement/SecureSourceLoaderInterface.php +++ /dev/null @@ -1,19 +0,0 @@ -entityManager = self::$container->get('doctrine.orm.default_entity_manager'); - $this->setSourceRepository(); - } - - private function setSourceRepository(): void - { - $this->sourceRepository = $this->entityManager->getRepository(AbstractSource::class); + $requestStack = self::$container->get('request_stack'); + $security = new Security(self::$kernel->getContainer()); + $entityManager = self::$container->get('doctrine.orm.default_entity_manager'); + $this->secureSourceReadService = new SecureSourceReadService($requestStack, $security, $entityManager); } public function testAccessDeniedException(): void @@ -54,9 +56,8 @@ class SecureSourceLoaderTest extends KernelTestCase $requestedRight->setLayer(LayerType::SOURCE); $requestedRight->setType(CRUDType::READ); $requestedRight->setReciever(new UserSource()); - $secureSourceLoader = new SecureSourceLoader($this->entityManager, $requestedRight); $this->expectException(AccessDeniedHttpException::class); - $secureSourceLoader->getSource(); + $this->secureSourceReadService->read($requestedRight); } public function testGranted(): void @@ -68,7 +69,7 @@ class SecureSourceLoaderTest extends KernelTestCase $requestedRight->setLayer(LayerType::SOURCE); $requestedRight->setType(CRUDType::READ); $requestedRight->setReciever($this->sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER)); - $secureSourceLoader = new SecureSourceLoader($this->entityManager, $requestedRight); - $this->assertInstanceOf(TextSourceInterface::class, $secureSourceLoader->getSource()); + $textSourceResponse = $this->secureSourceReadService->read($requestedRight); + $this->assertInstanceOf(TextSourceInterface::class, $textSourceResponse); } } diff --git a/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceTest.php b/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceTest.php index 44b3bb0..6e7417f 100644 --- a/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceTest.php +++ b/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceTest.php @@ -8,7 +8,7 @@ use Symfony\Component\Security\Core\Security; use App\Domain\SecureCRUDManagement\Factory\SecureCRUDFactoryService; use App\DBAL\Types\Meta\Right\LayerType; use App\Entity\Meta\Right; -use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDInterface; +use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDServiceInterface; use App\DBAL\Types\Meta\Right\CRUDType; /** @@ -50,7 +50,7 @@ class SecureCRUDFactoryServiceTest extends KernelTestCase $requestedRight->setLayer($layer); $requestedRight->setType($crud); $secureCreator = $this->secureCRUDFactoryService->create($requestedRight); - $this->assertInstanceOf(SecureCRUDInterface::class, $secureCreator); + $this->assertInstanceOf(SecureCRUDServiceInterface::class, $secureCreator); } } }