Skip to content
Snippets Groups Projects
Commit a19f7e00 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

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

parent 2d8707d2
No related branches found
No related tags found
No related merge requests found
......@@ -152,6 +152,9 @@ class Module implements ConfigProviderInterface, ViewHelperProviderInterface, Se
return $form;
},
),
'invokables' => array(
'authUserContext' => '\UnicaenAuth\Service\UserContext'
),
);
}
}
\ No newline at end of file
<?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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment