2013-09-05 3 views
0

저는 이미 Symfony의 ACL을 프로젝트에서 작동시키는 데 몇 시간을 보냈지만 단순히 해결책을 찾지 못했습니다. 이것은 나의 테스트 예제이다 :Symfony2 ACL - isGranted는 항상 false를 반환합니다.

$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); 

.

$competition = $this->getDoctrine()->getManager() 
    ->getRepository('MyBundle:Competition')->find(158); 

$foo = $this->get('security.context')->isGranted(MaskBuilder::MASK_EDIT, $competition); 

var_dump($foo); // always bool(false) 

나는 데이터가 테이블에 표시하지만 isGranted는 항상 false를 돌려 볼 수 있습니다. 어떤 생각인지 내가 뭘 잘못 했니?

acl_classes :

id class_type 
2 Me\MyBundle\Entity\Competition 

acl_entries :

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 

acl_object_identities :

id parent_object_identity_id class_id object_identifier entries_inheriting 
3 NULL      2   158     1 

acl_object_identity_ancestors :

object_identity_id ancestor_id 
3     3 

acl_security_identities :

id identifier     username 
2 Me\MyBundle\Entity\User-Me 1 
+0

당신이 할 수있는 도움이되기를 바랍니다 'MaskBuilder :: MASK_EDIT' 대신'EDIT'를 전달하려고합니까? – sergekv

+0

'$ this-> get ('security.context') -> isGranted ('EDIT', $ competition);' – sergekv

답변

0

내가 ObjectIdentityInterface를 구현하는 내 기업에서 동일한 문제가 있었다 ...

getType로 내 구현했다 :

public function getType() { 
     return __CLASS__; 
} 

이가 (정적)으로 선언 된 클래스의 이름을 돌려이었고, 그래서 난에 dinamically을 변경

comparisson에 실패

public function getType() { 
     return get_class($this); 
} 

그것이

관련 문제