我有类范围的问题.我为这样的类创建了一个ace:
$userIdentity = UserSecurityIdentity::fromAccount($user);
$classIdentity = new ObjectIdentity('some_identifier', 'Class\FQCN');
$acl = $aclProvider->createAcl($classIdentity);
$acl->insertClassAce($userIdentity, MaskBuilder::MASK_CREATE);
$aclProvider->updateAcl($acl);
Run Code Online (Sandbox Code Playgroud)
现在,我正在尝试检查用户的权限.我找到了这种做事方式,没有记录,但是在课堂上给出了预期的结果:
$securityContext->isGranted('CREATE', $classIdentity); // returns true
$securityContext->isGranted('VIEW', $classIdentity); // returns true
$securityContext->isGranted('DELETE', $classIdentity); // returns false
Run Code Online (Sandbox Code Playgroud)
此方法很好地适应"CREATE"权限检查,其中没有可用的对象实例传递给该方法.但是,应该可以检查是否在特定实例的基础上授予了另一个权限:
$entity = new Class\FQCN();
$em->persist($entity);
$em->flush();
$securityContext->isGranted('VIEW', $entity); // returns false
Run Code Online (Sandbox Code Playgroud)
这是测试失败的地方.我希望在类上具有给定权限掩码的用户对该类的每个实例具有相同的权限,如文档中所述("PermissionGrantingStrategy首先检查所有对象范围的ACE,如果没有适用的话,该类-scope ACE将被检查"),但似乎并非如此.