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

api-platform / core / 20822307873

08 Jan 2026 03:35PM UTC coverage: 21.258% (-7.6%) from 28.879%
20822307873

Pull #7658

github

web-flow
Merge 7e9d13d39 into 550b7621d
Pull Request #7658: fix(openapi): properly document list parameters

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

14467 existing lines in 472 files now uncovered.

12215 of 57461 relevant lines covered (21.26%)

49.28 hits per line

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

85.71
/src/Symfony/Security/ResourceAccessChecker.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;
15

16
use ApiPlatform\Metadata\ResourceAccessCheckerInterface;
17
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
18
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
19
use Symfony\Component\Security\Core\Authentication\Token\NullToken;
20
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
21
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
22
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
23
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
24

25
/**
26
 * Checks if the logged user has sufficient permissions to access the given resource.
27
 *
28
 * @author Kévin Dunglas <dunglas@gmail.com>
29
 */
30
final class ResourceAccessChecker implements ResourceAccessCheckerInterface
31
{
32
    public function __construct(private readonly ?ExpressionLanguage $expressionLanguage = null, private readonly ?AuthenticationTrustResolverInterface $authenticationTrustResolver = null, private readonly ?RoleHierarchyInterface $roleHierarchy = null, private readonly ?TokenStorageInterface $tokenStorage = null, private readonly ?AuthorizationCheckerInterface $authorizationChecker = null)
33
    {
UNCOV
34
    }
1,529✔
35

36
    public function isGranted(string $resourceClass, string $expression, array $extraVariables = []): bool
37
    {
UNCOV
38
        if (null === $this->tokenStorage || null === $this->authenticationTrustResolver) {
136✔
UNCOV
39
            throw new \LogicException('The "symfony/security" library must be installed to use the "security" attribute.');
×
40
        }
41

UNCOV
42
        if (null === $this->expressionLanguage) {
136✔
UNCOV
43
            throw new \LogicException('The "symfony/expression-language" library must be installed to use the "security" attribute.');
×
44
        }
45

UNCOV
46
        $variables = array_merge($extraVariables, [
136✔
UNCOV
47
            'trust_resolver' => $this->authenticationTrustResolver,
136✔
UNCOV
48
            'auth_checker' => $this->authorizationChecker, // needed for the is_granted expression function
136✔
UNCOV
49
        ]);
136✔
50

UNCOV
51
        if (null === $token = $this->tokenStorage->getToken()) {
136✔
UNCOV
52
            $token = new NullToken();
16✔
53
        }
54

UNCOV
55
        $variables = array_merge($variables, $this->getVariables($token));
136✔
56

UNCOV
57
        return (bool) $this->expressionLanguage->evaluate($expression, $variables);
136✔
58
    }
59

60
    /**
61
     * @copyright Fabien Potencier <fabien@symfony.com>
62
     *
63
     * @see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php
64
     */
65
    private function getVariables(TokenInterface $token): array
66
    {
UNCOV
67
        return [
136✔
UNCOV
68
            'token' => $token,
136✔
UNCOV
69
            'user' => $token->getUser(),
136✔
UNCOV
70
            'roles' => $this->getEffectiveRoles($token),
136✔
UNCOV
71
        ];
136✔
72
    }
73

74
    /**
75
     * @return string[]
76
     */
77
    private function getEffectiveRoles(TokenInterface $token): array
78
    {
UNCOV
79
        if (null === $this->roleHierarchy) {
136✔
UNCOV
80
            return $token->getRoleNames();
×
81
        }
82

UNCOV
83
        return $this->roleHierarchy->getReachableRoleNames($token->getRoleNames());
136✔
84
    }
85
}
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