- 原文出处:http://symfony.com/doc/current/cookbook/security/acl_advanced.html
- 原文作者:Symfony.com
- 授权许可:创作共用协议
- 翻译人员:StarBear
- 校对人员:FireHare
- 适用版本:Symfony 2
- 文章状态:已校对
The aim of this chapter is to give a more in-depth view of the ACL system, and also explain some of the design decisions behind it.
本章的目的是更加深入地了解ACL系统,并在之后解释一些设计理念。
Design Concepts(设计思路)
Symfony2's object instance security capabilities are based on the concept of an Access Control List. Every domain object instance has its own ACL. The ACL instance holds a detailed list of Access Control Entries (ACEs) which are used to make access decisions. Symfony2's ACL system focuses on two main objectives:
Symfony2的对象实例安全功能是建立在访问控制列表概念之上的。所有的域对象实例都拥有自己的ACL。ACL实例有着一个访问控制项的详细列表(ACEs),该列表用来指定访问权限。Symfony2的ACL系统专注于两个主要目标:
- providing a way to efficiently retrieve a large amount of ACLs/ACEs for your domain objects, and to modify them;
- 为你的域对象提供一个有效的方法去检索和更改大量的ACLs/ACEs。
- providing a way to easily make decisions of whether a person is allowed to perform an action on a domain object or not.
- 提供一个方法,可以方便地确定用户是否被允许在一个域对象上具备执行相关操作的权限。
As indicated by the first point, one of the main capabilities of Symfony2's ACL system is a high-performance way of retrieving ACLs/ACEs. This is extremely important since each ACL might have several ACEs, and inherit from another ACL in a tree-like fashion. Therefore, we specifically do not leverage any ORM, but the default implementation interacts with your connection directly using Doctrine's DBAL.
第一点明确表明,Symfony2中ACL系统的主要功能之一就是高效检索ACLs/ACEs。这非常重要,因为每个ACL有多条ACEs、同时它还以类树型的方式从其他ACL中继承。因此,虽然我们没有指定ORM,但是默认与你的连接交互实现是直接使用Doctrine的DBAL。
Object Identities(对象标识)
The ACL system is completely decoupled from your domain objects. They don't even have to be stored in the same database, or on the same server. In order to achieve this decoupling, in the ACL system your objects are represented through object identity objects. Everytime, you want to retrieve the ACL for a domain object, the ACL system will first create an object identity from your domain object, and then pass this object identity to the ACL provider for further processing.
ACL系统是完全与你的域对象分离的。它们甚至不需要保存在同一个数据库或同一台主机中。为了实现这种分离,在ACL系统里你的对象被认为是对象标识。任何时候,在你想检索域对象的ACL时,ACL系统都会事先为你的域对象创建一个对象标识,然后将该对象标识传递到ACL提供器作进一步处理。
Security Identities(安全标识)
This is analog to the object identity, but represents a user, or a role in your application. Each role, or user has its own security identity.
与对象标识类似,但表现为你应用程序中的用户或角色。每个角色或用户都拥有各自的安全标识。(校者注:与域对象拥有自己的对象标识相似,用户或角色也拥有各自的安全标识)
Database Table Structure(数据表结构)
The default implementation uses five database tables as listed below. The tables are ordered from least rows to most rows in a typical application:
(ACL系统)缺省使用下列五个数据表来实现。在一个典型的应用程序中这些表按记录数从小到大排列。
- acl_security_identities: This table records all security identities (SID) which hold ACEs. The default implementation ships with two security identities: RoleSecurityIdentity, and UserSecurityIdentity
- acl_security_identities:该表记录所有拥有ACEs的安全标识(SID)。并缺省实现两个安全标识:RoleSecurityIdentity和UserSecurityIdentity之间的关系。
- acl_classes: This table maps class names to a unique id which can be referenced from other tables.
- acl_classes:该表将类名映射成唯一id,该id可以被其他数据表引用。
- acl_object_identities: Each row in this table represents a single domain object instance.
- acl_object_identities:数据表中的每条记录都表示一个单独的域对象实例。
- acl_object_identity_ancestors: This table allows us to determine all the ancestors of an ACL in a very efficient way.
- acl_object_identity_ancestors:该表允许我们用一种非常高效的方式去确定一条ACL的所有祖先。(校者注:也就是可以迭代地确定该ACL继承了哪些ACL)
- acl_entries: This table contains all ACEs. This is typically the table with the most rows. It can contain tens of millions without significantly impacting performance.
- acl_entries:该数据表包含所有的ACEs。该表通常拥有最多的记录。在包含数千万条记录的情况下不会显著影响性能。
Scope of Access Control Entries(访问控制项范围)
Access control entries can have different scopes in which they apply. In Symfony2, we have basically two different scopes:
访问控制项在应用时有不同的范围。在Symfony2中我们有两个基本的范围。
- Class-Scope: These entries apply to all objects with the same class.
- 类范围:这些项应用于拥有相同类的所有对象上。
- Object-Scope: This was the scope we solely used in the previous chapter, and it only applies to one specific object.
- 对象范围:在前面的章节中我们使用过这个范围,它仅用于指定的对象。
Sometimes, you will find the need to apply an ACE only to a specific field of the object. Let's say you want the ID only to be viewable by an administrator, but not by your customer service. To solve this common problem, we have added two more sub-scopes:
有时候,你只能将ACE应用到对象的特定字段里。比如说,你想ID只能被管理员而不是客户服务查看。那么要解决这个问题,我们需要添加两个额外的子范围:
- Class-Field-Scope: These entries apply to all objects with the same class, but only to a specific field of the objects.
- 类字段范围:这些项应用于拥有相同类的所有对象上,但仅仅是对象的特定字段。
- Object-Field-Scope: These entries apply to a specific object, and only to a specific field of that object.
- 对象字段范围:这些项应用于指定对象,但仅限于该对象的特定字段。
PermissionGrantingStrategy首先检查所有对象范围的ACEs,如果没有匹配,则检查类范围的ACEs,如果还未匹配,将会重复在父ACL上的ACEs的检查过程。如果父ACL不存在,则抛出异常。