[SecurityBundle] Fix valid provider considered undefined
This commit is contained in:
parent
a5130b29c6
commit
efa4cb9a66
@ -331,10 +331,10 @@ class SecurityExtension extends Extension
|
||||
|
||||
// Provider id (take the first registered provider if none defined)
|
||||
if (isset($firewall['provider'])) {
|
||||
$defaultProvider = $this->getUserProviderId($firewall['provider']);
|
||||
if (!in_array($defaultProvider, $providerIds, true)) {
|
||||
if (!isset($providerIds[$normalizedName = str_replace('-', '_', $firewall['provider'])])) {
|
||||
throw new InvalidConfigurationException(sprintf('Invalid firewall "%s": user provider "%s" not found.', $id, $firewall['provider']));
|
||||
}
|
||||
$defaultProvider = $providerIds[$normalizedName];
|
||||
} else {
|
||||
$defaultProvider = reset($providerIds);
|
||||
}
|
||||
@ -491,10 +491,10 @@ class SecurityExtension extends Extension
|
||||
|
||||
if (isset($firewall[$key])) {
|
||||
if (isset($firewall[$key]['provider'])) {
|
||||
if (!in_array($firewall[$key]['provider'], $providerIds, true)) {
|
||||
if (!isset($providerIds[$normalizedName = str_replace('-', '_', $firewall[$key]['provider'])])) {
|
||||
throw new InvalidConfigurationException(sprintf('Invalid firewall "%s": user provider "%s" not found.', $id, $firewall[$key]['provider']));
|
||||
}
|
||||
$userProvider = $this->getUserProviderId($firewall[$key]['provider']);
|
||||
$userProvider = $providerIds[$normalizedName];
|
||||
} else {
|
||||
$userProvider = $defaultProvider;
|
||||
}
|
||||
@ -596,7 +596,7 @@ class SecurityExtension extends Extension
|
||||
$providerIds = array();
|
||||
foreach ($config['providers'] as $name => $provider) {
|
||||
$id = $this->createUserDaoProvider($name, $provider, $container);
|
||||
$providerIds[] = $id;
|
||||
$providerIds[str_replace('-', '_', $name)] = $id;
|
||||
}
|
||||
|
||||
return $providerIds;
|
||||
|
@ -405,6 +405,18 @@ abstract class CompleteConfigurationTest extends TestCase
|
||||
$this->getContainer('listener_undefined_provider');
|
||||
}
|
||||
|
||||
public function testFirewallWithUserProvider()
|
||||
{
|
||||
$this->getContainer('firewall_provider');
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testFirewallListenerWithProvider()
|
||||
{
|
||||
$this->getContainer('listener_provider');
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
protected function getContainer($file)
|
||||
{
|
||||
$file = $file.'.'.$this->getFileExtension();
|
||||
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
$container->loadFromExtension('security', array(
|
||||
'providers' => array(
|
||||
'default' => array(
|
||||
'memory' => $memory = array(
|
||||
'users' => array('foo' => array('password' => 'foo', 'roles' => 'ROLE_USER')),
|
||||
),
|
||||
),
|
||||
'with-dash' => array(
|
||||
'memory' => $memory,
|
||||
),
|
||||
),
|
||||
'firewalls' => array(
|
||||
'main' => array(
|
||||
'provider' => 'default',
|
||||
'form_login' => true,
|
||||
),
|
||||
'other' => array(
|
||||
'provider' => 'with-dash',
|
||||
'form_login' => true,
|
||||
),
|
||||
),
|
||||
));
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
$container->loadFromExtension('security', array(
|
||||
'providers' => array(
|
||||
'default' => array(
|
||||
'memory' => array(
|
||||
'users' => array('foo' => array('password' => 'foo', 'roles' => 'ROLE_USER')),
|
||||
),
|
||||
),
|
||||
),
|
||||
'firewalls' => array(
|
||||
'main' => array(
|
||||
'form_login' => array('provider' => 'default'),
|
||||
),
|
||||
),
|
||||
));
|
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:sec="http://symfony.com/schema/dic/security"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<sec:config>
|
||||
<sec:providers>
|
||||
<sec:provider name="with-dash" id="foo" />
|
||||
</sec:providers>
|
||||
|
||||
<sec:firewalls>
|
||||
<sec:firewall name="main" provider="with-dash">
|
||||
<sec:form_login />
|
||||
</sec:firewall>
|
||||
</sec:firewalls>
|
||||
</sec:config>
|
||||
|
||||
</container>
|
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:sec="http://symfony.com/schema/dic/security"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<sec:config>
|
||||
<sec:providers>
|
||||
<sec:provider name="default" id="foo" />
|
||||
</sec:providers>
|
||||
|
||||
<sec:firewalls>
|
||||
<sec:firewall name="main">
|
||||
<sec:form_login provider="default" />
|
||||
</sec:firewall>
|
||||
</sec:firewalls>
|
||||
</sec:config>
|
||||
|
||||
</container>
|
@ -0,0 +1,16 @@
|
||||
security:
|
||||
providers:
|
||||
default:
|
||||
memory:
|
||||
users: { foo: { password: foo, roles: ROLE_USER } }
|
||||
with-dash:
|
||||
memory:
|
||||
users: { foo: { password: foo, roles: ROLE_USER } }
|
||||
|
||||
firewalls:
|
||||
main:
|
||||
provider: default
|
||||
form_login: true
|
||||
other:
|
||||
provider: with-dash
|
||||
form_login: true
|
@ -0,0 +1,10 @@
|
||||
security:
|
||||
providers:
|
||||
default:
|
||||
memory:
|
||||
users: { foo: { password: foo, roles: ROLE_USER } }
|
||||
|
||||
firewalls:
|
||||
main:
|
||||
form_login:
|
||||
provider: default
|
Reference in New Issue
Block a user