From ccb9530881da542a4a9c759b73669f3e45624bd9 Mon Sep 17 00:00:00 2001 From: David Surville <david.surville@unicaen.fr> Date: Tue, 28 Nov 2023 15:46:27 +0100 Subject: [PATCH] =?UTF-8?q?Quelques=20corrections=20n=C3=A9cessaires=20apr?= =?UTF-8?q?=C3=A8s=20l'int=C3=A9gration=20de=20la=20branche=20release/1.3.?= =?UTF-8?q?0=20dans=20la=20branche=205.x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Provider/Identity/Ldap.php | 8 +------- .../Provider/Identity/LdapServiceFactory.php | 3 --- .../Service/UserContext.php | 2 +- .../Service/UserContextFactory.php | 3 +-- .../Service/UserMapper.php | 17 ----------------- .../View/Helper/UserConnection.php | 12 ++---------- .../View/Helper/UserConnectionFactory.php | 13 ++----------- view/unicaen-authentification/auth/login.phtml | 9 +++++---- 8 files changed, 12 insertions(+), 55 deletions(-) diff --git a/src/UnicaenAuthentification/Provider/Identity/Ldap.php b/src/UnicaenAuthentification/Provider/Identity/Ldap.php index 51e8e38..bdbd312 100644 --- a/src/UnicaenAuthentification/Provider/Identity/Ldap.php +++ b/src/UnicaenAuthentification/Provider/Identity/Ldap.php @@ -18,12 +18,6 @@ use ZfcUser\Entity\UserInterface; */ class Ldap extends AuthenticationIdentityProvider implements ChainableProvider { - protected $usernamefield; - - public function setUsernamefield(?string $value = null) - { - $this->usernamefield=$value; - } /** * {@inheritDoc} */ @@ -56,7 +50,7 @@ class Ldap extends AuthenticationIdentityProvider implements ChainableProvider } if ($identity instanceof UserInterface) { - $roles[] = $identity->getUsername($this->usernamefield); + $roles[] = $identity->getUsername(); } return $roles; diff --git a/src/UnicaenAuthentification/Provider/Identity/LdapServiceFactory.php b/src/UnicaenAuthentification/Provider/Identity/LdapServiceFactory.php index 8ea231c..98cbebf 100644 --- a/src/UnicaenAuthentification/Provider/Identity/LdapServiceFactory.php +++ b/src/UnicaenAuthentification/Provider/Identity/LdapServiceFactory.php @@ -31,9 +31,6 @@ class LdapServiceFactory implements FactoryInterface $simpleIdentityProvider->setDefaultRole($config['default_role']); $simpleIdentityProvider->setAuthenticatedRole($config['authenticated_role']); - $usernamefield = $container->get('Config')['unicaen-auth']['local']['ldap']['username']; - $simpleIdentityProvider->setUsernamefield($usernamefield); - return $simpleIdentityProvider; } } \ No newline at end of file diff --git a/src/UnicaenAuthentification/Service/UserContext.php b/src/UnicaenAuthentification/Service/UserContext.php index 5dd76d9..8952ff3 100644 --- a/src/UnicaenAuthentification/Service/UserContext.php +++ b/src/UnicaenAuthentification/Service/UserContext.php @@ -138,7 +138,7 @@ class UserContext extends AbstractService implements EventManagerAwareInterface return $user->getUsername(); } if ($user = $this->getLdapUser()) { - return $user->getUsername($this->usernamefield); + return $user->getUsername(); } if ($user = $this->getDbUser()) { return $user->getUsername(); diff --git a/src/UnicaenAuthentification/Service/UserContextFactory.php b/src/UnicaenAuthentification/Service/UserContextFactory.php index e2a1880..563f9be 100644 --- a/src/UnicaenAuthentification/Service/UserContextFactory.php +++ b/src/UnicaenAuthentification/Service/UserContextFactory.php @@ -32,8 +32,7 @@ class UserContextFactory // mais c'est impossible pour l'instant car il y a un cycle dans les dépendances entre services qui // provoque une boucle infinie. // - $usernamefield = $container->get('Config')['unicaen-auth']['local']['ldap']['username']; - $service->setUsernamefield($usernamefield); + return $service; } } \ No newline at end of file diff --git a/src/UnicaenAuthentification/Service/UserMapper.php b/src/UnicaenAuthentification/Service/UserMapper.php index cfb10cc..15d2e13 100644 --- a/src/UnicaenAuthentification/Service/UserMapper.php +++ b/src/UnicaenAuthentification/Service/UserMapper.php @@ -90,21 +90,4 @@ class UserMapper implements UserInterface return $entity; } - //=================== - - - - /** - * Recherche un utilisateur par son username (identifiant de connexion). - * - * @param string $username - * @return AbstractUser|null - */ - public function findOneByUsername($username) - { - /** @var AbstractUser $user */ - $user = $this->em->getRepository($this->options->getUserEntityClass())->findOneBy(['username' => $username]); - - return $user; - } } \ No newline at end of file diff --git a/src/UnicaenAuthentification/View/Helper/UserConnection.php b/src/UnicaenAuthentification/View/Helper/UserConnection.php index d2465f4..6e18249 100644 --- a/src/UnicaenAuthentification/View/Helper/UserConnection.php +++ b/src/UnicaenAuthentification/View/Helper/UserConnection.php @@ -11,8 +11,6 @@ use UnicaenUtilisateur\View\Helper\UserAbstract; */ class UserConnection extends UserAbstract { - public bool $onlyCas = false; - /** * Point d'entrée. * @@ -20,6 +18,7 @@ class UserConnection extends UserAbstract */ public function __invoke() { + return $this; } /** @@ -35,13 +34,6 @@ class UserConnection extends UserAbstract return $out; } - public function computeConnectionLink() - { - $urlHelper = $this->getView()->plugin('url'); - $href = $urlHelper('zfcuser/login'); - if ($this->onlyCas) $href = $urlHelper('zfcuser/authenticate',['type' => 'cas']); - return $href; - } /** * * @return string @@ -54,7 +46,7 @@ class UserConnection extends UserAbstract $template = '<a class="navbar-link user-connection" href="%s" title="%s">%s</a>'; if (!$identity) { - $href = $this->computeConnectionLink(); + $href = $urlHelper('zfcuser/login'); $lib = "Connexion"; $title = "Affiche le formulaire d'authentification"; } diff --git a/src/UnicaenAuthentification/View/Helper/UserConnectionFactory.php b/src/UnicaenAuthentification/View/Helper/UserConnectionFactory.php index 5506545..dda0809 100644 --- a/src/UnicaenAuthentification/View/Helper/UserConnectionFactory.php +++ b/src/UnicaenAuthentification/View/Helper/UserConnectionFactory.php @@ -2,9 +2,9 @@ namespace UnicaenAuthentification\View\Helper; -use Psr\Container\ContainerInterface; use Laminas\ServiceManager\FactoryInterface; use Laminas\ServiceManager\ServiceLocatorInterface; +use Psr\Container\ContainerInterface; /** * Description of UserConnectionFactory @@ -20,17 +20,8 @@ class UserConnectionFactory implements FactoryInterface public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { - $config = $container->get('Config')['unicaen-auth']; - $activeModes = []; - foreach ($config['auth_types'] as $type) { - if ($config[$type]['enabled']) $activeModes[] = $type; - } - $onlyCas = (count($activeModes) === 1 AND $activeModes[0] === 'cas'); - $authUserContext = $container->get('authUserContext'); - $uc = new UserConnection($authUserContext); - $uc->onlyCas = $onlyCas; - return $uc; + return new UserConnection($authUserContext); } } \ No newline at end of file diff --git a/view/unicaen-authentification/auth/login.phtml b/view/unicaen-authentification/auth/login.phtml index ad8f207..7a92f11 100644 --- a/view/unicaen-authentification/auth/login.phtml +++ b/view/unicaen-authentification/auth/login.phtml @@ -1,4 +1,9 @@ <?php + +use Application\View\Renderer\PhpRenderer; +use UnicaenAuthentification\Form\LoginForm; +use Laminas\Form\Form; + /** * @var PhpRenderer $this * @var array[] $types Types d'authentification activés, ex: ['db' => ['enabled'=>true, 'type'=>'local'], 'shib' => ['enabled'=>true]] @@ -11,10 +16,6 @@ * @see \UnicaenAuthentification\Controller\AuthController::loginAction() */ -use Application\View\Renderer\PhpRenderer; -use UnicaenAuthentification\Form\LoginForm; -use Laminas\Form\Form; - $this->headTitle("Connexion") ?> <div class="div-connexion"> -- GitLab