PLATFORM >= 2015.09
Description
eZ content repository uses the concept of Roles and Policies in order to authorize a user to do something (e.g. read content).
- A Role is composed of Policies and can be assigned to a User or a User Group.
- A Policy is composed of a combination of module and function (e.g.
content/read
,content
being the module andread
being the function). - Depending on module and function combination, a Policy can also be composed of Limitations.
It is possible for any bundle to expose available Policies via a PolicyProvider
which can be added to EzPublishCoreBundle's DIC extension.
PolicyProvider
A PolicyProvider
is an object providing a hash containing declared modules, functions and limitations.
- Each Policy provider provides a collection of permission modules.
- Each module can provide functions (e.g. "content/read": "content" is the module, "read" is the function)
- Each function can provide a collection of Limitations.
Policies configuration hash contains declared these modules, functions and Limitations.
First level key is the module name, value is a hash of available functions, with function name as key.
Function value is an array of available Limitations, identified by the alias declared in LimitationType service tag.
If no Limitation is provided, value can be null
or an empty array.
Limitations need to be implemented as limitation types and declared as services identified with ezpublish.limitationType
tag. Name provided in the hash for each Limitation is the same value set in alias
attribute in the service tag.
Example
YamlPolicyProvider
An abstract class based on YAML is provided: eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Security\PolicyProvider\YamlPolicyProvider
.
It defines an abstract getFiles()
method.
Extend YamlPolicyProvider
and implement getFiles()
to return absolute paths to your YAML files.
Extending existing policies
A PolicyProvider
may provide new functions to a module, and additional Limitations to an existing function.
It is however strongly encouraged to add functions to your own Policy modules.
It is not possible to remove an existing module, function or limitation from a Policy.
Integrating the PolicyProvider into EzPublishCoreBundle
For a PolicyProvider to be active, it must be properly declared in EzPublishCoreBundle.
A bundle just has to retrieve CoreBundle's DIC extension and call addPolicyProvider()
. This must be done in the bundle's build()
method.
Core policies
Policies used internally in repository services are defined in EzPublishCoreBundle/Resources/config/policies.yml
.
1 Comment
Gaetano Giunta
It would be nice to have a paragraph here describing as well how these can be tested, or at least a link to the page where this is described...