merged branch Fran6co/fix-security-handlers (PR #4985)

Commits
-------

39157a8 [Security] fixes multiple overlapping definitions of DefaultFailureHandler and DefaultSuccessHandler in AbstractFactory

Discussion
----------

[Security] fixes multiple overlapping definitions of DefaultFailureHandler and DefaultSuccessHandler in AbstractFactory

If more than one listener extends AbstractFactory, you'll have multiple calls to createAuthenticationFailureHandler and createAuthenticationSuccessHandler with the same id.

Implicitly it's going to use the one generated by the last factory generating unexpected behavior.

This is related to commits 915704c071 and c6aa392df7
This commit is contained in:
Fabien Potencier 2012-07-20 07:15:13 +02:00
commit b201812927
2 changed files with 9 additions and 4 deletions

View File

@ -172,7 +172,7 @@ abstract class AbstractFactory implements SecurityFactoryInterface
return $config['success_handler'];
}
$successHandlerId = 'security.authentication.success_handler.'.$id;
$successHandlerId = 'security.authentication.success_handler.'.$id.'.'.str_replace('-', '_', $this->getKey());
$successHandler = $container->setDefinition($successHandlerId, new DefinitionDecorator('security.authentication.success_handler'));
$successHandler->replaceArgument(1, array_intersect_key($config, $this->defaultSuccessHandlerOptions));
@ -187,7 +187,7 @@ abstract class AbstractFactory implements SecurityFactoryInterface
return $config['failure_handler'];
}
$id = 'security.authentication.failure_handler.'.$id;
$id = 'security.authentication.failure_handler.'.$id.'.'.str_replace('-', '_', $this->getKey());
$failureHandler = $container->setDefinition($id, new DefinitionDecorator('security.authentication.failure_handler'));
$failureHandler->replaceArgument(2, array_intersect_key($config, $this->defaultFailureHandlerOptions));

View File

@ -54,7 +54,7 @@ class AbstractFactoryTest extends \PHPUnit_Framework_TestCase
$definition = $container->getDefinition('abstract_listener.foo');
$arguments = $definition->getArguments();
$this->assertEquals(new Reference('security.authentication.failure_handler.foo'), $arguments['index_6']);
$this->assertEquals(new Reference('security.authentication.failure_handler.foo.abstract_factory'), $arguments['index_6']);
}
public function testDefaultSuccessHandler()
@ -67,7 +67,7 @@ class AbstractFactoryTest extends \PHPUnit_Framework_TestCase
$definition = $container->getDefinition('abstract_listener.foo');
$arguments = $definition->getArguments();
$this->assertEquals(new Reference('security.authentication.success_handler.foo'), $arguments['index_5']);
$this->assertEquals(new Reference('security.authentication.success_handler.foo.abstract_factory'), $arguments['index_5']);
}
protected function callFactory($id, $config, $userProviderId, $defaultEntryPointId)
@ -84,6 +84,11 @@ class AbstractFactoryTest extends \PHPUnit_Framework_TestCase
->method('getListenerId')
->will($this->returnValue('abstract_listener'))
;
$factory
->expects($this->any())
->method('getKey')
->will($this->returnValue('abstract_factory'))
;
$container = new ContainerBuilder();
$container->register('auth_provider');