schmittjoh/JMSSecurityExtraBundle — Issue #25: ExpressionVoter continues because attribute is not instanceof Expression
Author: jonathaningram
Created: 2011-12-01 02:01:05+00:00
State: open

Hi!

I've got this call in my controller since I am unable to use annotations at this stage due to the use of FOSRestBundle overriding my templating.

```php
get('security.context')->isGranted(new Expression('hasRole("ROLE_SUPERUSER")'))) {
throw new AccessDeniedException('Token does not have the required roles.');
}
```

Note: this is meant to be a full expression:

`hasPermission(company, "MASTER") or hasRole("ROLE_SUPERUSER")`

However, I am simplifying if for this issue.

Now, debugging this, the security context converts the expression to an array:

```php
accessDecisionManager->decide($this->token, (array) $attributes, $object);
```

And the `ExpressionVoter` receives an array for `$attributes`, and so does not vote:

```php
evaluators[$attribute->expression])) {
$this->evaluators[$attribute->expression] =
$this->createEvaluator($attribute);
}

if (call_user_func($this->evaluators[$attribute->expression],
$this->expressionHandler->createContext($token, $object))) {
return VoterInterface::ACCESS_GRANTED;
}
}

return $result;
}
```

The `$attributes` variable looks like this:

```
array(1) (
[expression] => (string) hasRole("ROLE_SUPERUSER")
)
```