@@ -679,6 +679,18 @@ In this section, you'll focus on how to secure different resources (e.g. URLs,
679
679
method calls, etc) with different roles. Later, you'll learn more about how
680
680
roles are created and assigned to users.
681
681
682
+ Securing resources is done by defining access rules under the
683
+ ``access_control `` section of the security configuration. Each rule is
684
+ composed of two parts:
685
+
686
+ * Settings that describe **which ** resource to secure (``path ``, ``ip ``,
687
+ ``host ``, and ``methods ``); these settings are used to create an instance of
688
+ :class: `Symfony\\ Component\\ HttpFoundation\\ RequestMatcher ` that will be
689
+ used to match the current Request object;
690
+
691
+ * Settings that **enforce ** access restrictions (``roles `` and
692
+ ``requires_channel ``) when the rule matches the current Request.
693
+
682
694
Securing Specific URL Patterns
683
695
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
684
696
@@ -766,28 +778,51 @@ given prefix, ``/esi``, from outside access:
766
778
# ...
767
779
access_control :
768
780
- { path: ^/esi, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }
781
+ - { path: ^/esi, roles: ROLE_NO_ACCESS }
769
782
770
783
.. code-block :: xml
771
784
772
785
<access-control >
773
786
<rule path =" ^/esi" role =" IS_AUTHENTICATED_ANONYMOUSLY" ip =" 127.0.0.1" />
787
+ <rule path =" ^/esi" role =" ROLE_NO_ACCESS" />
774
788
</access-control >
775
789
776
790
.. code-block :: php
777
791
778
792
'access_control' => array(
779
793
array('path' => '^/esi', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY', 'ip' => '127.0.0.1'),
794
+ array('path' => '^/esi', 'role' => 'ROLE_NO_ACCESS'),
780
795
),
781
796
797
+ Here is how it works when the path is ``/esi/something `` coming from the
798
+ ``10.0.0.1 `` IP:
799
+
800
+ * The first access control rule does not match and is ignored as the ``path ``
801
+ matches but the ``ip `` does not;
802
+
803
+ * The second access control rule matches (the only restriction being the
804
+ ``path `` and it matches): as the user cannot have the ``ROLE_NO_ACCESS ``
805
+ role as it's not defined, access is denied (the ``ROLE_NO_ACCESS `` role can
806
+ be anything that does not match an existing role, it just serves as a trick
807
+ to always deny access).
808
+
809
+ Now, if the same request comes from ``127.0.0.1 ``:
810
+
811
+ * Now, the first access control rule does match as both the ``path `` and the
812
+ ``ip `` match: access is allowed as the user always has the
813
+ ``IS_AUTHENTICATED_ANONYMOUSLY `` role.
814
+
815
+ * The second access rule is not examined as the first rule matched.
816
+
782
817
.. _book-security-securing-channel :
783
818
784
819
.. include :: /book/_security-2012-6431.rst.inc
785
820
786
821
Securing by Channel
787
822
~~~~~~~~~~~~~~~~~~~
788
823
789
- Much like securing based on IP, requiring the use of SSL is as simple as
790
- adding a new access_control entry :
824
+ You can also restrict access by requiring the use of SSL; just use the
825
+ `` requires_channel `` argument in any `` access_control `` entries :
791
826
792
827
.. configuration-block ::
793
828
0 commit comments