Skip to content

Commit

Permalink
fix(symfony): securityPostValidation when use_symfony_listeners (#6479)
Browse files Browse the repository at this point in the history
closes #6446
  • Loading branch information
soyuka authored Jul 19, 2024
1 parent 71dbfb1 commit c3e2e5b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
12 changes: 12 additions & 0 deletions features/authorization/deny.feature
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,15 @@ Feature: Authorization checking
Then the response status code should be 200
And the response should contain "ownerOnlyProperty"
And the response should contain "attributeBasedProperty"

Scenario: Security post validation should be hit
When I add "Content-Type" header equal to "application/ld+json"
And I add "Authorization" header equal to "Basic ZHVuZ2xhczprZXZpbg=="
And I send a "POST" request to "/issue_6446" with body:
"""
{
"title": ""
}
"""
Then the response status code should be 403

Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ private function registerSecurityConfiguration(ContainerBuilder $container, arra

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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\ApiResource\Issue6446;

use ApiPlatform\Metadata\Post;
use Symfony\Component\Validator\Constraints\NotNull;

#[Post(uriTemplate: 'issue_6446', securityPostValidation: 'is_granted(\'ROLE_ADMIN\')')]
class SecurityPostValidation
{
#[NotNull]
public string $title;
}

0 comments on commit c3e2e5b

Please sign in to comment.