[SecurityBundle] Convert Http method to uppercase in the config
This commit is contained in:
parent
cb00411fc8
commit
32dc31eceb
@ -177,7 +177,7 @@ class SecurityExtension extends Extension
|
||||
$container,
|
||||
$access['path'],
|
||||
$access['host'],
|
||||
count($access['methods']) === 0 ? null : $access['methods'],
|
||||
$access['methods'],
|
||||
$access['ip']
|
||||
);
|
||||
|
||||
@ -536,7 +536,7 @@ class SecurityExtension extends Extension
|
||||
return $switchUserListenerId;
|
||||
}
|
||||
|
||||
private function createRequestMatcher($container, $path = null, $host = null, $methods = null, $ip = null, array $attributes = array())
|
||||
private function createRequestMatcher($container, $path = null, $host = null, $methods = array(), $ip = null, array $attributes = array())
|
||||
{
|
||||
$serialized = serialize(array($path, $host, $methods, $ip, $attributes));
|
||||
$id = 'security.request_matcher.'.md5($serialized).sha1($serialized);
|
||||
@ -545,6 +545,10 @@ class SecurityExtension extends Extension
|
||||
return $this->requestMatchers[$id];
|
||||
}
|
||||
|
||||
if ($methods) {
|
||||
$methods = array_map('strtoupper', (array) $methods);
|
||||
}
|
||||
|
||||
// only add arguments that are necessary
|
||||
$arguments = array($path, $host, $methods, $ip, $attributes);
|
||||
while (count($arguments) > 0 && !end($arguments)) {
|
||||
|
@ -58,7 +58,7 @@ $container->loadFromExtension('security', array(
|
||||
),
|
||||
|
||||
'access_control' => array(
|
||||
array('path' => '/blog/524', 'role' => 'ROLE_USER', 'requires_channel' => 'https'),
|
||||
array('path' => '/blog/524', 'role' => 'ROLE_USER', 'requires_channel' => 'https', 'methods' => array('get', 'POST')),
|
||||
array('path' => '/blog/.*', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY'),
|
||||
),
|
||||
|
||||
|
@ -53,7 +53,7 @@
|
||||
<role id="ROLE_SUPER_ADMIN">ROLE_USER,ROLE_ADMIN,ROLE_ALLOWED_TO_SWITCH</role>
|
||||
<role id="ROLE_REMOTE">ROLE_USER,ROLE_ADMIN</role>
|
||||
|
||||
<rule path="/blog/524" role="ROLE_USER" requires-channel="https" />
|
||||
<rule path="/blog/524" role="ROLE_USER" requires-channel="https" methods="get,POST" />
|
||||
<rule role='IS_AUTHENTICATED_ANONYMOUSLY' path="/blog/.*" />
|
||||
</config>
|
||||
</srv:container>
|
||||
|
@ -49,7 +49,7 @@ security:
|
||||
ROLE_REMOTE: ROLE_USER,ROLE_ADMIN
|
||||
|
||||
access_control:
|
||||
- { path: /blog/524, role: ROLE_USER, requires_channel: https }
|
||||
- { path: /blog/524, role: ROLE_USER, requires_channel: https, methods: [get, POST]}
|
||||
-
|
||||
path: /blog/.*
|
||||
role: IS_AUTHENTICATED_ANONYMOUSLY
|
||||
|
@ -104,6 +104,7 @@ abstract class SecurityExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
$matcherIds = array();
|
||||
foreach ($rules as $rule) {
|
||||
list($matcherId, $roles, $channel) = $rule;
|
||||
$requestMatcher = $container->getDefinition($matcherId);
|
||||
|
||||
$this->assertFalse(isset($matcherIds[$matcherId]));
|
||||
$matcherIds[$matcherId] = true;
|
||||
@ -112,9 +113,17 @@ abstract class SecurityExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
if (1 === $i) {
|
||||
$this->assertEquals(array('ROLE_USER'), $roles);
|
||||
$this->assertEquals('https', $channel);
|
||||
$this->assertEquals(
|
||||
array('/blog/524', null, array('GET', 'POST')),
|
||||
$requestMatcher->getArguments()
|
||||
);
|
||||
} elseif (2 === $i) {
|
||||
$this->assertEquals(array('IS_AUTHENTICATED_ANONYMOUSLY'), $roles);
|
||||
$this->assertNull($channel);
|
||||
$this->assertEquals(
|
||||
array('/blog/.*'),
|
||||
$requestMatcher->getArguments()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user