You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/security.md
+46Lines changed: 46 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,52 @@ section.
6
6
Using API Platform, you can leverage all security features provided by the [Symfony Security component](http://symfony.com/doc/current/book/security.html).
7
7
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).
8
8
9
+
You can also add security directly in the entity using the [Symfony's access control expressions](https://symfony.com/doc/current/expressions.html#security-complex-access-controls-with-expressions).
10
+
Here is a little exemple for this :
11
+
12
+
```php
13
+
14
+
use ApiPlatform\Core\Annotation\ApiResource;
15
+
use Doctrine\ORM\Mapping as ORM;
16
+
use Symfony\Component\Validator\Constraints as Assert;
* "get"={"method"="GET", "is_granted"="has_role('ROLE_USER') and object.getOwner() == user"}
31
+
* }
32
+
* )
33
+
* @ORM\Entity
34
+
*/
35
+
class Book
36
+
{
37
+
/**
38
+
* @var int
39
+
*
40
+
* @ORM\Column(type="integer")
41
+
* @ORM\Id
42
+
* @ORM\GeneratedValue(strategy="AUTO")
43
+
*/
44
+
public $id;
45
+
/**
46
+
* @var string The title
47
+
*
48
+
* @ORM\Column
49
+
* @Assert\NotBlank
50
+
*/
51
+
public $title;
52
+
}
53
+
```
54
+
9
55
It is also possible to use the [event system](events.md) for more advanced logic or even [custom actions](operations.md#creating-custom-operations-and-controllers)
0 commit comments