Skip to content
Snippets Groups Projects
Select Git revision
  • b3d50fdb8f1c72db47cb0e39aaaabb84f898abb7
  • master default protected
  • ll-wf-finitions
  • ll-workflow
  • b24
  • alc-scindage-donnees-pj
  • FJ_LL_Tbl_Contrat
  • alc-docker-node
  • ll-apiplatform
  • php84
  • ll-rgpd
  • b23
  • alc-filtre-type-intervenant
  • ll-sans-mdb5
  • formules-ancienne-infra
  • ll-formules
  • alc-intervenant-dmep
  • ll-suppr-v_vol-s
  • b20
  • ll-postgresql
  • b23.0.1
  • 24.10
  • 24.9
  • 24.8
  • 24.7
  • 24.6
  • 24.5
  • 24.4
  • 24.3
  • 24.2
  • 24.1
  • 24.0
  • 23.15
  • 24.0-beta19
  • 24.0-beta18
  • 24.0-beta17
  • 24.0-beta16
  • 24.0-beta15
  • 24.0-beta14
  • 24.0-beta13
  • 23.14
41 results

EntityServiceFactory.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AdapterChain.php 3.68 KiB
    <?php
    
    namespace ZfcUser\Authentication\Adapter;
    
    use Laminas\Authentication\Adapter\AdapterInterface;
    use Laminas\Authentication\Result as AuthenticationResult;
    use Laminas\EventManager\Event;
    use Laminas\EventManager\EventManagerAwareTrait;
    use Laminas\Stdlib\RequestInterface as Request;
    use Laminas\Stdlib\ResponseInterface as Response;
    use ZfcUser\Exception;
    
    class AdapterChain implements AdapterInterface
    {
        use EventManagerAwareTrait;
    
        /**
         * @var AdapterChainEvent
         */
        protected $event;
    
        /**
         * Returns the authentication result
         *
         * @return AuthenticationResult
         */
        public function authenticate()
        {
            $e = $this->getEvent();
    
            $result = new AuthenticationResult(
                $e->getCode(),
                $e->getIdentity(),
                $e->getMessages()
            );
    
            $this->resetAdapters();
    
            return $result;
        }
    
        /**
         * prepareForAuthentication
         *
         * @param  Request $request
         * @return Response|bool
         * @throws Exception\AuthenticationEventException
         */
        public function prepareForAuthentication(Request $request)
        {
            $e = $this->getEvent();
            $e->setRequest($request);
    
            $this->getEventManager()->trigger('authenticate.pre', $e);
    
            $result = $this->getEventManager()->trigger('authenticate', $e, function ($test) {
                return ($test instanceof Response);
            });
    
            if ($result->stopped()) {
                if ($result->last() instanceof Response) {
                    return $result->last();
                }
    
                throw new Exception\AuthenticationEventException(
                    sprintf(
                        'Auth event was stopped without a response. Got "%s" instead',
                        is_object($result->last()) ? get_class($result->last()) : gettype($result->last())
                    )
                );
            }
    
            if ($e->getIdentity()) {
                $this->getEventManager()->trigger('authenticate.success', $e);
                return true;
            }
    
            $this->getEventManager()->trigger('authenticate.fail', $e);
    
            return false;
        }
    
        /**
         * resetAdapters
         *
         * @return AdapterChain
         */
        public function resetAdapters()
        {
            $sharedManager = $this->getEventManager()->getSharedManager();
    
            if ($sharedManager) {
                $listeners = $sharedManager->getListeners(['authenticate'], 'authenticate');
                foreach ($listeners as $listener) {
                    if (is_array($listener) && $listener[0] instanceof ChainableAdapter) {
                        $listener[0]->getStorage()->clear();
                    }
                }
            }
    
            return $this;
        }
    
        /**
         * logoutAdapters
         *
         * @return AdapterChain
         */
        public function logoutAdapters()
        {
            //Adapters might need to perform additional cleanup after logout
            $this->getEventManager()->trigger('logout', $this->getEvent());
        }
    
        /**
         * Get the auth event
         *
         * @return AdapterChainEvent
         */
        public function getEvent()
        {
            if (null === $this->event) {
                $this->setEvent(new AdapterChainEvent);
                $this->event->setTarget($this);
            }
    
            return $this->event;
        }
    
        /**
         * Set an event to use during dispatch
         *
         * By default, will re-cast to AdapterChainEvent if another event type is provided.
         *
         * @param  Event $e
         * @return AdapterChain
         */
        public function setEvent(Event $e)
        {
            if (!$e instanceof AdapterChainEvent) {
                $eventParams = $e->getParams();
                $e = new AdapterChainEvent();
                $e->setParams($eventParams);
            }
    
            $this->event = $e;
    
            return $this;
        }
    }