[SecurityBundle] Firewall providers building - code cleaning
This commit is contained in:
parent
b0ab6878ed
commit
c3c904d01f
@ -495,6 +495,7 @@ class SecurityExtension extends Extension
|
||||
{
|
||||
$name = $this->getUserProviderId(strtolower($name));
|
||||
|
||||
// Doctrine Entity and In-memory DAO provider are managed by factories
|
||||
foreach ($this->userProviderFactories as $factory) {
|
||||
$key = str_replace('-', '_', $factory->getKey());
|
||||
|
||||
@ -521,37 +522,12 @@ class SecurityExtension extends Extension
|
||||
|
||||
$container
|
||||
->setDefinition($name, new DefinitionDecorator('security.user.provider.chain'))
|
||||
->addArgument($providers)
|
||||
;
|
||||
->addArgument($providers);
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
// Doctrine Entity DAO provider
|
||||
if (isset($provider['entity'])) {
|
||||
$container
|
||||
->setDefinition($name, new DefinitionDecorator('security.user.provider.entity'))
|
||||
->addArgument($provider['entity']['class'])
|
||||
->addArgument($provider['entity']['property'])
|
||||
;
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
// In-memory DAO provider
|
||||
$definition = $container->setDefinition($name, new DefinitionDecorator('security.user.provider.in_memory'));
|
||||
foreach ($provider['users'] as $username => $user) {
|
||||
$userId = $name.'_'.$username;
|
||||
|
||||
$container
|
||||
->setDefinition($userId, new DefinitionDecorator('security.user.provider.in_memory.user'))
|
||||
->setArguments(array($username, (string) $user['password'], $user['roles']))
|
||||
;
|
||||
|
||||
$definition->addMethodCall('createUser', array(new Reference($userId)));
|
||||
}
|
||||
|
||||
return $name;
|
||||
throw new InvalidConfigurationException(sprintf('Unable to create definition for "%s" user provider', $name));
|
||||
}
|
||||
|
||||
private function getUserProviderId($name)
|
||||
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
|
||||
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class DummyProvider implements UserProviderFactoryInterface
|
||||
{
|
||||
public function create(ContainerBuilder $container, $id, $config)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getKey()
|
||||
{
|
||||
return 'foo';
|
||||
}
|
||||
|
||||
public function addConfiguration(NodeDefinition $node)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
|
||||
use Symfony\Bundle\SecurityBundle\SecurityBundle;
|
||||
use Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider\DummyProvider;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class SecurityExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
@ -66,6 +67,33 @@ class SecurityExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
$container->compile();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
* @expectedExceptionMessage Unable to create definition for "security.user.provider.concrete.my_foo" user provider
|
||||
*/
|
||||
public function testFirewallWithInvalidUserProvider()
|
||||
{
|
||||
$container = $this->getRawContainer();
|
||||
|
||||
$extension = $container->getExtension('security');
|
||||
$extension->addUserProviderFactory(new DummyProvider());
|
||||
|
||||
$container->loadFromExtension('security', array(
|
||||
'providers' => array(
|
||||
'my_foo' => array('foo' => []),
|
||||
),
|
||||
|
||||
'firewalls' => array(
|
||||
'some_firewall' => array(
|
||||
'pattern' => '/.*',
|
||||
'http_basic' => [],
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$container->compile();
|
||||
}
|
||||
|
||||
protected function getRawContainer()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
Reference in New Issue
Block a user