Commit 63bfd1c0 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Authentification shibboleth : serrages de vis dans les typages et les...

Authentification shibboleth : serrages de vis dans les typages et les attributs obligatoires, toilettage, doc.
parent e4c714d0
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
# CHANGELOG

6.x.x ?????????????????????????????????
6.4.4
-----

- Authentification shibboleth : serrages de vis dans les typages et les attributs obligatoires, toilettage, doc.
- Ajout de documentation

6.4.3 (29/01/2025)
+11 −9
Original line number Diff line number Diff line
@@ -200,18 +200,20 @@ $settings = [
            'sn'                     => 'HTTP_SN',
            'givenName'              => 'HTTP_GIVENNAME',
        ],
        /*
        */

        /**
         * Clés dont la présence sera requise par la bibliothèque dans la variable superglobale $_SERVER
         * une fois l'authentification réussie.
         */
        'required_attributes' => [
            'eppn',
            'mail',
            'eduPersonPrincipalName',
            'supannCivilite',
            'displayName',
            'sn | surname', // i.e. 'sn' ou 'surname'
            'givenName',
            'supannEtuId|supannEmpId',
            'supannEmpId | supannEtuId | supannRefId',
        ],
        */

        /**
         * Configuration de la stratégie d'extraction d'un identifiant utile parmi les données d'authentification
@@ -223,19 +225,19 @@ $settings = [
            // domaine (ex: 'unicaen.fr') de l'EPPN (ex: hochonp@unicaen.fr')
            'unicaen.fr' => [
                'supannRefId' => [
                    // nom du 1er attribut recherché
                    // 1er attribut recherché
                    'name' => 'supannRefId', // ex: '{OCTOPUS:ID}1234;{ISO15693}044D1AZE7A5P80'
                    // pattern éventuel pour extraire la partie intéressante
                    'preg_match_pattern' => '|\{OCTOPUS:ID\}(\d+)|', // ex: permet d'extraire '1234'
                ],
                'supannEmpId' => [
                    // nom du 2e attribut recherché, si le 1er est introuvable
                    // 2e attribut recherché, si le 1er est introuvable
                    'name' => 'supannEmpId',
                    // pas de pattern donc valeur brute utilisée
                    'preg_match_pattern' => null,
                ],
                'supannEtuId' => [
                    // nom du 3e attribut recherché, si le 2e est introuvable
                    // 3e attribut recherché, si le 2e est introuvable
                    'name' => 'supannEtuId',
                ],
            ],
+15 −15
Original line number Diff line number Diff line
@@ -80,10 +80,10 @@ return [
            /**
             * URL de déconnexion.
             */
            'logout_url' => '/Shibboleth.sso/Logout?return=', // NB: '?return=' semble obligatoire!
            'logout_url' => '/Shibboleth.sso/Logout?return=', // NB: '?return=' obligatoire pour pouvoir concaténer une URL de retour

            /**
             * Autorise l'IDP à gérer la déconnexion
             * Autoriser l'IDP à gérer la déconnexion ?
             */
            'idp_logout' => false,

@@ -114,17 +114,17 @@ return [
            /**
             * Clés dont la présence sera requise par l'application dans la variable superglobale $_SERVER
             * une fois l'authentification réussie.
             */
            //'required_attributes' => [
            //    'eppn',
            //    'mail',
            //    'eduPersonPrincipalName',
             * Celles-ci sont requises d'office par la bibliothèque :
             *   - 'eppn',
             *   - 'mail',
             *   - 'displayName',
             *   - 'sn | surname', // i.e. 'sn' ou 'surname'
             *   - 'givenName',
             *   - 'supannEmpId | supannEtuId | supannRefId',
             */
            'required_attributes' => [
                //'supannCivilite',
            //    'displayName',
            //    'sn|surname', // i.e. 'sn' ou 'surname'
            //    'givenName',
            //    'supannEtuId|supannEmpId',
            //],
            ],

            /**
             * Configuration de la stratégie d'extraction d'un identifiant utile parmi les données d'authentification
@@ -135,19 +135,19 @@ return [
                // domaine (ex: 'unicaen.fr') de l'EPPN (ex: hochonp@unicaen.fr')
//                'unicaen.fr' => [
//                    'supannRefId' => [
//                        // nom du 1er attribut recherché
//                        // 1er attribut recherché
//                        'name' => 'supannRefId', // ex: '{OCTOPUS:ID}1234;{ISO15693}044D1AZE7A5P80'
//                        // pattern éventuel pour extraire la partie intéressante
//                        'preg_match_pattern' => '|\{OCTOPUS:ID\}(\d+)|', // ex: permet d'extraire '1234'
//                    ],
//                    'supannEmpId' => [
//                        // nom du 2e attribut recherché
//                        // 2e attribut recherché, si le 1er n'a pas été trouvé
//                        'name' => 'supannEmpId',
//                        // pas de pattern donc valeur brute utilisée
//                        'preg_match_pattern' => null,
//                    ],
//                    'supannEtuId' => [
//                        // nom du 3e attribut recherché
//                        // 3e attribut recherché, si le 2e n'a pas été trouvé
//                        'name' => 'supannEtuId',
//                    ],
//                ],
+18 −37
Original line number Diff line number Diff line
@@ -2,10 +2,11 @@

namespace UnicaenAuthentification\Authentication\Adapter;

use UnicaenAuthentification\Authentication\SessionIdentity;
use UnicaenAuthentification\Controller\AuthController;
use UnicaenAuthentification\Options\Traits\ModuleOptionsAwareTrait;
use UnicaenAuthentification\Service\Traits\ShibServiceAwareTrait;
use UnicaenAuthentification\Service\User;
use UnicaenAuthentification\Service\User as UserService;
use Laminas\Authentication\AuthenticationService;
use Laminas\Authentication\Result as AuthenticationResult;
use Laminas\EventManager\EventInterface;
@@ -25,57 +26,34 @@ class Shib extends AbstractAdapter

    const TYPE = 'shib';

    /**
     * @var string
     */
    protected $type = self::TYPE;
    protected AuthenticationService $authenticationService;

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

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

    /**
     * @var RouteInterface
     */
    private $router;
    private RouteInterface $router;

    /**
     * @param RouteInterface $router
     */
    public function setRouter(RouteInterface $router)
    public function setRouter(RouteInterface $router): void
    {
        $this->router = $router;
    }

    /**
     * @var User
     */
    private $userService;
    private UserService $userService;

    /**
     * @param User $userService
     */
    public function setUserService(User $userService)
    public function setUserService(UserService $userService): void
    {
        $this->userService = $userService;
    }

    /**
     * @inheritDoc
     * @param \Laminas\EventManager\EventInterface $e
     * @throws \Laminas\Authentication\Exception\ExceptionInterface
     */
//    public function authenticate(EventInterface $e)
    public function authenticate( $e)
    public function authenticate($e): Response|bool
    {
        // NB: Dans la version 3.0.0 de zf-commons/zfc-user, cette méthode prend un EventInterface.
        // Mais dans la branche 3.x, c'est un AdapterChainEvent !
@@ -126,25 +104,25 @@ class Shib extends AbstractAdapter
            ->setCode(AuthenticationResult::SUCCESS)
            ->setMessages(['Authentication successful.']);

        /* @var $userService User */
        /* @var $userService UserService */
        $this->userService->userAuthenticated($shibUser);

        return true;
    }

    /**
     * @inheritDoc
     * @throws \Laminas\Authentication\Exception\ExceptionInterface
     */
    public function logout(EventInterface $e)
    public function logout(EventInterface $e): ?Response
    {
        $storage = $this->getStorage()->read();

        if (is_array($storage)){
            if (! isset($storage['identity'])) {
                return;
                return null;
            }
        }else if (!$storage instanceof SessionIdentity) {
            return;
            return null;
        }

        parent::logout($e);
@@ -167,6 +145,7 @@ class Shib extends AbstractAdapter
            $response = new Response();
            $response->getHeaders()->addHeaderLine('Location', $shibbolethLogoutUrl);
            $response->setStatusCode(302);

            return $response;
        }

@@ -177,5 +156,7 @@ class Shib extends AbstractAdapter
         * todo: supprimer cette verrue lorsque l'IDP redirigera correctement.
         */
        $this->authenticationService->clearIdentity();

        return null;
    }
}
 No newline at end of file
+6 −8
Original line number Diff line number Diff line
@@ -13,12 +13,10 @@ use UnicaenAuthentification\Service\User;
class ShibAdapterFactory
{
    /**
     * @param ContainerInterface $container
     * @param string $requestedName
     * @param array|null $options
     * @return Shib
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    public function __invoke(ContainerInterface $container, string $requestedName, array $options = null)
    public function __invoke(ContainerInterface $container, string $requestedName, array $options = null): Shib
    {
        $adapter = new Shib();
        $adapter->setStorage(new Session(Shib::class));
@@ -29,10 +27,10 @@ class ShibAdapterFactory
    }

    /**
     * @param Shib $adapter
     * @param ContainerInterface $container
     * @throws \Psr\Container\NotFoundExceptionInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     */
    private function injectDependencies(Shib $adapter, ContainerInterface $container)
    private function injectDependencies(Shib $adapter, ContainerInterface $container): void
    {
        /** @var ShibService $shibService */
        $shibService = $container->get(ShibService::class);
Loading