访问控制security.yml中的表达式语言不用于路由

时间:2017-10-24 08:27:46

标签: symfony symfony-security

我在访问控制中使用参数时遇到问题(symfony 3.3。)*:

-
    path: ^/api
    allow_if: "has_role('ROLE_API_USER') or request.getHost() in '%internal_host%'"

堆栈跟踪错误

A string value must be composed of strings and/or numbers, but found parameter "internal_host" of type array inside string value "has_role('ROLE_API_USER') or request.getHost() in '%internal_host%'"

我尝试了其他方式,例如request.getHost() in parameter('internal_host')request.getHost() in container.getParameter('internal_host')但我有错误消息,例如The function "parameter" does not exist around position 51 for expression has_role('ROLE_API_USER') or request.getHost() in parameter('internal_host').(与容器服务相同的消息)。

如何使用表达式语言在访问控制中使用参数?

1 个答案:

答案 0 :(得分:-1)

如果您使用Symfony 3,您可以尝试:

-
    path: ^/api
    allow_if: "has_role('ROLE_API_USER') or request.getHost() in ['%internal_host%']"

cf Access global parameters from route condition expressions in Symfony