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 <?php
$settings = array( $settings = array(
/**
* Fournisseurs d'identité.
*/
'identity_providers' => array(
200 => 'UnicaenAuth\Provider\Identity\Db',
100 => 'UnicaenAuth\Provider\Identity\Ldap',
),
); );
$zfcuserSettings = array( $zfcuserSettings = array(
......
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
namespace UnicaenAuth\Provider\Identity; namespace UnicaenAuth\Provider\Identity;
use BjyAuthorize\Provider\Identity\ProviderInterface; use BjyAuthorize\Provider\Identity\ProviderInterface;
use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerInterface; use Zend\EventManager\EventManagerAwareTrait;
use Zend\Permissions\Acl\Role\RoleInterface; use Zend\Permissions\Acl\Role\RoleInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorAwareTrait;
/** /**
* Chaîne de responsabilité permettant à plusieures sources de fournir * Chaîne de responsabilité permettant à plusieures sources de fournir
...@@ -19,15 +18,8 @@ use Zend\ServiceManager\ServiceLocatorInterface; ...@@ -19,15 +18,8 @@ use Zend\ServiceManager\ServiceLocatorInterface;
*/ */
class Chain implements ProviderInterface, ServiceLocatorAwareInterface, EventManagerAwareInterface class Chain implements ProviderInterface, ServiceLocatorAwareInterface, EventManagerAwareInterface
{ {
/** use ServiceLocatorAwareTrait;
* @var ServiceLocatorAwareInterface use EventManagerAwareTrait;
*/
protected $serviceLocator;
/**
* @var EventManagerInterface
*/
protected $eventManager;
/** /**
* @var ChainEvent * @var ChainEvent
...@@ -82,57 +74,6 @@ class Chain implements ProviderInterface, ServiceLocatorAwareInterface, EventMan ...@@ -82,57 +74,6 @@ class Chain implements ProviderInterface, ServiceLocatorAwareInterface, EventMan
return $this->roles; 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 * @return ChainEvent
......
...@@ -5,7 +5,7 @@ use Zend\ServiceManager\FactoryInterface; ...@@ -5,7 +5,7 @@ use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
/** /**
* Description of CcainIdentityProviderServiceFactory * Intsancie une chaîne de fournisseurs d'identité.
* *
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/ */
...@@ -19,17 +19,19 @@ class ChainServiceFactory implements FactoryInterface ...@@ -19,17 +19,19 @@ class ChainServiceFactory implements FactoryInterface
*/ */
public function createService(ServiceLocatorInterface $serviceLocator) public function createService(ServiceLocatorInterface $serviceLocator)
{ {
$providers = array( $config = $serviceLocator->get('Config'); //'unicaen-auth_module_options'
200 => 'UnicaenAuth\Provider\Identity\Db', if (!isset($config['unicaen-auth']['identity_providers']) || !$config['unicaen-auth']['identity_providers']) {
100 => 'UnicaenAuth\Provider\Identity\Ldap', 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 = new Chain();
$chain->setServiceLocator($serviceLocator); $chain->setServiceLocator($serviceLocator);
foreach ($providers as $priority => $name) { foreach ($providers as $priority => $name) {
$provider = $serviceLocator->get($name); $provider = $serviceLocator->get($name);
$chain->getEventManager()->attach('getIdentityRoles', array($provider, 'getIdentityRolesTrigger'), $priority); $chain->getEventManager()->attach('getIdentityRoles', array($provider, 'injectIdentityRoles'), $priority);
} }
return $chain; return $chain;
......
...@@ -5,9 +5,9 @@ namespace UnicaenAuth\Provider\Identity; ...@@ -5,9 +5,9 @@ namespace UnicaenAuth\Provider\Identity;
interface ChainableProvider 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 ...@@ -21,7 +21,7 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getIdentityRolesTrigger(ChainEvent $event) public function injectIdentityRoles(ChainEvent $event)
{ {
$event->addRoles($this->getIdentityRoles()); $event->addRoles($this->getIdentityRoles());
} }
......
<?php <?php
namespace UnicaenAuth\Provider\Identity; namespace UnicaenAuth\Provider\Identity;
use UnicaenAuth\Entity\Ldap\People;
use BjyAuthorize\Provider\Identity\AuthenticationIdentityProvider; use BjyAuthorize\Provider\Identity\AuthenticationIdentityProvider;
use BjyAuthorize\Provider\Role\ProviderInterface; use BjyAuthorize\Provider\Role\ProviderInterface;
use ZfcUser\Entity\UserInterface; use ZfcUser\Entity\UserInterface;
...@@ -16,12 +15,12 @@ use ZfcUser\Entity\UserInterface; ...@@ -16,12 +15,12 @@ use ZfcUser\Entity\UserInterface;
* *
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/ */
class Ldap extends AuthenticationIdentityProvider implements ChainableProvider//, ServiceLocatorAwareInterface class Ldap extends AuthenticationIdentityProvider implements ChainableProvider
{ {
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getIdentityRolesTrigger(ChainEvent $event) public function injectIdentityRoles(ChainEvent $event)
{ {
$event->addRoles($this->getIdentityRoles()); $event->addRoles($this->getIdentityRoles());
} }
......
Supports Markdown
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