mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-03 18:58:01 +00:00 
			
		
		
		
	Refactored code to SecureSourceChecker
This commit is contained in:
		@@ -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();
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,33 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureManagement;
 | 
			
		||||
 | 
			
		||||
use App\Entity\Meta\RightInterface;
 | 
			
		||||
use App\Entity\Source\SourceInterface;
 | 
			
		||||
use App\Domain\LawManagement\LawPermissionCheckerService;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class SecureSourceChecker implements SecureSourceCheckerInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var SourceInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $source;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param SourceInterface $source
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(SourceInterface $source)
 | 
			
		||||
    {
 | 
			
		||||
        $this->source = $source;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function hasPermission(RightInterface $requestedRight): bool
 | 
			
		||||
    {
 | 
			
		||||
        $law = new LawPermissionCheckerService($this->source->getLaw());
 | 
			
		||||
 | 
			
		||||
        return $law->hasPermission($requestedRight);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,18 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureManagement;
 | 
			
		||||
 | 
			
		||||
use App\Entity\Meta\RightInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface SecureSourceCheckerInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @param RightInterface $right
 | 
			
		||||
     *
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function hasPermission(RightInterface $requestedRight): bool;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								application/src/Exception/SourceAccessDenied.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								application/src/Exception/SourceAccessDenied.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Exception;
 | 
			
		||||
 | 
			
		||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
 | 
			
		||||
 | 
			
		||||
class SourceAccessDenied extends AccessDeniedHttpException
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user