Php Symfony2 ACL-isgrated始终返回false
我已经花了几个小时试图使Symfony的ACL在我的项目中工作,但我根本无法找到解决方案。这是我的测试示例:Php Symfony2 ACL-isgrated始终返回false,php,symfony,acl,Php,Symfony,Acl,我已经花了几个小时试图使Symfony的ACL在我的项目中工作,但我根本无法找到解决方案。这是我的测试示例: $competition = $this->getDoctrine()->getManager() ->getRepository('MyBundle:Competition')->find(158); $objectIdentity = ObjectIdentity::fromDomainObject($competition); $aclProvid
$competition = $this->getDoctrine()->getManager()
->getRepository('MyBundle:Competition')->find(158);
$objectIdentity = ObjectIdentity::fromDomainObject($competition);
$aclProvider = $this->get('security.acl.provider');
try {
$acl = $aclProvider->findAcl($objectIdentity);
} catch (\Symfony\Component\Security\Acl\Exception\AclNotFoundException $e) {
$acl = $aclProvider->createAcl($objectIdentity);
}
// retrieving the security identity of the currently logged-in user
$securityIdentity = UserSecurityIdentity::fromAccount(
$this->get('security.context')->getToken()->getUser());
// grant owner access
$acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_EDIT);
$aclProvider->updateAcl($acl);
我可以看到数据显示在表中,但isgrated
始终返回false。知道我做错了什么吗
acl_类:
id class_type
2 Me\MyBundle\Entity\Competition
id class_id object_identity_id security_identity_id field_name ace_order mask granting granting_strategy audit_success audit_failure
1 2 3 2 NULL 0 4 1 all 0 0
id parent_object_identity_id class_id object_identifier entries_inheriting
3 NULL 2 158 1
object_identity_id ancestor_id
3 3
id identifier username
2 Me\MyBundle\Entity\User-Me 1
acl\u条目:
id class_type
2 Me\MyBundle\Entity\Competition
id class_id object_identity_id security_identity_id field_name ace_order mask granting granting_strategy audit_success audit_failure
1 2 3 2 NULL 0 4 1 all 0 0
id parent_object_identity_id class_id object_identifier entries_inheriting
3 NULL 2 158 1
object_identity_id ancestor_id
3 3
id identifier username
2 Me\MyBundle\Entity\User-Me 1
acl\u对象\u标识:
id class_type
2 Me\MyBundle\Entity\Competition
id class_id object_identity_id security_identity_id field_name ace_order mask granting granting_strategy audit_success audit_failure
1 2 3 2 NULL 0 4 1 all 0 0
id parent_object_identity_id class_id object_identifier entries_inheriting
3 NULL 2 158 1
object_identity_id ancestor_id
3 3
id identifier username
2 Me\MyBundle\Entity\User-Me 1
acl\u对象\u标识\u祖先:
id class_type
2 Me\MyBundle\Entity\Competition
id class_id object_identity_id security_identity_id field_name ace_order mask granting granting_strategy audit_success audit_failure
1 2 3 2 NULL 0 4 1 all 0 0
id parent_object_identity_id class_id object_identifier entries_inheriting
3 NULL 2 158 1
object_identity_id ancestor_id
3 3
id identifier username
2 Me\MyBundle\Entity\User-Me 1
acl\u安全\u身份:
id class_type
2 Me\MyBundle\Entity\Competition
id class_id object_identity_id security_identity_id field_name ace_order mask granting granting_strategy audit_success audit_failure
1 2 3 2 NULL 0 4 1 all 0 0
id parent_object_identity_id class_id object_identifier entries_inheriting
3 NULL 2 158 1
object_identity_id ancestor_id
3 3
id identifier username
2 Me\MyBundle\Entity\User-Me 1
我在实现ObjectIdentityInterface的实体中遇到了相同的问题 我的getType实现是:
public function getType() {
return __CLASS__;
}
这将返回声明它的类的名称(静态),并且在比较中失败
所以我把它改成了DINAMICALL:
public function getType() {
return get_class($this);
}
希望有帮助你能试着通过
'EDIT'
而不是MaskBuilder::MASK\u EDIT
?我的意思是$this->get('security.context')->被授予('EDIT',$competition')代码>