Skip to content

Commit 117fba2

Browse files
Merge pull request #63 from OpenClassrooms/OC-XXXXX_add_security_documentation
chores(security): add documentation about default roles
2 parents d752dfd + b11d1ca commit 117fba2

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

docs/Interceptor/security.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
# Security
22

3+
#[Security] attribute allows to check access.
4+
5+
```php
6+
7+
class AUseCase
8+
{
9+
#[Security("is_granted('ROLE_1')")]
10+
public function execute(UseCaseRequest $useCaseRequest)
11+
{
12+
// do things
13+
14+
return $useCaseResponse;
15+
}
16+
}
17+
```
18+
19+
## Other options :
20+
21+
```php
22+
23+
// You can use expressions to combine multiple checks, for instance role or voter:
24+
#[Security("is_granted('ROLE_1') or is_granted('VOTER_1', request)")]
25+
26+
// Beware of the following syntax
27+
#[Security]
28+
29+
// If it precedes a method named execute, __invoke or __construct, it will be interpreted as following:
30+
#[Security("is_granted('ROLE_NAME_OF_CLASS_IN_SNAKE_CASE')")]
31+
public function execute(UseCaseRequest $useCaseRequest)
32+
33+
// However, if it precedes a method with a different name, it will be interpreted as following:
34+
#[Security("is_granted('ROLE_NAME_OF_CLASS_IN_SNAKE_CASE_PROCESS_ORDER')")]
35+
public function processOrder(UseCaseRequest $useCaseRequest)
36+
// Note that ROLE contains class name AND method name in snake case
37+
38+
```
39+
340
@Security annotation allows to check access.
441

542
```php

0 commit comments

Comments
 (0)