나는 그것을 이해했다고 생각합니다.
먼저 새로운 인터페이스 인 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
을 사용하는 이유입니다.
개선에 대해 감사드립니다.