Skip to content

Commit b164dc9

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: [Security] Document the delete_cookies option [Security] Add type hints
2 parents fd12d45 + 30ba09a commit b164dc9

File tree

2 files changed

+83
-7
lines changed

2 files changed

+83
-7
lines changed

reference/configuration/security.rst

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Configuration
2828
**Basic Options**:
2929

3030
* `access_denied_url`_
31+
* `delete_cookies`_
3132
* `erase_credentials`_
3233
* `hide_user_not_found`_
3334
* `session_fixation_strategy`_
@@ -51,6 +52,81 @@ access_denied_url
5152
Defines the URL where the user is redirected after a ``403`` HTTP error (unless
5253
you define a custom access denial handler). Example: ``/no-permission``
5354

55+
delete_cookies
56+
~~~~~~~~~~~~~~
57+
58+
**type**: ``array`` **default**: ``[]``
59+
60+
Lists the names (and other optional features) of the cookies to delete when the
61+
user logs out::
62+
63+
.. configuration-block::
64+
65+
.. code-block:: yaml
66+
67+
# config/packages/security.yaml
68+
security:
69+
# ...
70+
71+
firewalls:
72+
main:
73+
# ...
74+
logout:
75+
delete_cookies:
76+
cookie1-name: null
77+
cookie2-name:
78+
path: '/'
79+
cookie3-name:
80+
path: null
81+
domain: example.com
82+
83+
.. code-block:: xml
84+
85+
<!-- config/packages/security.xml -->
86+
<?xml version="1.0" encoding="UTF-8" ?>
87+
<srv:container xmlns="http://symfony.com/schema/dic/security"
88+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
89+
xmlns:srv="http://symfony.com/schema/dic/services"
90+
xsi:schemaLocation="http://symfony.com/schema/dic/services
91+
https://symfony.com/schema/dic/services/services-1.0.xsd">
92+
93+
<config>
94+
<!-- ... -->
95+
96+
<firewall name="main">
97+
<!-- ... -->
98+
<logout path="...">
99+
<delete-cookie name="cookie1-name"/>
100+
<delete-cookie name="cookie2-name" path="/"/>
101+
<delete-cookie name="cookie3-name" domain="example.com"/>
102+
</logout>
103+
</firewall>
104+
</config>
105+
</srv:container>
106+
107+
.. code-block:: php
108+
109+
// config/packages/security.php
110+
$container->loadFromExtension('security', [
111+
// ...
112+
'firewalls' => [
113+
'main' => [
114+
'logout' => [
115+
'delete_cookies' => [
116+
'cookie1-name' => null,
117+
'cookie2-name' => [
118+
'path' => '/',
119+
],
120+
'cookie3-name' => [
121+
'path' => null,
122+
'domain' => 'example.com',
123+
],
124+
],
125+
],
126+
],
127+
],
128+
]);
129+
54130
erase_credentials
55131
~~~~~~~~~~~~~~~~~
56132

security/voters.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ which makes creating a voter even easier::
4747

4848
abstract class Voter implements VoterInterface
4949
{
50-
abstract protected function supports(string $attribute, $subject);
51-
abstract protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token);
50+
abstract protected function supports(string $attribute, mixed $subject);
51+
abstract protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token);
5252
}
5353

5454
.. _how-to-use-the-voter-in-a-controller:
@@ -129,7 +129,7 @@ would look like this::
129129
const VIEW = 'view';
130130
const EDIT = 'edit';
131131

132-
protected function supports(string $attribute, $subject): bool
132+
protected function supports(string $attribute, mixed $subject): bool
133133
{
134134
// if the attribute isn't one we support, return false
135135
if (!in_array($attribute, [self::VIEW, self::EDIT])) {
@@ -144,7 +144,7 @@ would look like this::
144144
return true;
145145
}
146146

147-
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
147+
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
148148
{
149149
$user = $token->getUser();
150150

@@ -189,7 +189,7 @@ That's it! The voter is done! Next, :ref:`configure it <declaring-the-voter-as-a
189189

190190
To recap, here's what's expected from the two abstract methods:
191191

192-
``Voter::supports(string $attribute, $subject)``
192+
``Voter::supports(string $attribute, mixed $subject)``
193193
When ``isGranted()`` (or ``denyAccessUnlessGranted()``) is called, the first
194194
argument is passed here as ``$attribute`` (e.g. ``ROLE_USER``, ``edit``) and
195195
the second argument (if any) is passed as ``$subject`` (e.g. ``null``, a ``Post``
@@ -199,7 +199,7 @@ To recap, here's what's expected from the two abstract methods:
199199
return ``true`` if the attribute is ``view`` or ``edit`` and if the object is
200200
a ``Post`` instance.
201201

202-
``voteOnAttribute(string $attribute, $subject, TokenInterface $token)``
202+
``voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token)``
203203
If you return ``true`` from ``supports()``, then this method is called. Your
204204
job is to return ``true`` to allow access and ``false`` to deny access.
205205
The ``$token`` can be used to find the current user object (if any). In this
@@ -242,7 +242,7 @@ with ``ROLE_SUPER_ADMIN``::
242242
$this->security = $security;
243243
}
244244

245-
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
245+
protected function voteOnAttribute($attribute, mixed $subject, TokenInterface $token): bool
246246
{
247247
// ...
248248

0 commit comments

Comments
 (0)