Implemented UserIdentityService

This commit is contained in:
Kevin Frantz 2019-01-13 13:14:29 +01:00
parent 04b156b8fc
commit c6552f4589
9 changed files with 171 additions and 56 deletions

View File

@ -20,6 +20,7 @@ use App\Domain\ResponseManagement\SourceRESTResponseManager;
final class DefaultController extends AbstractController final class DefaultController extends AbstractController
{ {
/** /**
* @deprecated Use load via source instead of fixed route
* @todo Optimize function! * @todo Optimize function!
* @Route("/imprint.{_format}", defaults={"_format"="json"}, name="imprint") * @Route("/imprint.{_format}", defaults={"_format"="json"}, name="imprint")
*/ */

View File

@ -1,13 +0,0 @@
<?php
namespace App\Domain\ResponseManagement;
use Symfony\Component\HttpFoundation\Response;
interface SourceRESTResponseManagerInterface
{
/**
* @return Response
*/
public function getResponse(): Response;
}

View File

@ -7,6 +7,7 @@ use App\Entity\UserInterface;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Meta\RightInterface; use App\Entity\Meta\RightInterface;
use App\Domain\UserManagement\UserIdentityManager; use App\Domain\UserManagement\UserIdentityManager;
use Symfony\Component\Security\Core\User\UserInterface as CoreUserInterface;
use FOS\RestBundle\View\ViewHandlerInterface; use FOS\RestBundle\View\ViewHandlerInterface;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use FOS\RestBundle\View\View; use FOS\RestBundle\View\View;
@ -18,13 +19,8 @@ use App\Domain\SecureCRUDManagement\CRUD\Read\SecureSourceReadService;
* *
* @todo Implement as a service! * @todo Implement as a service!
*/ */
final class SourceRESTResponseManager implements SourceRESTResponseManagerInterface final class SourceRESTResponseManagerService implements SourceRESTResponseManagerServiceInterface
{ {
/**
* @var UserInterface
*/
private $user;
/** /**
* @var EntityManagerInterface * @var EntityManagerInterface
*/ */
@ -35,32 +31,20 @@ final class SourceRESTResponseManager implements SourceRESTResponseManagerInterf
*/ */
private $requestedRight; private $requestedRight;
/**
* @var ViewHandlerInterface
*/
private $viewHandler;
/** /**
* @var SourceInterface * @var SourceInterface
*/ */
private $loadedSource; private $loadedSource;
/** /**
* @var View * @var UserInterface
*/ */
private $view; private $user;
/** public function __construct(CoreUserInterface $user,SecureSourceReadService $secureSourceRead, EntityManagerInterface $entityManager, RightInterface $requestedRight)
* @param UserInterface $user
* @param EntityManagerInterface $entityManager
* @param RightInterface $requestedRight
* @param ViewHandlerInterface $viewHandler
*/
public function __construct(?UserInterface $user, EntityManagerInterface $entityManager, RightInterface $requestedRight, ViewHandlerInterface $viewHandler)
{ {
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->viewHandler = $viewHandler; $this->user = $user;
$this->setUser($user);
$this->setRequestedRight($requestedRight); $this->setRequestedRight($requestedRight);
$this->setLoadedSource(); $this->setLoadedSource();
$this->setView(); $this->setView();
@ -71,21 +55,6 @@ final class SourceRESTResponseManager implements SourceRESTResponseManagerInterf
$this->view = new View($this->loadedSource, 200); $this->view = new View($this->loadedSource, 200);
} }
private function setLoadedSource(): void
{
$secureSourceLoader = new SecureSourceReadService($this->entityManager, $this->requestedRight);
$this->loadedSource = $secureSourceLoader->getSource();
}
/**
* @param UserInterface $user
*/
private function setUser(?UserInterface $user): void
{
$userIdentityManager = new UserIdentityManager($this->entityManager, $user);
$this->user = $userIdentityManager->getUser();
}
/** /**
* @param RightInterface $requestedRight * @param RightInterface $requestedRight
* *
@ -103,12 +72,11 @@ final class SourceRESTResponseManager implements SourceRESTResponseManagerInterf
} }
/** /**
* {@inheritdoc} * {@inheritDoc}
* * @see \App\Domain\ResponseManagement\SourceRESTResponseManagerServiceInterface::getResponse()
* @see \App\Domain\ResponseManagement\SourceRESTResponseManagerInterface::getResponse()
*/ */
public function getResponse(): Response public function getResponse(ViewHandlerInterface $viewHandler): Response
{ {
return $this->viewHandler->handle($this->view); return $viewHandler->handle($this->view);
} }
} }

View File

@ -0,0 +1,14 @@
<?php
namespace App\Domain\ResponseManagement;
use Symfony\Component\HttpFoundation\Response;
use FOS\RestBundle\View\ViewHandlerInterface;
interface SourceRESTResponseManagerServiceInterface
{
/**
* @return Response
*/
public function getResponse(ViewHandlerInterface $viewHandler): Response;
}

View File

@ -0,0 +1,41 @@
<?php
namespace App\Domain\RightManagement;
use App\Entity\Meta\Right;
use App\Entity\UserInterface as InfinitoUserInterface;
use App\Entity\Source\SourceInterface;
use App\Entity\UserInterface;
use Symfony\Component\Security\Core\Security;
/**
*
* @author kevinfrantz
*
*/
final class UserRightService extends Right implements UserRightServiceInterface
{
/**
*
* @var Security
*/
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
/**
* {@inheritDoc}
* @see \App\Entity\Attribut\RecieverAttributInterface::setReciever()
*/
public function setReciever(SourceInterface $reciever):void{
}
public function getReciever():SourceInterface{
return $this->user->getSource();
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace App\Domain\RightManagement;
use App\Entity\Meta\RightInterface;
/**
* Offers a Service for managing the rights
* @author kevinfrantz
*
*/
interface UserRightServiceInterface extends RightInterface
{
}

View File

@ -0,0 +1,53 @@
<?php
namespace App\Domain\UserManagement;
use App\Entity\UserInterface;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Security\Core\Security;
/**
*
* @author kevinfrantz
* @todo Test!
*/
final class UserIdentityService implements UserIdentityServiceInterface
{
/**
* @var EntityManager
*/
private $entityManager;
/**
* @var Security
*/
private $security;
/**
* @var UserIdentityManagerInterface
*/
private $userIdentityManager;
/**
* @param EntityManager $entityManager
* @param Security $security
*/
public function __construct(EntityManager $entityManager, Security $security){
$this->entityManager = $entityManager;
$this->security = $security;
}
private function setUserIdentityManager():void{
$this->userIdentityManager = new UserIdentityManager($this->entityManager, $this->security->getUser());
}
/**
* @todo Optimzed performance!
* {@inheritDoc}
* @see \App\Domain\UserManagement\UserIdentityManagerInterface::getUser()
*/
public function getUser(): UserInterface
{
$this->setUserIdentityManager();
return $this->userIdentityManager->getUser();
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Domain\UserManagement;
/**
*
* @author kevinfrantz
*
*/
interface UserIdentityServiceInterface extends UserIdentityManagerInterface
{
}

View File

@ -0,0 +1,25 @@
<?php
namespace tests\Unit\Domain\RightManagement;
use PHPUnit\Framework\TestCase;
use App\Entity\User;
use App\Entity\Source\SourceInterface;
use App\Domain\RightManagement\UserRightService;
/**
*
* @author kevinfrantz
*
*/
class UserRightServiceTest extends TestCase
{
public function testUserSet():void{
$user = new User();
$source = $this->createMock(SourceInterface::class);
$user->setSource($source);
$userRight = new UserRightService($user);
$this->assertEquals($source, $userRight->getReciever());
}
}