Commit a19f7e00 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Ajout du mécanisme de rapatriement de l'utilisateur courant

parent 2d8707d2
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -152,6 +152,9 @@ class Module implements ConfigProviderInterface, ViewHelperProviderInterface, Se
                    return $form;
                },
            ),
            'invokables' => array(
                'authUserContext' => '\UnicaenAuth\Service\UserContext'
            ),
        );
      }
}
 No newline at end of file
+100 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenAuth\Service;

use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcUser\Entity\UserInterface;
use UnicaenAuth\Entity\Ldap\People;

/**
 *
 *
 * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
 */
class UserContext implements ServiceLocatorAwareInterface
{

    /**
     * @var ServiceLocatorInterface
     */
    protected $sl;

    /**
     * @var mixed
     */
    protected $identity;





    /**
     *
     * @return mixed
     */
    protected function getIdentity()
    {
        if (null === $this->identity) {
            $authenticationService = $this->sl->get('Zend\Authentication\AuthenticationService');
            if ($authenticationService->hasIdentity()) {
                $this->identity = $authenticationService->getIdentity();
            }
        }

        return $this->identity;
    }

    /**
     * Retourne l'utilisateur BDD courant
     *
     * @return UserInterface
     */
    public function getDbUser()
    {
        if (($identity = $this->getIdentity())) {
            if (isset($identity['db']) && $identity['db'] instanceof UserInterface) {
                return $identity['db'];
            }
        }
        return null;
    }

    /**
     * Retourne l'utilisateur LDAP courant
     *
     * @return People
     */
    public function getLdapUser()
    {
        if (($identity = $this->getIdentity())) {
            if (isset($identity['ldap']) && $identity['ldap'] instanceof People) {
                return $identity['ldap'];
            }
        }
        return null;
    }

    /**
     * Set service locator
     *
     * @param ServiceLocatorInterface $serviceLocator
     * @return self
     */
    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
    {
        $this->sl = $serviceLocator;

        return $this;
    }

    /**
     * Get service locator
     *
     * @return ServiceLocatorInterface
     */
    public function getServiceLocator()
    {
        return $this->sl;
    }
}
 No newline at end of file