Loading src/UnicaenUtilisateur/Service/User/UserService.php +30 −20 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ namespace UnicaenUtilisateur\Service\User; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\ORMException; use InvalidArgumentException; use Ramsey\Uuid\Uuid; use UnicaenApp\Entity\Ldap\People; use UnicaenApp\Service\EntityManagerAwareTrait; Loading @@ -29,19 +29,24 @@ class UserService implements RechercheIndividuServiceInterface use RoleServiceAwareTrait; use MailServiceAwareTrait; /** * @var string */ private $userEntityClass; private ?string $userEntityClass = null; private ?array $authentificationConfig = null; /** * @var AuthenticationService */ private $authenticationService; public function getAuthentificationConfig(): ?array { return $this->authentificationConfig; } public function setAuthentificationConfig(?array $authentificationConfig): void { $this->authentificationConfig = $authentificationConfig; } private ?AuthenticationService $authenticationService; private $renderer; public function setRenderer($renderer) { $this->renderer = $renderer;} private $appname; private ?string $appname = null; public function setAppname($appname) { $this->appname = $appname;} Loading @@ -49,19 +54,18 @@ class UserService implements RechercheIndividuServiceInterface * @param string $userEntityClass * @return void */ public function setUserEntityClass($userEntityClass) public function setUserEntityClass(string $userEntityClass) : void { if (! class_exists($userEntityClass) || ! in_array(UserInterface::class, class_implements($userEntityClass))) { throw new InvalidArgumentException("L'entité associée aux utilisateurs doit implémenter " . UserInterface::class); } $this->userEntityClass = $userEntityClass; } /** * @return string */ public function getEntityClass() public function getEntityClass() : ?string { return $this->userEntityClass; } Loading @@ -71,7 +75,7 @@ class UserService implements RechercheIndividuServiceInterface * * @return UserInterface */ public function getEntityInstance() public function getEntityInstance() : UserInterface { return new $this->userEntityClass; } Loading Loading @@ -346,19 +350,25 @@ class UserService implements RechercheIndividuServiceInterface return $qb->getQuery()->getResult(); } /** * @return UserInterface */ public function getConnectedUser() public function getConnectedUser() : ?UserInterface { $identity = $this->authenticationService->getIdentity(); if ($identity) { $username = null; if (isset($identity['ldap'])) { /** @var People $userIdentity */ $userIdentity = $identity['ldap']; switch ($this->getAuthentificationConfig()['local']['ldap']['username']) { case 'uid' : $username = $userIdentity->getUid(); break; case 'supannaliaslogin' : $username = $userIdentity->getSupannAliasLogin(); break; default : throw new RuntimeException("La clef de config [unicaen-auth][loca][ldap][username] n'est pas défini ou à une valeur non attendue."); } $user = $this->findByUsername($username); return $user; Loading src/UnicaenUtilisateur/Service/User/UserServiceFactory.php +6 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ namespace UnicaenUtilisateur\Service\User; use Doctrine\ORM\EntityManager; use Interop\Container\ContainerInterface; use Laminas\View\Renderer\PhpRenderer; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use UnicaenAuthentification\Service\UserContext; use UnicaenMail\Service\Mail\MailService; use UnicaenUtilisateur\Entity\Db\User; Loading @@ -20,8 +22,10 @@ class UserServiceFactory * @param string $requestedName * @param array|null $options * @return UserService * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) public function __invoke(ContainerInterface $container, $requestedName, array $options = null) : UserService { /** * @var EntityManager $entityManager Loading @@ -43,6 +47,7 @@ class UserServiceFactory $service->setRoleService($roleService); $service->setServiceUserContext($userContext); $service->setUserEntityClass($allConfig['zfcuser']['user_entity_class'] ?? User::class); $service->setAuthentificationConfig($allConfig['unicaen-auth']); $service->setAuthenticationService($authenticationService); /* @var PhpRenderer $renderer */ Loading Loading
src/UnicaenUtilisateur/Service/User/UserService.php +30 −20 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ namespace UnicaenUtilisateur\Service\User; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\ORMException; use InvalidArgumentException; use Ramsey\Uuid\Uuid; use UnicaenApp\Entity\Ldap\People; use UnicaenApp\Service\EntityManagerAwareTrait; Loading @@ -29,19 +29,24 @@ class UserService implements RechercheIndividuServiceInterface use RoleServiceAwareTrait; use MailServiceAwareTrait; /** * @var string */ private $userEntityClass; private ?string $userEntityClass = null; private ?array $authentificationConfig = null; /** * @var AuthenticationService */ private $authenticationService; public function getAuthentificationConfig(): ?array { return $this->authentificationConfig; } public function setAuthentificationConfig(?array $authentificationConfig): void { $this->authentificationConfig = $authentificationConfig; } private ?AuthenticationService $authenticationService; private $renderer; public function setRenderer($renderer) { $this->renderer = $renderer;} private $appname; private ?string $appname = null; public function setAppname($appname) { $this->appname = $appname;} Loading @@ -49,19 +54,18 @@ class UserService implements RechercheIndividuServiceInterface * @param string $userEntityClass * @return void */ public function setUserEntityClass($userEntityClass) public function setUserEntityClass(string $userEntityClass) : void { if (! class_exists($userEntityClass) || ! in_array(UserInterface::class, class_implements($userEntityClass))) { throw new InvalidArgumentException("L'entité associée aux utilisateurs doit implémenter " . UserInterface::class); } $this->userEntityClass = $userEntityClass; } /** * @return string */ public function getEntityClass() public function getEntityClass() : ?string { return $this->userEntityClass; } Loading @@ -71,7 +75,7 @@ class UserService implements RechercheIndividuServiceInterface * * @return UserInterface */ public function getEntityInstance() public function getEntityInstance() : UserInterface { return new $this->userEntityClass; } Loading Loading @@ -346,19 +350,25 @@ class UserService implements RechercheIndividuServiceInterface return $qb->getQuery()->getResult(); } /** * @return UserInterface */ public function getConnectedUser() public function getConnectedUser() : ?UserInterface { $identity = $this->authenticationService->getIdentity(); if ($identity) { $username = null; if (isset($identity['ldap'])) { /** @var People $userIdentity */ $userIdentity = $identity['ldap']; switch ($this->getAuthentificationConfig()['local']['ldap']['username']) { case 'uid' : $username = $userIdentity->getUid(); break; case 'supannaliaslogin' : $username = $userIdentity->getSupannAliasLogin(); break; default : throw new RuntimeException("La clef de config [unicaen-auth][loca][ldap][username] n'est pas défini ou à une valeur non attendue."); } $user = $this->findByUsername($username); return $user; Loading
src/UnicaenUtilisateur/Service/User/UserServiceFactory.php +6 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ namespace UnicaenUtilisateur\Service\User; use Doctrine\ORM\EntityManager; use Interop\Container\ContainerInterface; use Laminas\View\Renderer\PhpRenderer; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use UnicaenAuthentification\Service\UserContext; use UnicaenMail\Service\Mail\MailService; use UnicaenUtilisateur\Entity\Db\User; Loading @@ -20,8 +22,10 @@ class UserServiceFactory * @param string $requestedName * @param array|null $options * @return UserService * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) public function __invoke(ContainerInterface $container, $requestedName, array $options = null) : UserService { /** * @var EntityManager $entityManager Loading @@ -43,6 +47,7 @@ class UserServiceFactory $service->setRoleService($roleService); $service->setServiceUserContext($userContext); $service->setUserEntityClass($allConfig['zfcuser']['user_entity_class'] ?? User::class); $service->setAuthentificationConfig($allConfig['unicaen-auth']); $service->setAuthenticationService($authenticationService); /* @var PhpRenderer $renderer */ Loading