Skip to content

Commit 42c5c3e

Browse files
fix(symfony): query parameter validation after authentication (#5473)
1 parent cfdc9ad commit 42c5c3e

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Feature: Authorization checking
2+
In order to use the API
3+
I need to be authorized to access a given resource.
4+
5+
@!mongodb
6+
@createSchema
7+
Scenario: An anonymous user retrieves a secured resource
8+
When I add "Accept" header equal to "application/ld+json"
9+
When I am on "/secured_dummy_with_filters?required=&required-allow-empty=&arrayRequired[foo]="
10+
Then the response status code should be 401
11+

src/Symfony/Bundle/Resources/config/symfony/validator.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory" />
2828
<argument>%api_platform.validator.query_parameter_validation%</argument>
2929

30-
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="16" />
30+
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="2" />
3131
</service>
3232
</services>
3333

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity;
15+
16+
use ApiPlatform\Metadata\ApiResource;
17+
use ApiPlatform\Tests\Fixtures\TestBundle\Filter\ArrayRequiredFilter;
18+
use Doctrine\ORM\Mapping as ORM;
19+
20+
/**
21+
* Secured resource.
22+
*
23+
* @author Kévin Dunglas <dunglas@gmail.com>
24+
*/
25+
#[ApiResource(
26+
security: 'is_granted(\'ROLE_USER\')',
27+
filters: [ArrayRequiredFilter::class],
28+
)]
29+
#[ORM\Entity]
30+
class SecuredDummyWithFilter
31+
{
32+
#[ORM\Column(type: 'integer')]
33+
#[ORM\Id]
34+
#[ORM\GeneratedValue(strategy: 'AUTO')]
35+
private ?int $id = null;
36+
37+
public function getId(): ?int
38+
{
39+
return $this->id;
40+
}
41+
}

0 commit comments

Comments
 (0)