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: symfony/security.md
+67-1Lines changed: 67 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -158,7 +158,73 @@ Additionally, in some cases you need to perform security checks on the original
158
158
159
159
The value in the `previous_object` variable is cloned from the original object.
160
160
Note that, by default, this clone is not a deep one (it doesn't clone relationships, relationships are references).
161
-
To make a deep clone, [implement `__clone` method](https://www.php.net/manual/en/language.oop5.cloning.php) in the concerned resource class.
161
+
To make a deep clone, [implement `__clone` method](https://www.php.net/manual/en/language.oop5.cloning.php) in the concerned resource class.i
162
+
163
+
## Controlling the response on `securityPostDenormalize`
164
+
165
+
By default, when a request for a write operation is made that doesn't meet the `securityPostDenormalize` requirements (i.e. the expression returns `false`), the values of those protected properties in the
166
+
request data are silently discarded and not set on the object. Any properties the user does have permission to update will be updated and the request succeeds.
167
+
168
+
You can optionally instruct API Platform to instead return a 403 Access Denied response in such cases, by adding `throw_on_access_denied` as an extra property with a value of `true`:
169
+
170
+
<code-selector>
171
+
172
+
```php
173
+
<?php
174
+
// api/src/Entity/Book.php
175
+
namespace App\Entity;
176
+
177
+
use ApiPlatform\Metadata\Get;
178
+
use ApiPlatform\Metadata\Put;
179
+
180
+
#[Get]
181
+
#[Put(
182
+
securityPostDenormalize: "is_granted('ROLE_ADMIN') or (object.owner == user and previous_object.owner == user)",
0 commit comments