• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 7196499749

13 Dec 2023 02:17PM UTC coverage: 37.359% (+1.4%) from 36.003%
7196499749

push

github

web-flow
ci: conflict sebastian/comparator (#6032)

* ci: conflict sebastian/comparator

* for lowest

10295 of 27557 relevant lines covered (37.36%)

28.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.77
/src/Symfony/Security/State/AccessCheckerProvider.php
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\Symfony\Security\State;
15

16
use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;
17
use ApiPlatform\Metadata\GraphQl\QueryCollection;
18
use ApiPlatform\Metadata\HttpOperation;
19
use ApiPlatform\Metadata\Operation;
20
use ApiPlatform\State\ProviderInterface;
21
use ApiPlatform\Symfony\Security\Exception\AccessDeniedException;
22
use ApiPlatform\Symfony\Security\ResourceAccessCheckerInterface;
23
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
24

25
/**
26
 * Allows access based on the ApiPlatform\Symfony\Security\ResourceAccessCheckerInterface.
27
 * This implementation covers GraphQl and HTTP.
28
 *
29
 * @see ResourceAccessCheckerInterface
30
 */
31
final class AccessCheckerProvider implements ProviderInterface
32
{
33
    public function __construct(private readonly ProviderInterface $decorated, private readonly ResourceAccessCheckerInterface $resourceAccessChecker, private readonly ?string $event = null)
34
    {
35
    }
105✔
36

37
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
38
    {
39
        switch ($this->event) {
105✔
40
            case 'post_denormalize':
105✔
41
                $isGranted = $operation->getSecurityPostDenormalize();
89✔
42
                $message = $operation->getSecurityPostDenormalizeMessage();
89✔
43
                break;
89✔
44
            case 'post_validate':
101✔
45
                $isGranted = $operation->getSecurityPostValidation();
89✔
46
                $message = $operation->getSecurityPostValidationMessage();
89✔
47
                break;
89✔
48
            default:
49
                $isGranted = $operation->getSecurity();
97✔
50
                $message = $operation->getSecurityMessage();
97✔
51
        }
52

53
        $body = $this->decorated->provide($operation, $uriVariables, $context);
105✔
54
        if (null === $isGranted) {
102✔
55
            return $body;
82✔
56
        }
57

58
        // On a GraphQl QueryCollection we want to perform security stage only on the top-level query
59
        if ($operation instanceof QueryCollection && null !== ($context['source'] ?? null)) {
32✔
60
            return $body;
×
61
        }
62

63
        if ($operation instanceof HttpOperation) {
32✔
64
            $request = $context['request'] ?? null;
28✔
65

66
            $resourceAccessCheckerContext = [
28✔
67
                'object' => $body,
28✔
68
                'previous_object' => $request?->attributes->get('previous_data'),
28✔
69
                'request' => $request,
28✔
70
            ];
28✔
71
        } else {
72
            $resourceAccessCheckerContext = [
4✔
73
                'object' => $body,
4✔
74
                'previous_object' => $context['graphql_context']['previous_object'] ?? null,
4✔
75
            ];
4✔
76
        }
77

78
        if (!$this->resourceAccessChecker->isGranted($operation->getClass(), $isGranted, $resourceAccessCheckerContext)) {
32✔
79
            $operation instanceof GraphQlOperation ? throw new AccessDeniedHttpException($message ?? 'Access Denied.') : throw new AccessDeniedException($message ?? 'Access Denied.');
8✔
80
        }
81

82
        return $body;
24✔
83
    }
84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc