You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -42,21 +45,15 @@ public function onKernelControllerArguments(ControllerArgumentsEvent $event)
42
45
$arguments = $event->getNamedArguments();
43
46
44
47
foreach ($attributesas$attribute) {
45
-
$subjectRef = $attribute->subject;
46
48
$subject = null;
47
49
48
-
if ($subjectRef) {
50
+
if ($subjectRef = $attribute->subject) {
49
51
if (\is_array($subjectRef)) {
50
-
foreach ($subjectRefas$ref) {
51
-
if (!\array_key_exists($ref, $arguments)) {
52
-
thrownewRuntimeException(sprintf('Could not find the subject "%s" for the #[IsGranted] attribute. Try adding a "$%s" argument to your controller method.', $ref, $ref));
thrownewRuntimeException(sprintf('Could not find the subject "%s" for the #[IsGranted] attribute. Try adding a "$%s" argument to your controller method.', $subjectRef, $subjectRef));
if (!\array_key_exists($subjectRef, $arguments)) {
92
+
thrownewRuntimeException(sprintf('Could not find the subject "%s" for the #[IsGranted] attribute. Try adding a "$%s" argument to your controller method.', $subjectRef, $subjectRef));
@@ -249,7 +253,11 @@ public function getAccessDeniedMessageTests()
249
253
{
250
254
yield [['ROLE_ADMIN'], null, 'admin', 'Access Denied by #[IsGranted("ROLE_ADMIN")] on controller'];
251
255
yield [['ROLE_ADMIN', 'ROLE_USER'], null, 'adminOrUser', 'Access Denied by #[IsGranted(["ROLE_ADMIN", "ROLE_USER"])] on controller'];
252
-
yield [['ROLE_ADMIN', 'ROLE_USER'], 'product', 'adminOrUserWithSubject', 'Access Denied by #[IsGranted(["ROLE_ADMIN", "ROLE_USER"], "product")] on controller'];
256
+
yield [['ROLE_ADMIN', 'ROLE_USER'], 'bar', 'adminOrUserWithSubject', 'Access Denied by #[IsGranted(["ROLE_ADMIN", "ROLE_USER"], "product")] on controller'];
257
+
yield [['ROLE_ADMIN'], ['arg1Name' => 'bar', 'arg2Name' => 'bar'], 'withSubjectArray', 'Access Denied by #[IsGranted("ROLE_ADMIN", ["arg1Name", "arg2Name"])] on controller'];
258
+
yield [[newExpression('"ROLE_ADMIN" in role_names or is_granted("POST_VIEW", subject)')], 'bar', 'withExpressionInAttribute', 'Access Denied by #[IsGranted(new Expression(""ROLE_ADMIN" in role_names or is_granted("POST_VIEW", subject)"), "post")] on controller'];
259
+
yield [[newExpression('user === subject')], 'bar', 'withExpressionInSubject', 'Access Denied by #[IsGranted(new Expression("user === subject"), new Expression("args["post"].getAuthor()"))] on controller'];
260
+
yield [[newExpression('user === subject["author"]')], ['author' => 'bar', 'alias' => 'bar'], 'withNestedExpressionInSubject', 'Access Denied by #[IsGranted(new Expression("user === subject["author"]"), ["author" => new Expression("args["post"].getAuthor()"), "alias" => "arg2Name"])] on controller'];
253
261
}
254
262
255
263
publicfunctiontestNotFoundHttpException()
@@ -273,4 +281,80 @@ public function testNotFoundHttpException()
0 commit comments