16
16
use ApiPlatform \Metadata \GraphQl \Operation as GraphQlOperation ;
17
17
use ApiPlatform \Metadata \Operation ;
18
18
use ApiPlatform \Metadata \ResourceAccessCheckerInterface ;
19
+ use ApiPlatform \State \ParameterNotFound ;
19
20
use ApiPlatform \State \ProviderInterface ;
20
21
use ApiPlatform \State \Util \ParameterParserTrait ;
21
22
use ApiPlatform \Symfony \Security \Exception \AccessDeniedException ;
22
- use Symfony \Component \HttpFoundation \Request ;
23
23
use Symfony \Component \HttpKernel \Exception \AccessDeniedHttpException ;
24
24
25
25
/**
@@ -30,36 +30,31 @@ final class SecurityParameterProvider implements ProviderInterface
30
30
{
31
31
use ParameterParserTrait;
32
32
33
- public function __construct (private readonly ? ProviderInterface $ decorated = null , private readonly ?ResourceAccessCheckerInterface $ resourceAccessChecker = null )
33
+ public function __construct (private readonly ProviderInterface $ decorated , private readonly ?ResourceAccessCheckerInterface $ resourceAccessChecker = null )
34
34
{
35
35
}
36
36
37
37
public function provide (Operation $ operation , array $ uriVariables = [], array $ context = []): object |array |null
38
38
{
39
- if (!($ request = $ context ['request ' ]) instanceof Request) {
40
- return $ this ->decorated ->provide ($ operation , $ uriVariables , $ context );
41
- }
42
-
43
- /** @var Operation $apiOperation */
44
- $ apiOperation = $ request ->attributes ->get ('_api_operation ' );
39
+ $ body = $ this ->decorated ->provide ($ operation , $ uriVariables , $ context );
40
+ $ request = $ context ['request ' ] ?? null ;
45
41
46
- foreach ($ apiOperation ->getParameters () ?? [] as $ parameter ) {
42
+ $ operation = $ request ?->attributes->get ('_api_operation ' ) ?? $ operation ;
43
+ foreach ($ operation ->getParameters () ?? [] as $ parameter ) {
47
44
if (null === $ security = $ parameter ->getSecurity ()) {
48
45
continue ;
49
46
}
50
47
51
- $ key = $ this ->getParameterFlattenKey ($ parameter ->getKey (), $ this ->extractParameterValues ($ parameter , $ request , $ context ));
52
- $ apiValues = $ parameter ->getExtraProperties ()['_api_values ' ] ?? [];
53
- if (!isset ($ apiValues [$ key ])) {
48
+ if (($ v = $ parameter ->getValue ()) instanceof ParameterNotFound) {
54
49
continue ;
55
50
}
56
- $ value = $ apiValues [$ key ];
57
51
58
- if (!$ this ->resourceAccessChecker ->isGranted ($ context ['resource_class ' ], $ security , [$ key => $ value ])) {
52
+ $ securityContext = [$ parameter ->getKey () => $ v , 'object ' => $ body ];
53
+ if (!$ this ->resourceAccessChecker ->isGranted ($ context ['resource_class ' ], $ security , $ securityContext )) {
59
54
throw $ operation instanceof GraphQlOperation ? new AccessDeniedHttpException ($ parameter ->getSecurityMessage () ?? 'Access Denied. ' ) : new AccessDeniedException ($ parameter ->getSecurityMessage () ?? 'Access Denied. ' );
60
55
}
61
56
}
62
57
63
- return $ this -> decorated -> provide ( $ operation , $ uriVariables , $ context ) ;
58
+ return $ body ;
64
59
}
65
60
}
0 commit comments