Merge branch '2.8' into 3.4
* 2.8: [SecurityBundle] Fail if security.http_utils cannot be configured
This commit is contained in:
commit
500bede9c8
@ -26,7 +26,7 @@ class AddSessionDomainConstraintPass implements CompilerPassInterface
|
|||||||
*/
|
*/
|
||||||
public function process(ContainerBuilder $container)
|
public function process(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
if (!$container->hasParameter('session.storage.options') || !$container->has('security.http_utils')) {
|
if (!$container->hasParameter('session.storage.options')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +34,7 @@ class AddSessionDomainConstraintPass implements CompilerPassInterface
|
|||||||
$domainRegexp = empty($sessionOptions['cookie_domain']) ? '%s' : sprintf('(?:%%s|(?:.+\.)?%s)', preg_quote(trim($sessionOptions['cookie_domain'], '.')));
|
$domainRegexp = empty($sessionOptions['cookie_domain']) ? '%s' : sprintf('(?:%%s|(?:.+\.)?%s)', preg_quote(trim($sessionOptions['cookie_domain'], '.')));
|
||||||
$domainRegexp = (empty($sessionOptions['cookie_secure']) ? 'https?://' : 'https://').$domainRegexp;
|
$domainRegexp = (empty($sessionOptions['cookie_secure']) ? 'https?://' : 'https://').$domainRegexp;
|
||||||
|
|
||||||
|
// if the service doesn't exist, an exception must be thrown - ignoring would put security at risk
|
||||||
$container->findDefinition('security.http_utils')->addArgument(sprintf('{^%s$}i', $domainRegexp));
|
$container->findDefinition('security.http_utils')->addArgument(sprintf('{^%s$}i', $domainRegexp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ class SecurityBundle extends Bundle
|
|||||||
$extension->addUserProviderFactory(new InMemoryFactory());
|
$extension->addUserProviderFactory(new InMemoryFactory());
|
||||||
$extension->addUserProviderFactory(new LdapFactory());
|
$extension->addUserProviderFactory(new LdapFactory());
|
||||||
$container->addCompilerPass(new AddSecurityVotersPass());
|
$container->addCompilerPass(new AddSecurityVotersPass());
|
||||||
$container->addCompilerPass(new AddSessionDomainConstraintPass(), PassConfig::TYPE_AFTER_REMOVING);
|
$container->addCompilerPass(new AddSessionDomainConstraintPass(), PassConfig::TYPE_BEFORE_REMOVING);
|
||||||
$container->addCompilerPass(new RegisterCsrfTokenClearingLogoutHandlerPass());
|
$container->addCompilerPass(new RegisterCsrfTokenClearingLogoutHandlerPass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +96,19 @@ class AddSessionDomainConstraintPassTest extends TestCase
|
|||||||
$this->assertTrue($utils->createRedirectResponse($request, 'http://pirate.com/foo')->isRedirect('http://pirate.com/foo'));
|
$this->assertTrue($utils->createRedirectResponse($request, 'http://pirate.com/foo')->isRedirect('http://pirate.com/foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
|
||||||
|
* @expectedExceptionMessage You have requested a non-existent service "security.http_utils".
|
||||||
|
*/
|
||||||
|
public function testNoHttpUtils()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$container->setParameter('session.storage.options', array());
|
||||||
|
|
||||||
|
$pass = new AddSessionDomainConstraintPass();
|
||||||
|
$pass->process($container);
|
||||||
|
}
|
||||||
|
|
||||||
private function createContainer($sessionStorageOptions)
|
private function createContainer($sessionStorageOptions)
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
Reference in New Issue
Block a user