From e9dec6148ee85d9753378580b9be589437e3e984 Mon Sep 17 00:00:00 2001 From: Danny van Wijk Date: Thu, 21 Nov 2024 13:25:19 +0100 Subject: [PATCH] Remove session security listener if values are not enabled --- .../KunstmaanAdminExtension.php | 10 ++++++++++ .../KunstmaanAdminExtensionTest.php | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Kunstmaan/AdminBundle/DependencyInjection/KunstmaanAdminExtension.php b/src/Kunstmaan/AdminBundle/DependencyInjection/KunstmaanAdminExtension.php index ff97b1c7b3..43e7653cb8 100644 --- a/src/Kunstmaan/AdminBundle/DependencyInjection/KunstmaanAdminExtension.php +++ b/src/Kunstmaan/AdminBundle/DependencyInjection/KunstmaanAdminExtension.php @@ -79,6 +79,7 @@ public function load(array $configs, ContainerBuilder $container): void } $this->registerExceptionLoggingConfiguration($config['exception_logging'], $container); + $this->removeSessionSecurityListener($config, $container); $container->setParameter('kunstmaan_admin.default_locale', $config['default_locale']); $container->setParameter('kunstmaan_admin.website_title', $config['website_title']); @@ -137,6 +138,15 @@ private function registerExceptionLoggingConfiguration(array $config, ContainerB $definition->setArgument(2, false); } + private function removeSessionSecurityListener(array $config, ContainerBuilder $container): void + { + if ($config['session_security']['ip_check'] || $config['session_security']['user_agent_check']) { + return; + } + + $container->removeDefinition('kunstmaan_admin.session_security'); + } + private function configureAuthentication(array $config, ContainerBuilder $container, LoaderInterface $loader): void { $container->setParameter('kunstmaan_admin.enable_new_cms_authentication', true); diff --git a/src/Kunstmaan/AdminBundle/Tests/DependencyInjection/KunstmaanAdminExtensionTest.php b/src/Kunstmaan/AdminBundle/Tests/DependencyInjection/KunstmaanAdminExtensionTest.php index 3da10d8991..7cceab1bb1 100644 --- a/src/Kunstmaan/AdminBundle/Tests/DependencyInjection/KunstmaanAdminExtensionTest.php +++ b/src/Kunstmaan/AdminBundle/Tests/DependencyInjection/KunstmaanAdminExtensionTest.php @@ -91,6 +91,20 @@ public function testExceptionExcludesFromExceptionLoggingConfig() $this->assertContainerBuilderHasParameter('kunstmaan_admin.admin_exception_excludes', ['test_exclude_new_config']); } + public function testRemoveSessionSecurityListener() + { + $this->assertContainerBuilderNotHasService('kunstmaan_admin.session_security'); + + $this->load(array_merge($this->getRequiredConfig(), [ + 'session_security' => [ + 'ip_check' => true, + 'user_agent_check' => true, + ], + ])); + + $this->assertContainerBuilderHasService('kunstmaan_admin.session_security'); + } + private function getRequiredConfig(?string $excludeKey = null) { $requiredConfig = [