2012-03-19 47 views
1

该文档缺少关于ACL的一些细节。它很简单,就像在持久化域对象上调用createAcl一样。然后在用户/对象上放置一个掩码insertObjectAceSymfony2内部如何维护ACL?

但是Symfony2如何管理ACL?是否有一些额外的列添加到表中?

$entityManager = $this->get('doctrine.orm.default_entity_manager'); 
$entityManager->persist($comment); 
$entityManager->flush(); 

// creating the ACL 
$aclProvider = $this->get('security.acl.provider'); 
$objectIdentity = ObjectIdentity::fromDomainObject($comment); 
$acl = $aclProvider->createAcl($objectIdentity); 

// retrieving the security identity of the currently logged-in user 
$securityContext = $this->get('security.context'); 
$user = $securityContext->getToken()->getUser(); 
$securityIdentity = UserSecurityIdentity::fromAccount($user); 

// grant owner access 
$acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER); 
$aclProvider->updateAcl($acl); 

回答

2

它创造了许多新表,

中的表从最低行命令中的大多数行一个典型 应用:

  • acl_security_identities:此表记录所有的安全标识(SID)持有ACE。默认实现附带两个
    安全身份:RoleSecurityIdentity和UserSecurityIdentity
  • acl_classes:此表将类名映射到可以从其他表引用的唯一标识。
  • acl_object_identities:此表中的每一行表示单个域对象实例。
  • acl_object_identity_ancestors:该表格允许我们以非常有效的方式确定ACL的所有祖先。
  • acl_entries:此表包含所有ACE。这通常是行数最多的表格。它可以包含数千万而不会显着影响性能。

其实本章向你解释一个关于如何ACL被Symfony2的内部管理很多事情:

http://symfony.com/doc/current/cookbook/security/acl_advanced.html