Commit 41456b6b authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Fournisseurs d'identité pour BjyAuthorize : ajout possibilité d'ajouter des...

Fournisseurs d'identité pour BjyAuthorize : ajout possibilité d'ajouter des fournisseurs d'identité via la config de UnicaenAuth : refactorisation.
parent 0aee6b10
<?php
$settings = array(
/**
* Fournisseurs d'identité.
*/
'identity_providers' => array(
200 => 'UnicaenAuth\Provider\Identity\Db',
100 => 'UnicaenAuth\Provider\Identity\Ldap',
),
);
$zfcuserSettings = array(
......
......@@ -2,12 +2,11 @@
namespace UnicaenAuth\Provider\Identity;
use BjyAuthorize\Provider\Identity\ProviderInterface;
use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\EventManagerAwareTrait;
use Zend\Permissions\Acl\Role\RoleInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
/**
* Chaîne de responsabilité permettant à plusieures sources de fournir
......@@ -19,15 +18,8 @@ use Zend\ServiceManager\ServiceLocatorInterface;
*/
class Chain implements ProviderInterface, ServiceLocatorAwareInterface, EventManagerAwareInterface
{
/**
* @var ServiceLocatorAwareInterface
*/
protected $serviceLocator;
/**
* @var EventManagerInterface
*/
protected $eventManager;
use ServiceLocatorAwareTrait;
use EventManagerAwareTrait;
/**
* @var ChainEvent
......@@ -82,57 +74,6 @@ class Chain implements ProviderInterface, ServiceLocatorAwareInterface, EventMan
return $this->roles;
}
/**
* Inject an EventManager instance
*
* @param EventManagerInterface $eventManager
* @return self
*/
public function setEventManager(EventManagerInterface $eventManager)
{
$eventManager->setIdentifiers(array(
__CLASS__,
get_called_class(),
));
$this->eventManager = $eventManager;
return $this;
}
/**
* Get the EventManager instance
*
* @return EventManagerInterface
*/
public function getEventManager()
{
if (null === $this->eventManager) {
$this->setEventManager(new EventManager());
}
return $this->eventManager;
}
/**
* Set service locator
*
* @param ServiceLocatorInterface $serviceLocator
* @return self
*/
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
return $this;
}
/**
* Get service locator
*
* @return ServiceLocatorInterface
*/
public function getServiceLocator()
{
return $this->serviceLocator;
}
/**
*
* @return ChainEvent
......
......@@ -5,7 +5,7 @@ use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* Description of CcainIdentityProviderServiceFactory
* Intsancie une chaîne de fournisseurs d'identité.
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
......@@ -19,17 +19,19 @@ class ChainServiceFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$providers = array(
200 => 'UnicaenAuth\Provider\Identity\Db',
100 => 'UnicaenAuth\Provider\Identity\Ldap',
);
$config = $serviceLocator->get('Config'); //'unicaen-auth_module_options'
if (!isset($config['unicaen-auth']['identity_providers']) || !$config['unicaen-auth']['identity_providers']) {
throw new \UnicaenApp\Exception\RuntimeException("Aucun fournisseur d'identité spécifié dans la config.");
}
$providers = (array) $config['unicaen-auth']['identity_providers'];
$chain = new Chain();
$chain->setServiceLocator($serviceLocator);
foreach ($providers as $priority => $name) {
$provider = $serviceLocator->get($name);
$chain->getEventManager()->attach('getIdentityRoles', array($provider, 'getIdentityRolesTrigger'), $priority);
$chain->getEventManager()->attach('getIdentityRoles', array($provider, 'injectIdentityRoles'), $priority);
}
return $chain;
......
......@@ -5,9 +5,9 @@ namespace UnicaenAuth\Provider\Identity;
interface ChainableProvider
{
/**
* Retrieve roles for the current identity
* Injecte les rôles que possède l'identité authentifiée courante.
*
* @param ChainEvent $event
* @param ChainEvent $e
*/
public function getIdentityRolesTrigger(ChainEvent $e);
public function injectIdentityRoles(ChainEvent $e);
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider
/**
* {@inheritDoc}
*/
public function getIdentityRolesTrigger(ChainEvent $event)
public function injectIdentityRoles(ChainEvent $event)
{
$event->addRoles($this->getIdentityRoles());
}
......
<?php
namespace UnicaenAuth\Provider\Identity;
use UnicaenAuth\Entity\Ldap\People;
use BjyAuthorize\Provider\Identity\AuthenticationIdentityProvider;
use BjyAuthorize\Provider\Role\ProviderInterface;
use ZfcUser\Entity\UserInterface;
......@@ -16,12 +15,12 @@ use ZfcUser\Entity\UserInterface;
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class Ldap extends AuthenticationIdentityProvider implements ChainableProvider//, ServiceLocatorAwareInterface
class Ldap extends AuthenticationIdentityProvider implements ChainableProvider
{
/**
* {@inheritDoc}
*/
public function getIdentityRolesTrigger(ChainEvent $event)
public function injectIdentityRoles(ChainEvent $event)
{
$event->addRoles($this->getIdentityRoles());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment