Skip to content

Commit 96700b5

Browse files
committed
Implement per-operation access control rules
1 parent 1c88abe commit 96700b5

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

Resources/doc/security.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
# Security
22

3-
To completely disable some operations from your application, refers to [Disabling operations](operations.md#disabling-operations).
3+
To completely disable some operations from your application, refer to [Disabling operations](operations.md#disabling-operations).
44

5-
This bundle relies on security features provided by the [Symfony Security Component](http://symfony.com/doc/current/book/security.html). For instance, if you wish to restrict the access of some endpoints, you can use [Access controls directives](http://symfony.com/doc/current/book/security.html#securing-url-patterns-access-control).
5+
This bundle relies on security features provided by the [Symfony Security Component](http://symfony.com/doc/current/book/security.html). To restrict access to some operations, use [Access control rules](security.md#access-control-rules).
66

7-
It is also possible to use the [Event system](the-event-system.md) for more advanced logic or even [Custom controlers](controllers.md#using-a-custom-controller) if you really need to.
7+
It is also possible to use the [Event system](the-event-system.md) for more advanced logic or even [Custom controllers](controllers.md#using-a-custom-controller) if you really need to.
8+
9+
## Access control rules
10+
11+
You can use [Security expressions](http://symfony.com/doc/current/cookbook/expression/expressions.html#book-security-expressions) to control access to each operation.
12+
13+
```yaml
14+
# app/config/services.yml
15+
services:
16+
resource.product:
17+
parent: api.resource
18+
arguments:
19+
- AppBundle\Entity\Product
20+
calls:
21+
- method: initAccessControlRules
22+
arguments:
23+
- collection:
24+
POST: "has_role('ROLE_ADMIN')"
25+
item:
26+
PUT: "has_role('ROLE_ADMIN')"
27+
DELETE: "has_role('ROLE_ADMIN')"
28+
tags:
29+
- name: api.resource
30+
```
831
932
Previous chapter: [Content negotiation](content-negotiation.md)<br>
10-
Next chapter: [Performances](performances.md)
33+
Next chapter: [Performance](performance.md)

0 commit comments

Comments
 (0)