Skip to content

Commit f965e3a

Browse files
committed
feature #5891 Removed the comments about the is_granted() issues in non-secure pages (javiereguiluz)
This PR was merged into the 2.8 branch. Discussion ---------- Removed the comments about the is_granted() issues in non-secure pages | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.8+ | Fixed tickets | #5860 Commits ------- 1361715 Removed the comments about the is_granted() issues in non-secure pages
2 parents 0061abe + 1361715 commit f965e3a

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

book/security.rst

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ Access Control in Templates
884884
...........................
885885

886886
If you want to check if the current user has a role inside a template, use
887-
the built-in helper function:
887+
the built-in ``is_granted()`` helper function:
888888

889889
.. configuration-block::
890890

@@ -900,20 +900,18 @@ the built-in helper function:
900900
<a href="...">Delete</a>
901901
<?php endif ?>
902902

903-
If you use this function and you are *not* behind a firewall, an exception will
904-
be thrown. Again, it's almost always a good idea to have a main firewall that
905-
covers all URLs (as shown before in this chapter).
906-
907-
.. caution::
903+
.. note::
908904

909-
Be careful with this in your base layout or on your error pages! Because of
910-
some internal Symfony details, to avoid broken error pages in the ``prod``
911-
environment, wrap calls in these templates with a check for ``app.user``:
905+
In Symfony versions previous to 2.8, using the ``is_granted()`` function
906+
in a page that wasn't behind a firewall resulted in an exception. That's why
907+
you also needed to check first for the existence of the user:
912908

913909
.. code-block:: html+twig
914910

915911
{% if app.user and is_granted('ROLE_ADMIN') %}
916912

913+
Starting from Symfony 2.8, the ``app.user and ...`` check is no longer needed.
914+
917915
Securing other Services
918916
.......................
919917

cookbook/controller/error_pages.rst

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ To override the 404 error template for HTML pages, create a new
9696
<h1>Page not found</h1>
9797

9898
{# example security usage, see below #}
99-
{% if app.user and is_granted('IS_AUTHENTICATED_FULLY') %}
99+
{% if is_granted('IS_AUTHENTICATED_FULLY') %}
100100
{# ... #}
101101
{% endif %}
102102

@@ -124,24 +124,6 @@ store the HTTP status code and message respectively.
124124
for the standard HTML exception page or ``exception.json.twig`` for the JSON
125125
exception page.
126126

127-
Avoiding Exceptions when Using Security Functions in Error Templates
128-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129-
130-
One of the common pitfalls when designing custom error pages is to use the
131-
``is_granted()`` function in the error template (or in any parent template
132-
inherited by the error template). If you do that, you'll see an exception thrown
133-
by Symfony.
134-
135-
The cause of this problem is that routing is done before security. If a 404 error
136-
occurs, the security layer isn't loaded and thus, the ``is_granted()`` function
137-
is undefined. The solution is to add the following check before using this function:
138-
139-
.. code-block:: twig
140-
141-
{% if app.user and is_granted('...') %}
142-
{# ... #}
143-
{% endif %}
144-
145127
.. _testing-error-pages:
146128

147129
Testing Error Pages during Development

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy