Loading src/UnicaenAuth/Provider/Identity/Db.php +9 −18 Original line number Diff line number Diff line Loading @@ -26,19 +26,16 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B use RoleServiceAwareTrait; use HostLocalizationAwareTrait; /** * @var Ldap */ private $ldap; private $ldap = null; /** * @var */ private $detectionContexteExecution; /** * {@inheritDoc} */ Loading @@ -47,8 +44,6 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B $event->addRoles($this->getIdentityRoles()); } /** * {@inheritDoc} */ Loading Loading @@ -83,6 +78,7 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B } /* Injection des rôles par filtre LDAP */ if ($this->ldap !== null) { $ldapRoles = $this->getServiceRole()->getList(); foreach ($ldapRoles as $role) { if ($role->getLdapFilter() && !in_array($role, $roles)) { Loading @@ -91,6 +87,7 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B } } } } $inEtablissement = $this->getHostLocalization()->inEtablissement(); if (!$inEtablissement) { // Si on n'est pas dans l'établissement, alors on filtre les rôles disponibles Loading @@ -104,8 +101,6 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B return $roles; } /** * @param AbstractRole $role * @param string $dn Loading @@ -115,14 +110,12 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B protected function roleMatches(AbstractRole $role, $dn) { try { return 1 === $this->getLdap()->count($role->getLdapFilter(), $dn, Ldap::SEARCH_SCOPE_SUB); return 1 === $this->ldap->count($role->getLdapFilter(), $dn, Ldap::SEARCH_SCOPE_SUB); } catch (\Laminas\Ldap\Exception\LdapException $e) { return false; } } /** * Returns the LDAP Object * Loading @@ -133,8 +126,6 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B return $this->ldap; } /** * Set an Ldap connection * Loading src/UnicaenAuth/Provider/Identity/DbServiceFactory.php +16 −2 Original line number Diff line number Diff line Loading @@ -2,7 +2,9 @@ namespace UnicaenAuth\Provider\Identity; use Laminas\Ldap\Exception\LdapException; use Psr\Container\ContainerInterface; use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Options\ModuleOptions; use Laminas\Ldap\Ldap; use Laminas\ServiceManager\FactoryInterface; Loading Loading @@ -32,8 +34,20 @@ class DbServiceFactory implements FactoryInterface $unicaenAppOptions = $container->get('unicaen-app_module_options'); /* @var $unicaenAppOptions ModuleOptions */ $ldap = new Ldap($unicaenAppOptions->getLdap()['connection']['default']['params']); $ldapOptions = $unicaenAppOptions->getLdap()['connection']['default']['params'] ?? []; if ($ldapOptions) { try { $ldap = new Ldap($ldapOptions); $ldap->connect(); } catch (LdapException $e) { throw new RuntimeException( "Impossible de se connecter à l'annuaire LDAP. Si aucune connexion LDAP n'est nécessaire, veuillez " . "commenter les paramètres de config (connection > default > params).", $e ); } $identityProvider->setLdap($ldap); } $identityProvider->setServiceRole($container->get('UnicaenAuth\Service\Role')); Loading Loading
src/UnicaenAuth/Provider/Identity/Db.php +9 −18 Original line number Diff line number Diff line Loading @@ -26,19 +26,16 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B use RoleServiceAwareTrait; use HostLocalizationAwareTrait; /** * @var Ldap */ private $ldap; private $ldap = null; /** * @var */ private $detectionContexteExecution; /** * {@inheritDoc} */ Loading @@ -47,8 +44,6 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B $event->addRoles($this->getIdentityRoles()); } /** * {@inheritDoc} */ Loading Loading @@ -83,6 +78,7 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B } /* Injection des rôles par filtre LDAP */ if ($this->ldap !== null) { $ldapRoles = $this->getServiceRole()->getList(); foreach ($ldapRoles as $role) { if ($role->getLdapFilter() && !in_array($role, $roles)) { Loading @@ -91,6 +87,7 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B } } } } $inEtablissement = $this->getHostLocalization()->inEtablissement(); if (!$inEtablissement) { // Si on n'est pas dans l'établissement, alors on filtre les rôles disponibles Loading @@ -104,8 +101,6 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B return $roles; } /** * @param AbstractRole $role * @param string $dn Loading @@ -115,14 +110,12 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B protected function roleMatches(AbstractRole $role, $dn) { try { return 1 === $this->getLdap()->count($role->getLdapFilter(), $dn, Ldap::SEARCH_SCOPE_SUB); return 1 === $this->ldap->count($role->getLdapFilter(), $dn, Ldap::SEARCH_SCOPE_SUB); } catch (\Laminas\Ldap\Exception\LdapException $e) { return false; } } /** * Returns the LDAP Object * Loading @@ -133,8 +126,6 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider, \B return $this->ldap; } /** * Set an Ldap connection * Loading
src/UnicaenAuth/Provider/Identity/DbServiceFactory.php +16 −2 Original line number Diff line number Diff line Loading @@ -2,7 +2,9 @@ namespace UnicaenAuth\Provider\Identity; use Laminas\Ldap\Exception\LdapException; use Psr\Container\ContainerInterface; use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Options\ModuleOptions; use Laminas\Ldap\Ldap; use Laminas\ServiceManager\FactoryInterface; Loading Loading @@ -32,8 +34,20 @@ class DbServiceFactory implements FactoryInterface $unicaenAppOptions = $container->get('unicaen-app_module_options'); /* @var $unicaenAppOptions ModuleOptions */ $ldap = new Ldap($unicaenAppOptions->getLdap()['connection']['default']['params']); $ldapOptions = $unicaenAppOptions->getLdap()['connection']['default']['params'] ?? []; if ($ldapOptions) { try { $ldap = new Ldap($ldapOptions); $ldap->connect(); } catch (LdapException $e) { throw new RuntimeException( "Impossible de se connecter à l'annuaire LDAP. Si aucune connexion LDAP n'est nécessaire, veuillez " . "commenter les paramètres de config (connection > default > params).", $e ); } $identityProvider->setLdap($ldap); } $identityProvider->setServiceRole($container->get('UnicaenAuth\Service\Role')); Loading