From ca03c152010af2294238a160d0b0b15be915c64e Mon Sep 17 00:00:00 2001 From: Thijs Kinkhorst Date: Sat, 11 May 2019 16:14:14 +0200 Subject: [PATCH] Skip initialisation with zero authsources. This allows me to include the bundle in my project, including changes to the various files and use twig fucntions as conditionals, but only activate it for deploys that will be using SSP authn. This change basically allows you to comment out/leave out the ssp_guard config in app/config/config.yml. If you do so, your project will just work and the twig helpers will tell you that there are 0 authsources. It is also then not necessary that the installation_path of ssp exists. It leaves enable/disable configuration of the bundle in one place. --- DependencyInjection/SSPGuardExtension.php | 56 ++++++++++++----------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/DependencyInjection/SSPGuardExtension.php b/DependencyInjection/SSPGuardExtension.php index 33bddcd..ff2c56b 100644 --- a/DependencyInjection/SSPGuardExtension.php +++ b/DependencyInjection/SSPGuardExtension.php @@ -37,35 +37,39 @@ public function load(array $configs, ContainerBuilder $container) $configuration = $this->getConfiguration($configs, $container); $config = $this->processConfiguration($configuration, $configs); - $container->setParameter('ssp_guard.installation_path', $config['installation_path']); - if (method_exists($container, 'resolveEnvPlaceholders')) { - $container->setParameter('ssp_guard.installation_path', $container->resolveEnvPlaceholders($container->getParameter('ssp_guard.installation_path'), true)); - } - - // Find SimpleSAMLphp _autoload.php file - $autoloadPath = sprintf('%s/lib/_autoload.php', rtrim($container->getParameter('ssp_guard.installation_path'), '/')); - if (false === file_exists($autoloadPath)) { - throw new InvalidConfigurationException('The path "ssp_guard.installation_path" doesn\'t contain a valid SimpleSAMLphp installation: '.$autoloadPath); - } - $this->autoloadPath = $autoloadPath; - $authSources = $config['auth_sources']; $authSourcesKeys = []; - foreach ($authSources as $key => $authSource) { - $tree = new TreeBuilder(); - $node = $tree->root('ssp_guard/auth_sources/'.$key); - $this->buildConfigurationForAuthSource($node, $key); - $processor = new Processor(); - $config = $processor->process($tree->buildTree(), [$authSource]); - - $authSourceKey = $this->configureAuthSource( - $container, - $key, - $config - ); - - $authSourcesKeys[$key] = $authSourceKey; + // Only configure the bundle if we have a configuration + if (count($authSources) > 0) { + + $container->setParameter('ssp_guard.installation_path', $config['installation_path']); + if (method_exists($container, 'resolveEnvPlaceholders')) { + $container->setParameter('ssp_guard.installation_path', $container->resolveEnvPlaceholders($container->getParameter('ssp_guard.installation_path'), true)); + } + + // Find SimpleSAMLphp _autoload.php file + $autoloadPath = sprintf('%s/lib/_autoload.php', rtrim($container->getParameter('ssp_guard.installation_path'), '/')); + if (false === file_exists($autoloadPath)) { + throw new InvalidConfigurationException('The path "ssp_guard.installation_path" doesn\'t contain a valid SimpleSAMLphp installation: '.$autoloadPath); + } + $this->autoloadPath = $autoloadPath; + + foreach ($authSources as $key => $authSource) { + $tree = new TreeBuilder(); + $node = $tree->root('ssp_guard/auth_sources/'.$key); + $this->buildConfigurationForAuthSource($node, $key); + $processor = new Processor(); + $config = $processor->process($tree->buildTree(), [$authSource]); + + $authSourceKey = $this->configureAuthSource( + $container, + $key, + $config + ); + + $authSourcesKeys[$key] = $authSourceKey; + } } $container->getDefinition('ssp.guard.registry')