Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8f2c52a

Browse filesBrowse files
committed
minor #47959 [SecurityBundle] Add XML support for new request attribute matcher (wouterj)
This PR was merged into the 6.2 branch. Discussion ---------- [SecurityBundle] Add XML support for new request attribute matcher | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - This adds support for the XML format to the new attribute request matching options (ref #45907). Commits ------- aa64204 [SecurityBundle] Add XML support for new request attribute matcher
2 parents f0f04cf + aa64204 commit 8f2c52a
Copy full SHA for 8f2c52a

File tree

Expand file treeCollapse file tree

6 files changed

+25
-0
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+25
-0
lines changed

‎src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ private function addAccessControlSection(ArrayNodeDefinition $rootNode)
133133
->prototype('array')
134134
->fixXmlConfig('ip')
135135
->fixXmlConfig('method')
136+
->fixXmlConfig('attribute')
136137
->children()
137138
->scalarNode('request_matcher')->defaultNull()->end()
138139
->scalarNode('requires_channel')->defaultNull()->end()
@@ -148,6 +149,7 @@ private function addAccessControlSection(ArrayNodeDefinition $rootNode)
148149
->prototype('scalar')->end()
149150
->end()
150151
->arrayNode('attributes')
152+
->useAttributeAsKey('key')
151153
->prototype('scalar')->end()
152154
->end()
153155
->scalarNode('route')->defaultNull()->end()

‎src/Symfony/Bundle/SecurityBundle/Resources/config/schema/security-1.0.xsd

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Resources/config/schema/security-1.0.xsd
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@
378378
<xsd:element name="method" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
379379
<xsd:element name="role" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
380380
<xsd:element name="allow-if" type="xsd:string" minOccurs="0" maxOccurs="1" />
381+
<xsd:element name="attribute" type="rule_attribute" minOccurs="0" maxOccurs="1" />
381382
</xsd:choice>
382383
<xsd:attribute name="requires-channel" type="xsd:string" />
383384
<xsd:attribute name="path" type="xsd:string" />
@@ -386,6 +387,7 @@
386387
<xsd:attribute name="role" type="xsd:string" />
387388
<xsd:attribute name="methods" type="xsd:string" />
388389
<xsd:attribute name="allow-if" type="xsd:string" />
390+
<xsd:attribute name="route" type="xsd:string" />
389391
</xsd:complexType>
390392

391393
<xsd:complexType name="role">
@@ -397,4 +399,12 @@
397399
</xsd:simpleContent>
398400
</xsd:complexType>
399401

402+
<xsd:complexType name="rule_attribute">
403+
<xsd:simpleContent>
404+
<xsd:extension base="xsd:string">
405+
<xsd:attribute name="key" type="xsd:string" use="required" />
406+
</xsd:extension>
407+
</xsd:simpleContent>
408+
</xsd:complexType>
409+
400410
</xsd:schema>

‎src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
2020
use Symfony\Component\DependencyInjection\Definition;
2121
use Symfony\Component\DependencyInjection\Reference;
22+
use Symfony\Component\HttpFoundation\RequestMatcher\AttributesRequestMatcher;
2223
use Symfony\Component\HttpFoundation\RequestMatcher\HostRequestMatcher;
2324
use Symfony\Component\HttpFoundation\RequestMatcher\MethodRequestMatcher;
2425
use Symfony\Component\HttpFoundation\RequestMatcher\PathRequestMatcher;
@@ -326,8 +327,15 @@ public function testAccess()
326327
$this->assertEquals('IS_AUTHENTICATED_ANONYMOUSLY', $attributes[0]);
327328
$expression = $container->getDefinition((string) $attributes[1])->getArgument(0);
328329
$this->assertEquals("token.getUserIdentifier() matches '/^admin/'", $expression);
330+
} elseif (4 === $i) {
331+
$this->assertEquals(['ROLE_ADMIN'], $attributes);
332+
$def = $container->getDefinition((string) $requestMatcher->getArgument(0)[0]);
333+
$this->assertSame(AttributesRequestMatcher::class, $def->getClass());
334+
$this->assertSame(['_controller' => 'AdminController::index', '_route' => 'admin'], $def->getArgument(0));
329335
}
330336
}
337+
338+
$this->assertCount(4, $matcherIds);
331339
}
332340

333341
public function testMerge()

‎src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
['path' => '/blog/524', 'role' => 'ROLE_USER', 'requires_channel' => 'https', 'methods' => ['get', 'POST'], 'port' => 8000],
9797
['path' => '/blog/.*', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY'],
9898
['path' => '/blog/524', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY', 'allow_if' => "token.getUserIdentifier() matches '/^admin/'"],
99+
['role' => 'ROLE_ADMIN', 'attributes' => ['_controller' => 'AdminController::index'], 'route' => 'admin'],
99100
],
100101

101102
'role_hierarchy' => [

‎src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,8 @@
7676
<rule path="/blog/524" role="ROLE_USER" requires-channel="https" methods="get,POST" port="8000" />
7777
<rule role='IS_AUTHENTICATED_ANONYMOUSLY' path="/blog/.*" />
7878
<rule role='IS_AUTHENTICATED_ANONYMOUSLY' allow-if="token.getUserIdentifier() matches '/^admin/'" path="/blog/524" />
79+
<rule role="ROLE_ADMIN" route="admin">
80+
<attribute key="_controller">AdminController::index</attribute>
81+
</rule>
7982
</config>
8083
</srv:container>

‎src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,4 @@ security:
8383
path: /blog/.*
8484
role: IS_AUTHENTICATED_ANONYMOUSLY
8585
- { path: /blog/524, role: IS_AUTHENTICATED_ANONYMOUSLY, allow_if: "token.getUserIdentifier() matches '/^admin/'" }
86+
- { role: ROLE_ADMIN, attributes: { _controller: 'AdminController::index' }, route: 'admin' }

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.