Skip to content

Commit

Permalink
Remove session security listener if values are not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny van Wijk committed Nov 21, 2024
1 parent 8f1601b commit e9dec61
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit e9dec61

Please sign in to comment.