dev-master
9999999-dev https://github.com/wemakecustom/symfony-acl-bundleSymfony ACL Bundle
MIT
The Requires
- php >=5.3.3
- symfony/security-core ~2.3
The Development Requires
Wallogit.com
2017 © Pedro PelĂĄez
Symfony ACL Bundle
This bundle is intended to provide a replacement to the Symfony2 ACL Component., (*1)
Symfony2's ACL Component is currently weakly documented, hard to extend, and present a leaky abstraction., (*2)
All of these issues makes it hard to maintain. In this context, we offer a new alternative, whose abstraction layer has been redesigned from scratch and offering easy extension points., (*3)
This component can be used either directly, requiring only the Symfony Core to be used. Or with the full-stack Symfony2 framework., (*4)
This component is relying on 5 concepts:, (*5)
An ACL (Access Control List), is a list of ACEs (Access Control Entry)., (*6)
An ACE is a triplet [Grantee, Target, Permission]. The Grantee is whom the permission is granted to. The Target is what the permission is granted on. The permission is obviously, what is granted., (*7)
For example, [UserA, Post1, VIEW] would mean that UserA is allowed to VIEW Post1., (*8)
Of course, the ACL system is internally using an abstraction for Grantees and Targets. But you don't need to worry about creating these yourself, the ACL Provider will take care of everything for you. You only need to know what is accepted as a Grantee or as a Target., (*9)
Grantees are abstracted away as SecurityIdentities. There are three kinds of security identity:, (*10)
Thus, accepted grantees are:, (*11)
null, denoting an Anonymous identity.Any implementation of
UserInterface
will be seamlessly accepted by the ACL system. The User is identified using its
class and ID (or Username if there is no getId() method). If you prefer to
identify your User using something else, you should implement
AclSecurityObjectInterface., (*12)
Any implementation of
RoleInterface
will be seamlessly accepted by the ACL system, as long as getRole() returns a
string. If you prefer to identify your Role using something else, you should
implement
AclSecurityObjectInterface., (*13)
Targets are abstracted away as TargetIdentities. ACLs can be granted on 4 kinds of targets:, (*14)
Thus, accepted target are:, (*15)
For objects to be accepted, they need to either implements
AclTargetObjectInterface, have a
getId() or a __toString() method., (*16)
N.B.: A field doesn't need to be actually a property within the class, but it could be any string. This could be useful to specify permissions on parts of an Object., (*17)
Symfony's Security system is based on "attributes", this is the first parameter given to isGranted., (*18)
However the mapping between granted permissions and attributes is not 1:1. For
example, following the Symfony2's ACL Built-in Permission
Map,
if you grant someone the OPERATOR permission, your intent is to grant VIEW,
EDIT, CREATE, DELETE, UNDELETE and OPERATOR attributes., (*19)
Thus, one permissions actually denotes several attributes. This correspondance is taken care of through the Permission Map. To this end, we provide a re-implementation of the Symfony2's ACL Built-in Permission Map., (*20)
In the full stack Symfony2 framework, the permission map is available through, (*21)
The ACL Provider is the most central item of the ACL system. The ACL Provider is the object responsible for fetching the ACEs from a backend storage (usually a database) and providing easy access to them. A basic ACL Provider is considered Read-Only, but the MutableAclProvider allows easy modification of the ACL (i.e. creation and deletion of ACEs)., (*22)
Symfony's Security system is based on a set of
Voters: each
time isGranted is called, a set of voters are called until one decides on
granting or denying access., (*23)
A Voter is provided with a Token (denoting a User and its Role), a Target and a set of Attributes., (*24)
The ACL default voter check if the current User or any of its Roles is granted a permission providing any of the requested Attributes., (*25)
However, granting decisions for ACL could be quite complex. To make this easier, the Voter is not implementing the whole access checking process, but delay the final decision to an Access Granting Strategy., (*26)
The strategy is responsible for deciding if any of the User or Roles is actually granted any of the attributes on the target., (*27)
We provide 5 built-in strategies:, (*28)
We check only the target ACEs themselves. So, given a class C1 and one of its
instances O1, if a User is granted access on C1, but the permission is not
explicitly given on O1, he will not be granted the permission., (*29)
We check for permissions on objects and their classes. If a User does not have any permission granted on an Object (or an Object's Field), we will try to check if they have any for the Class (or the Class' Field)., (*30)
This is the default strategy in the full stack framework., (*31)
We check for permissions on Fields and Object or Class. If a User does not have any permission granted on an Object's (or Class)' Field, we will try to check if they have any for the Object (or Class) itself., (*32)
We check for permission on Parent classes. If a User does not have any permission granted on a Class (or its Field), we will try to check on its Parent Class (or its Field)., (*33)
This strategy is a mix the last three. It is mostly intended to be used as a code example for your own Strategies. Please read the source code for more details., (*34)
Symfony ACL Bundle
MIT