-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feature: add doc for #230 #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
core/security.md
Outdated
@@ -6,6 +6,52 @@ section. | |||
Using API Platform, you can leverage all 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). | |||
|
|||
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). | |||
Here is a little exemple for this : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since 2.1, you can add security through Symfony's access control expressions in your entities.
Here is an example:
core/security.md
Outdated
Here is a little exemple for this : | ||
|
||
```php | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line?
core/security.md
Outdated
/** | ||
* Secured resource. | ||
* | ||
* @author Kévin Dunglas <[email protected]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed here
core/security.md
Outdated
* @ORM\GeneratedValue(strategy="AUTO") | ||
*/ | ||
public $id; | ||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line missing
Thanks for handling this Hamza! Can you just add sentence explaining what the example do? |
Uhh... I've never noticed this, but |
By the way this is documenting api-platform/core#938 |
@dunglas, I will update this asap :p |
@Simperfit, can you replace |
ping @Simperfit |
e0a78d0
to
18678c3
Compare
done |
core/security.md
Outdated
} | ||
``` | ||
|
||
This exemple is going to allow only fetching the book related to the current user, if he try to fetch a book that is not linked to his account that will not return the resource and only admins are able to create books which means that a user could not create a book. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Add a dot here:
current user. If he
is linked to his account, that will
- Replace
try
bytries
return the resource. In addition, only admins are
core/security.md
Outdated
* Secured resource. | ||
* | ||
* @ApiResource( | ||
* attributes={"is_granted"="has_role('ROLE_USER')"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
access_control
too.
core/security.md
Outdated
} | ||
``` | ||
|
||
This exemple is going to allow only fetching the book related to the current user. if he tries to fetch a book that is linked to his account, that will not return the resource. In addition, only admins are are able to create books which means that a user could not create a book. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are are able
areuh areuh?
It would be nice to mention these variables, but it can be done in a future PR: https://github.com/api-platform/core/blob/7d85bbcf60f1aa1822384e8f330f2fe3c594e809/src/Security/EventListener/DenyAccessListener.php#L105-L116 |
core/security.md
Outdated
public $title; | ||
|
||
/** | ||
* @ORM\Column(type="text") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be string or a relation.
No description provided.