Skip to content

fix(symfony): securityPostValidation when use_symfony_listeners #6479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
*
* 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;
}
Loading