2013-01-09 5 views
0

상위 항목을 나열하는 동안 여러 하위 엔티티의 acl 항목을 확인하려고합니다. 현재 설정 한게Symfony2 하위 엔티티에 대한 ACL 확인

:

Gallery (parent) 
    Gallerycategory (child) 
    Gallerylanguage (child) 
  • 모든 사용자 그룹은 자신의 역할을한다.
  • Gallerycategory 또는 Gallerylanguage를 만들 때이 엔티티에 액세스해야하는 모든 그룹의 목록을 만듭니다.
  • 이 옵션을 선택하면 그룹에서 ACL에 Gallerycategory -> ROLE_(Usergroup) 관계에 대한 VIEW 항목을 가져옵니다.

지금 내 갤러리를 나열하려면 허용 된 Gallerycategory 또는 Gallerylanguage 항목 만 표시되어야합니다.

달성하기 가장 좋은 방법은 무엇인가요? 저장소로 들어가서 현재 사용자를 확인 하시겠습니까?

답변

0

나는 그것을 이해했다고 생각합니다.

먼저 새로운 인터페이스 인 AclChildEntityInterface을 만들었습니다. 매우 간단 :

interface AclChildEntityInterface{ 
    public function getAclChildren(); 
} 

내가 아이 ACL/ACE를 확인하려는 모든 엔티티를 구현하고 자식 entites를 얻을 수있는 기능의 배열을 반환합니다.

class Gallery implements AclChildEntityInterface 
{ 
    public function getAclChildren(){ 
     return array(
      'mediacategories' => 'getMediacategories', 
      'medialanguages' => 'getMedialanguages', 
     ); 
    } 
} 

참고 배열 값이 현재의 엔티티 클래스의 함수로서 존재한다.

그 후 내가 Symfony\Component\Security\Acl\Voter\AclVoter 연장 새로운 AclVoter 생성 : 클래스가 거의 동일

을 난

catch (AclNotFoundException $noAcl)

use Symfony\Component\Security\Acl\Voter\AclVoter as BaseVoter; 
... 
use Develth\Prodcut\GalleryBundle\Entity\AclChildEntityInterface; 

class MediaAclVoter extends BaseVoter 
{ 
    ... 
    public function vote(TokenInterface $token, $object, array $attributes) 
    { 
     ... 
     } catch (AclNotFoundException $noAcl) { 
      if (null !== $this->logger) { 
       $this->logger->debug('No ACL found for the object identity. Voting to deny access.'); 
      } 

      // Check if entity has childs to check 
      if($object instanceof AclChildEntityInterface){ 
       $entityChilds = $object->getAclChildren(); 
       foreach ($entityChilds as $child) { 
        $childEntites = call_user_func(array($object,$child)); 
        foreach ($childEntites as $childEntity) { 
         $mapping = $childEntity->getName(); 
         $oid = $this->objectIdentityRetrievalStrategy->getObjectIdentity($childEntity); 
         try{ 
          $acl = $this->aclProvider->findAcl($oid, $sids); 
          if($acl->isGranted($masks, $sids, false)){ 
           // Has permission to view. show it. 
           return self::ACCESS_GRANTED; 
          } 
         }catch(AclNotFoundException $noAcl){ 
          // No ACL for this entity. Ignore 
         }catch(NoAceFoundException $noAce){ 
          // No ACE for this entity. Ignore because other could have. 
         } 
        } 
       } 
      } 

      return self::ACCESS_DENIED; 
     } catch (NoAceFoundException $noAce) { 
      ... 

}  

의 로그인 기능의 동작을 변경 juste 여기서 어떻게됩니까?

현재 엔티티에 대해 ACL이 발견되지 않으면 이전에 작성한 AclChildEntityInterface의 인스턴스가 있는지 확인합니다. 검사 할 모든 childAcl을 가져오고 ACE가 발견되면 ACCESS_GRANTED을 반환합니다.

하지만 아직 개선되지 않았다고 생각되는 부분이 있습니다. 내가 그런 일을 할 AclChildEntityInterface를 구현하는 Entity 클래스에서

:

public function getAclChildren(){ 
    return array(
     'mediacategories' => $this->mediacategories, 
     'medialanguages' => $this->medialanguages, 
    ); 
} 

나에 대한 get 메소드.

하지만 유권자에 액세스하려면 소유자 인 주체 미디어가있는 PersistentCollection을 항상 가져와 직접 액세스 할 수 없습니다. 그게 내가 call_user_funk을 사용하는 이유입니다.

개선에 대해 감사드립니다.

관련 문제