Skip to content

Commit c3e2e5b

Browse files
authored
fix(symfony): securityPostValidation when use_symfony_listeners (#6479)
closes #6446
1 parent 71dbfb1 commit c3e2e5b

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

features/authorization/deny.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,15 @@ Feature: Authorization checking
305305
Then the response status code should be 200
306306
And the response should contain "ownerOnlyProperty"
307307
And the response should contain "attributeBasedProperty"
308+
309+
Scenario: Security post validation should be hit
310+
When I add "Content-Type" header equal to "application/ld+json"
311+
And I add "Authorization" header equal to "Basic ZHVuZ2xhczprZXZpbg=="
312+
And I send a "POST" request to "/issue_6446" with body:
313+
"""
314+
{
315+
"title": ""
316+
}
317+
"""
318+
Then the response status code should be 403
319+

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ private function registerSecurityConfiguration(ContainerBuilder $container, arra
958958

959959
$loader->load('state/security.xml');
960960

961-
if (interface_exists(ValidatorInterface::class) && !$config['use_symfony_listeners']) {
961+
if (interface_exists(ValidatorInterface::class)) {
962962
$loader->load('state/security_validator.xml');
963963
}
964964

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
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\ApiResource\Issue6446;
15+
16+
use ApiPlatform\Metadata\Post;
17+
use Symfony\Component\Validator\Constraints\NotNull;
18+
19+
#[Post(uriTemplate: 'issue_6446', securityPostValidation: 'is_granted(\'ROLE_ADMIN\')')]
20+
class SecurityPostValidation
21+
{
22+
#[NotNull]
23+
public string $title;
24+
}

0 commit comments

Comments
 (0)