Skip to content

Commit

Permalink
fix(symfony): query parameter validation after authentication (#5473)
Browse files Browse the repository at this point in the history
  • Loading branch information
nawel-les-tilleuls authored Mar 19, 2023
1 parent cfdc9ad commit 42c5c3e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
11 changes: 11 additions & 0 deletions features/authorization/deny_authentication_before_filter.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Authorization checking
In order to use the API
I need to be authorized to access a given resource.

@!mongodb
@createSchema
Scenario: An anonymous user retrieves a secured resource
When I add "Accept" header equal to "application/ld+json"
When I am on "/secured_dummy_with_filters?required=&required-allow-empty=&arrayRequired[foo]="
Then the response status code should be 401

2 changes: 1 addition & 1 deletion src/Symfony/Bundle/Resources/config/symfony/validator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory" />
<argument>%api_platform.validator.query_parameter_validation%</argument>

<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="16" />
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="2" />
</service>
</services>

Expand Down
41 changes: 41 additions & 0 deletions tests/Fixtures/TestBundle/Entity/SecuredDummyWithFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Tests\Fixtures\TestBundle\Filter\ArrayRequiredFilter;
use Doctrine\ORM\Mapping as ORM;

/**
* Secured resource.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
#[ApiResource(
security: 'is_granted(\'ROLE_USER\')',
filters: [ArrayRequiredFilter::class],
)]
#[ORM\Entity]
class SecuredDummyWithFilter
{
#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id = null;

public function getId(): ?int
{
return $this->id;
}
}

0 comments on commit 42c5c3e

Please sign in to comment.