Commit 878a1d3d authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Retrait des storage et identity provider Ldap lorsque l'auth LDAP est désactivée

parent 6d3ff3d5
......@@ -2,6 +2,7 @@
namespace UnicaenAuth\Authentication\Storage;
use UnicaenAuth\Options\ModuleOptions;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -31,6 +32,14 @@ class ChainServiceFactory implements FactoryInterface
{
$chain = new Chain();
/** @var ModuleOptions $options */
$options = $serviceLocator->get('unicaen-auth_module_options');
// retrait du fournisseur Ldap si l'auth LDAP est désactivée
if (isset($options->getLdap()['enabled']) && ! $options->getLdap()['enabled']) {
unset($this->mandatoryStorages[200]);
}
$storages = $this->mandatoryStorages + $this->storages;
krsort($storages);
......
<?php
namespace UnicaenAuth\Provider\Identity;
use Zend\ServiceManager\FactoryInterface;
......@@ -19,16 +20,11 @@ class ChainServiceFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$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);
$providers = $this->computeProviders($serviceLocator);
foreach ($providers as $priority => $name) {
$provider = $serviceLocator->get($name);
$chain->getEventManager()->attach('getIdentityRoles', [$provider, 'injectIdentityRoles'], $priority);
......@@ -36,4 +32,28 @@ class ChainServiceFactory implements FactoryInterface
return $chain;
}
/**
* @param ServiceLocatorInterface $serviceLocator
* @return array
*/
private function computeProviders(ServiceLocatorInterface $serviceLocator)
{
$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'];
// retrait du fournisseur 'Ldap' si l'auth Ldap est désactivée
if (isset($config['unicaen-auth']['ldap']['enabled']) && ! $config['unicaen-auth']['ldap']['enabled']) {
$key = array_search('UnicaenAuth\Provider\Identity\Ldap', $providers, true);
if ($key !== false) {
unset($providers[$key]);
}
}
return $providers;
}
}
\ No newline at end of file
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