Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Security Symfony 2 ACL vs选民_Security_Symfony_Acl_Vote - Fatal编程技术网

Security Symfony 2 ACL vs选民

Security Symfony 2 ACL vs选民,security,symfony,acl,vote,Security,Symfony,Acl,Vote,我想使用isgrated('EDIT',$userObject)允许所有管理员和经理以及该用户编辑给定的用户数据 我应该使用ACL来控制编辑$userObject吗? 我写了额外的投票者,检查登录的用户和给定的对象是否相同,或者用户是经理还是管理员 在acl中,我必须为所有管理员、经理和该用户添加ACE for userObject 推荐哪条路? 我是新来的 以下为投票人代码: function vote(TokenInterface $token, $object, array $attrib

我想使用isgrated('EDIT',$userObject)允许所有管理员和经理以及该用户编辑给定的用户数据

我应该使用ACL来控制编辑$userObject吗? 我写了额外的投票者,检查登录的用户和给定的对象是否相同,或者用户是经理还是管理员

在acl中,我必须为所有管理员、经理和该用户添加ACE for userObject

推荐哪条路? 我是新来的

以下为投票人代码:

function vote(TokenInterface $token, $object, array $attributes)
{
    $intersect=array_intersect(array('EDIT','VIEW' ), $attributes);
    if (!empty($intersect))
    {
        //intersect is not empty, it seems to edit or view are in $attributes
        //voter grants privileges for [user->granted object]
        //manager->every customer, child-manager
        //admin->every customer and manager
        if ($token->getUser()->isAdmin())
        {
            return VoterInterface::ACCESS_GRANTED;
        }
        elseif ($token->getUser()->isCustomer())
        {
            //voter not want to think about customer grants, because customer grants currently are held in ACL
            return VoterInterface::ACCESS_ABSTAIN;
        }
        /* @var $object \PSB\StoreBundle\Entity\Customer */
        if (is_a($object, '\PSB\StoreBundle\Entity\Customer'))
        {

            if ($token->getUser()->isManager())
            {
                //managers also edit customers
                return VoterInterface::ACCESS_GRANTED;
            }
        }
        elseif (is_a($object, '\PSB\StoreBundle\Entity\Manager'))
        {
            /* @var $object \PSB\StoreBundle\Entity\Manager */
            if ($token->getUser()->isManager())
            {
                //manager can edit own children
                if ($token->getUser() == $object->getParent())
                {
                    return VoterInterface::ACCESS_GRANTED;
                }
            }
        }
    }
    return VoterInterface::ACCESS_ABSTAIN;
}

当您的模型已经存储了知道是否应该授予某个操作所需的数据时,让ACL与实际数据保持同步真的很烦人

因此,你显然应该落实你自己的选民


PS:你应该使用
$object instanceof Class
而不是
is_a($object,'Class')
当你的模型已经存储了需要知道是否应该授权某个操作的数据时,让ACL与你的真实数据保持同步真的很烦人

因此,你显然应该落实你自己的选民


PS:您应该使用类的
$object instanceof
而不是
是一个($object,'Class')

谢谢instanceof提示:顺便问一下,我可以用哪种方式传递类作为参数?使用\My\package\Class;——函数获取类参数(类);我知道这是一个古老的答案,但我的天哪,这仍然是一个伟大而相关的答案。谢谢提示的例子:顺便问一下,我用哪种方式通过课堂作为论点?使用\My\package\Class;——函数获取类参数(类);我知道这是一个古老的答案,但天哪,这仍然是一个伟大而相关的答案。