@@ -376,20 +376,24 @@ generated earlier, the roles are an array that's stored in the database, and
376
376
every user is *always * given at least one role: ``ROLE_USER ``::
377
377
378
378
// src/Entity/User.php
379
- // ...
380
-
381
- /**
382
- * @ORM\Column(type="json")
383
- */
384
- private $roles = [];
385
379
386
- public function getRoles(): array
380
+ // ...
381
+ class User
387
382
{
388
- $roles = $this->roles;
389
- // guarantee every user at least has ROLE_USER
390
- $roles[] = 'ROLE_USER';
383
+ /**
384
+ * @ORM\Column(type="json")
385
+ */
386
+ private $roles = [];
391
387
392
- return array_unique($roles);
388
+ // ...
389
+ public function getRoles(): array
390
+ {
391
+ $roles = $this->roles;
392
+ // guarantee every user at least has ROLE_USER
393
+ $roles[] = 'ROLE_USER';
394
+
395
+ return array_unique($roles);
396
+ }
393
397
}
394
398
395
399
This is a nice default, but you can do *whatever * you want to determine which roles
@@ -644,6 +648,16 @@ Securing other Services
644
648
645
649
See :doc: `/security/securing_services `.
646
650
651
+ Securing Individual Objects
652
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
653
+
654
+ Most applications require more specific access rules. For instance, a User
655
+ should be able to only edit their own comments on a blog. Voters allow you
656
+ to write *whatever * business logic you need to determine access. Using
657
+ these voters is similar to the role-based access checks implemented in the
658
+ previous chapters. Read :doc: `/security/voters ` to learn how to implement
659
+ your own voter.
660
+
647
661
Checking to see if a User is Logged In (IS_AUTHENTICATED_FULLY)
648
662
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
663
@@ -681,22 +695,6 @@ like this:
681
695
this - this is useful when *whitelisting * URLs to guarantee access - some
682
696
details are in :doc: `/security/access_control `.
683
697
684
- .. _security-secure-objects :
685
-
686
- Access Control Lists (ACLs): Securing individual Database Objects
687
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
688
-
689
- Imagine you are designing a blog where users can comment on your posts. You
690
- also want a user to be able to edit their own comments, but not those of
691
- other users. Also, as the admin user, you want to be able to edit *all * comments.
692
-
693
- :doc: `Voters </security/voters >` allow you to write *whatever * business logic you
694
- need (e.g. the user can edit this post because they are the creator) to determine
695
- access. That's why voters are officially recommended by Symfony to create ACL-like
696
- security systems.
697
-
698
- If you still prefer to use traditional ACLs, refer to the `Symfony ACL bundle `_.
699
-
700
698
.. _retrieving-the-user-object :
701
699
702
700
5a) Fetching the User Object
0 commit comments