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

api-platform / core / 20847864477

09 Jan 2026 09:47AM UTC coverage: 29.1% (+0.005%) from 29.095%
20847864477

Pull #7649

github

web-flow
Merge b342dd5db into d640d106b
Pull Request #7649: feat(validator): uuid/ulid parameter validation

0 of 4 new or added lines in 1 file covered. (0.0%)

15050 existing lines in 491 files now uncovered.

16996 of 58406 relevant lines covered (29.1%)

81.8 hits per line

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

97.37
/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\Exception\RuntimeException;
17
use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;
18
use ApiPlatform\Metadata\GraphQl\QueryCollection;
19
use ApiPlatform\Metadata\HttpOperation;
20
use ApiPlatform\Metadata\Operation;
21
use ApiPlatform\Metadata\ResourceAccessCheckerInterface;
22
use ApiPlatform\State\ProviderInterface;
23
use ApiPlatform\Symfony\Security\Exception\AccessDeniedException;
24
use ApiPlatform\Symfony\Security\ObjectVariableCheckerInterface;
25
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
26

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

39
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
40
    {
UNCOV
41
        switch ($this->event) {
2,310✔
UNCOV
42
            case 'post_denormalize':
2,310✔
UNCOV
43
                $isGranted = $operation->getSecurityPostDenormalize();
1,951✔
UNCOV
44
                $message = $operation->getSecurityPostDenormalizeMessage();
1,951✔
UNCOV
45
                break;
1,951✔
UNCOV
46
            case 'post_validate':
2,308✔
UNCOV
47
                $isGranted = $operation->getSecurityPostValidation();
2,266✔
UNCOV
48
                $message = $operation->getSecurityPostValidationMessage();
2,266✔
UNCOV
49
                break;
2,266✔
UNCOV
50
            case 'after_resolver':
2,306✔
UNCOV
51
                if (!$operation instanceof GraphQlOperation) {
261✔
52
                    throw new RuntimeException('Not a graphql operation');
×
53
                }
54

UNCOV
55
                $isGranted = $operation->getSecurityAfterResolver();
261✔
UNCOV
56
                $message = $operation->getSecurityMessageAfterResolver();
261✔
UNCOV
57
                break;
261✔
58
            default:
UNCOV
59
                $isGranted = $operation->getSecurity();
2,306✔
UNCOV
60
                $message = $operation->getSecurityMessage();
2,306✔
61
        }
62

63
        if (
UNCOV
64
            null === $isGranted
2,310✔
65
            // On a GraphQl QueryCollection we want to perform security stage only on the top-level query
UNCOV
66
            || ($operation instanceof QueryCollection && null !== ($context['source'] ?? null))
2,310✔
67
        ) {
UNCOV
68
            return $this->decorated->provide($operation, $uriVariables, $context);
2,298✔
69
        }
70

UNCOV
71
        $body = 'pre_read' === $this->event ? null : $this->decorated->provide($operation, $uriVariables, $context);
155✔
72

UNCOV
73
        if ($operation instanceof HttpOperation) {
155✔
UNCOV
74
            $request = $context['request'] ?? null;
85✔
75

UNCOV
76
            $resourceAccessCheckerContext = [
85✔
UNCOV
77
                'object' => $body,
85✔
UNCOV
78
                'previous_object' => $request?->attributes->get('previous_data'),
85✔
UNCOV
79
                'request' => $request,
85✔
UNCOV
80
            ];
85✔
81
        } else {
UNCOV
82
            $resourceAccessCheckerContext = [
70✔
UNCOV
83
                'object' => $body,
70✔
UNCOV
84
                'previous_object' => $context['graphql_context']['previous_object'] ?? null,
70✔
UNCOV
85
            ];
70✔
86
        }
87

UNCOV
88
        if ('pre_read' === $this->event && $this->resourceAccessChecker instanceof ObjectVariableCheckerInterface && $this->resourceAccessChecker->usesObjectVariable($isGranted, $resourceAccessCheckerContext)) {
155✔
89
            return $this->decorated->provide($operation, $uriVariables, $context);
14✔
90
        }
91

UNCOV
92
        if (!$this->resourceAccessChecker->isGranted($operation->getClass(), $isGranted, $resourceAccessCheckerContext)) {
155✔
UNCOV
93
            $operation instanceof GraphQlOperation ? throw new AccessDeniedHttpException($message ?? 'Access Denied.') : throw new AccessDeniedException($message ?? 'Access Denied.');
56✔
94
        }
95

UNCOV
96
        return 'pre_read' === $this->event ? $this->decorated->provide($operation, $uriVariables, $context) : $body;
103✔
97
    }
98
}
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