How to use the AccessDecisionManager in Symfony2 for authorization of arbitrary users?

后端 未结 7 1899
庸人自扰
庸人自扰 2020-12-14 21:14

I\'d like to be able to verify whether or not attributes (roles) are granted to any arbitrary object implementing UserInterface in Symfony2. Is this possible?

7条回答
  •  臣服心动
    2020-12-14 22:06

    You can use the security.context service with the isGranted method.

    You can pass a second argument which is your object (see here).

    In a controller:

    $this->get('security.context')->isGranted('ROLE_FOOBAR', $myUser)
    

提交回复
热议问题