Permission overview¶
A new User does not have permissions for any part of the system, unless they are explicitly given access. To get access they need to inherit Roles, typically assigned to the User Group they belong to.
Each Role can contain one or more Policies. A Policy is a rule that gives access to a single function in a module.
For example, a section/assign
Policy allows the User to assign content to Sections.
When you add a Policy to a Role, you can also restrict it using one or more Limitations.
A Policy with a Limitation will only apply when the condition in the Limitation is fulfilled.
For example, a content/publish
Policy with a ContentType
Limitation on the "Blog Post" content type will allow the User to publish only Blog Posts, and not other content.
A Limitation, like a Policy, specifies what a User can do, not what they can't do.
A Section
Limitation, for example, gives the User access to the selected Section, not prohibits it.
See Limitation reference for further information and Permission use cases for example permission setups.
Assigning Roles to Users¶
Every User or User Group can have many roles. A User can also belong to many groups, for example, Administrators, Editors, Subscribers.
It is best practice to avoid assigning Roles to users directly. Instead, try to organize your content so that it can be covered with general Roles assigned to User Groups.
Using Groups is easier to manage and more secure. It also improves system performance. The more Role assignments and complex Policies you add for a given User, the more complex the search/load queries will be, because they always take permissions into account.
Permissions for custom controllers¶
You can control access to a custom controller by implementing the performAccessCheck()
method.
In the following example the user does not have access to the controller unless they have the section/view
Policy:
1 2 3 4 5 6 7 |
|
Attribute
accepts three arguments:
module
is the Policy module (e.g.content
)function
is the function inside the module (e.g.read
)limitations
are optional Limitations to check against. Here you can provide two keys:valueObject
is the object you want to check for, for exampleContentInfo
.targets
are a table of value objects that are the target of the operation. For example, to check if content can be assigned to a Section, provide the Section astargets
.targets
accept Location, Object state and Section objects.
Checking user access¶
To check if a user has access to an operation, use the isGranted()
method.
For example, to check if content can be assigned to a Section:
1 2 3 |
|
You can also use the permission resolver (Ibexa\Core\Repository\Permission\PermissionResolver
).
The canUser()
method checks if the user can perform a given action with the selected object.
For example: canUser('content', 'edit', $content, [$location] );
checks the content/edit
permission for the provided content item at the provided Location.
Blocking access to controller action¶
To block access to a specific action of the controller, add the following to the action's definition:
1 |
|