@@ -802,9 +802,6 @@ the ``^``) would match ``/admin/foo`` but would also match URLs like ``/foo/admi
802
802
803
803
To learn about all of this, see :doc: `/cookbook/security/access_control `.
804
804
805
- .. _`book-security-securing-controller` :
806
-
807
-
808
805
Securing other Services
809
806
~~~~~~~~~~~~~~~~~~~~~~~
810
807
@@ -813,11 +810,15 @@ the one seen in the previous section. For example, suppose you have a service
813
810
(i.e. a PHP class) whose job is to send emails from one user to another.
814
811
You can restrict use of this class - no matter where it's being used from -
815
812
to users that have a specific role.
816
- >>>>>>> Minor format improvements
813
+
814
+ .. _`book-security-securing-controller` :
817
815
818
816
Securing Controllers and other Code
819
817
...................................
820
818
819
+ Securing a Controller
820
+ ~~~~~~~~~~~~~~~~~~~~~
821
+
821
822
You can easily deny access from inside a controller::
822
823
823
824
// ...
@@ -835,6 +836,12 @@ You can easily deny access from inside a controller::
835
836
The ``security.authorization_checker `` service was introduced in Symfony 2.6. Prior
836
837
to Symfony 2.6, you had to use the ``isGranted() `` method of the ``security.context `` service.
837
838
839
+ .. versionadded :: 2.6
840
+ You can use directly :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller::isGranted `
841
+ instead of `$this->get('security.context')->isGranted($role) ` to check if
842
+ a role is granted and :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller::denyAccessUnlessGranted `
843
+ to throw an exception if the access is not granted (like in the example above).
844
+
838
845
.. versionadded :: 2.5
839
846
The ``createAccessDeniedException `` method was introduced in Symfony 2.5.
840
847
0 commit comments