Commit f4f3a483 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Adapteur d'auth Shib : retrait d'une injection de dépendance pouvant créer une...

Adapteur d'auth Shib : retrait d'une injection de dépendance pouvant créer une boucle infinie de dépendances de services et qui n'est plus nécessaire (l'IDP semble désormais rediriger correctement après la déconnexion).
parent 52f76b1a
Loading
Loading
Loading
Loading
Loading
+1 −14
Original line number Diff line number Diff line
@@ -30,8 +30,8 @@ use UnicaenAuth\Event\Listener\LdapAuthenticationFailureLoggerListenerFactory;
use UnicaenAuth\Form\CasLoginForm;
use UnicaenAuth\Form\CasLoginFormFactory;
use UnicaenAuth\Form\Droits\RoleFormFactory;
use UnicaenAuth\Form\LoginFormFactory;
use UnicaenAuth\Form\LoginForm;
use UnicaenAuth\Form\LoginFormFactory;
use UnicaenAuth\Form\ShibLoginForm;
use UnicaenAuth\Form\ShibLoginFormFactory;
use UnicaenAuth\Guard\PrivilegeControllerFactory;
@@ -75,8 +75,6 @@ use UnicaenAuth\View\Helper\UserStatus;
use UnicaenAuth\View\Helper\UserStatusFactory;
use UnicaenAuth\View\Helper\UserUsurpationHelper;
use UnicaenAuth\View\Helper\UserUsurpationHelperFactory;
use Laminas\Authentication\AuthenticationService;
use Laminas\ServiceManager\Proxy\LazyServiceFactory;

$settings = [
    /**
@@ -712,17 +710,6 @@ return [

            LdapAuthenticationFailureLoggerListener::class => LdapAuthenticationFailureLoggerListenerFactory::class,
        ],
        'lazy_services' => [
            // Mapping services to their class names is required since the ServiceManager is not a declarative DIC.
            'class_map' => [
                'zfcuser_auth_service' => AuthenticationService::class,
            ],
        ],
        'delegators' => [
            'zfcuser_auth_service' => [
                LazyServiceFactory::class,
            ],
        ],
        'shared' => [
            'MouchardCompleterAuth'        => false,
        ],
+3 −31
Original line number Diff line number Diff line
@@ -2,15 +2,13 @@

namespace UnicaenAuth\Authentication\Adapter;

use UnicaenAuth\Controller\AuthController;
use UnicaenAuth\Options\Traits\ModuleOptionsAwareTrait;
use UnicaenAuth\Service\Traits\ShibServiceAwareTrait;
use UnicaenAuth\Service\User;
use Laminas\Authentication\AuthenticationService;
use Laminas\Authentication\Result as AuthenticationResult;
use Laminas\EventManager\EventInterface;
use Laminas\Http\Response;
use Laminas\Router\RouteInterface;
use UnicaenAuth\Options\Traits\ModuleOptionsAwareTrait;
use UnicaenAuth\Service\Traits\ShibServiceAwareTrait;
use UnicaenAuth\Service\User;
use ZfcUser\Authentication\Adapter\AdapterChainEvent;

/**
@@ -30,21 +28,6 @@ class Shib extends AbstractAdapter
     */
    protected $type = self::TYPE;

    /**
     * @var AuthenticationService
     */
    protected $authenticationService;

    /**
     * @param AuthenticationService $authenticationService
     * @return self
     */
    public function setAuthenticationService(AuthenticationService $authenticationService): self
    {
        $this->authenticationService = $authenticationService;
        return $this;
    }

    /**
     * @var RouteInterface
     */
@@ -121,9 +104,6 @@ class Shib extends AbstractAdapter
        return true;
    }

    /**
     * @inheritDoc
     */
    public function logout(EventInterface $e)
    {
        parent::logout($e);
@@ -146,13 +126,5 @@ class Shib extends AbstractAdapter
        $response = new Response();
        $response->getHeaders()->addHeaderLine('Location', $shibbolethLogoutUrl);
        $response->setStatusCode(302);

        /**
         * Problème : l'IDP Shibboleth ne redirige pas correctement vers l'URL demandée après déconnexion.
         * Solution : pour l'instant, on fait le nécessaire ici (qui devrait être fait normalement dans
         * {@see AuthController::logoutAction()} si l'IDP redonnait la main à l'appli.
         * todo: supprimer cette verrue lorsque l'IDP redirigera correctement.
         */
        $this->authenticationService->clearIdentity();
    }
}
 No newline at end of file
+4 −15
Original line number Diff line number Diff line
@@ -2,22 +2,15 @@

namespace UnicaenAuth\Authentication\Adapter;

use Laminas\Authentication\Storage\Session;
use Laminas\Router\RouteInterface;
use Psr\Container\ContainerInterface;
use UnicaenAuth\Options\ModuleOptions;
use UnicaenAuth\Service\ShibService;
use UnicaenAuth\Service\User;
use Laminas\Authentication\AuthenticationService;
use Laminas\Authentication\Storage\Session;
use Laminas\Router\RouteInterface;

class ShibAdapterFactory
{
    /**
     * @param ContainerInterface $container
     * @param string $requestedName
     * @param array|null $options
     * @return Shib
     */
    public function __invoke(ContainerInterface $container, string $requestedName, array $options = null)
    {
        $adapter = new Shib();
@@ -29,8 +22,8 @@ class ShibAdapterFactory
    }

    /**
     * @param Shib $adapter
     * @param ContainerInterface $container
     * @throws \Psr\Container\NotFoundExceptionInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     */
    private function injectDependencies(Shib $adapter, ContainerInterface $container)
    {
@@ -38,10 +31,6 @@ class ShibAdapterFactory
        $shibService = $container->get(ShibService::class);
        $adapter->setShibService($shibService);

        /** @var AuthenticationService $authenticationService */
        $authenticationService = $container->get('zfcuser_auth_service');
        $adapter->setAuthenticationService($authenticationService);

        /** @var RouteInterface $router */
        $router = $container->get('router');
        $adapter->setRouter($router);