Skip to content

Commit 2daccc3

Browse files
committed
Merge branch '2.8'
* 2.8: tweaks thanks to the guys removing deprecation note on a section that was removed Wrap all strings containing @ in quotes in Yaml Updating some places to use the new CustomUserMessageAuthenticationException Added a note about the use of _format query parameter Always use "main" as the default firewall name (to match Symfony Standard Edition)
2 parents 1a27539 + 8d61eb6 commit 2daccc3

10 files changed

+61
-34
lines changed

book/routing.rst

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,12 +1104,20 @@ a slash. URLs matching this route might look like:
11041104

11051105
This example also highlights the special ``_format`` routing parameter.
11061106
When using this parameter, the matched value becomes the "request format"
1107-
of the ``Request`` object. Ultimately, the request format is used for such
1108-
things as setting the ``Content-Type`` of the response (e.g. a ``json``
1109-
request format translates into a ``Content-Type`` of ``application/json``).
1110-
It can also be used in the controller to render a different template for
1111-
each value of ``_format``. The ``_format`` parameter is a very powerful way
1112-
to render the same content in different formats.
1107+
of the ``Request`` object.
1108+
1109+
Ultimately, the request format is used for such things as setting the
1110+
``Content-Type`` of the response (e.g. a ``json`` request format translates
1111+
into a ``Content-Type`` of ``application/json``). It can also be used in the
1112+
controller to render a different template for each value of ``_format``.
1113+
The ``_format`` parameter is a very powerful way to render the same content
1114+
in different formats.
1115+
1116+
In Symfony versions previous to 3.0, it is possible to override the request
1117+
format by adding a query parameter named ``_format`` (for example:
1118+
``/foo/bar?_format=json``). Relying on this behavior not only is considered
1119+
a bad practice but it will complicate the upgrade of your applications to
1120+
Symfony 3.
11131121

11141122
.. note::
11151123

cookbook/bundles/best_practices.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ The end user can provide values in any configuration file:
342342
343343
# app/config/config.yml
344344
parameters:
345-
acme_blog.author.email: fabien@example.com
345+
acme_blog.author.email: "fabien@example.com"
346346
347347
.. code-block:: xml
348348

cookbook/console/console_command.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ for details.
8282
Getting Services from the Service Container
8383
-------------------------------------------
8484

85-
.. caution::
86-
87-
The "container scopes" concept explained in this section has been deprecated
88-
in Symfony 2.8 and it will be removed in Symfony 3.0.
89-
9085
By using :class:`Symfony\\Bundle\\FrameworkBundle\\Command\\ContainerAwareCommand`
9186
as the base class for the command (instead of the more basic
9287
:class:`Symfony\\Component\\Console\\Command\\Command`), you have access to the

cookbook/email/dev_environment.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ via the ``delivery_address`` option:
6666
6767
# app/config/config_dev.yml
6868
swiftmailer:
69-
delivery_address: dev@example.com
69+
delivery_address: "dev@example.com"
7070
7171
.. code-block:: xml
7272

cookbook/logging/monolog_email.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ it is broken down.
3131
handler: swift
3232
swift:
3333
type: swift_mailer
34-
from_email: error@example.com
35-
to_email: error@example.com
34+
from_email: "error@example.com"
35+
to_email: "error@example.com"
3636
# or list of recipients
37-
# to_email: [dev1@example.com, dev2@example.com, ...]
37+
# to_email: ["dev1@example.com", "dev2@example.com", ...]
3838
subject: An Error Occurred!
3939
level: debug
4040
@@ -161,8 +161,8 @@ get logged on the server as well as the emails being sent:
161161
handler: swift
162162
swift:
163163
type: swift_mailer
164-
from_email: error@example.com
165-
to_email: error@example.com
164+
from_email: "error@example.com"
165+
to_email: "error@example.com"
166166
subject: An Error Occurred!
167167
level: debug
168168

cookbook/security/api_key_authentication.rst

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ value and then a User object is created::
3737
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
3838
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
3939
use Symfony\Component\Security\Core\Exception\AuthenticationException;
40+
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
4041
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
4142
use Symfony\Component\Security\Core\User\UserProviderInterface;
4243
use Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface;
@@ -80,7 +81,9 @@ value and then a User object is created::
8081
$username = $userProvider->getUsernameForApiKey($apiKey);
8182

8283
if (!$username) {
83-
throw new AuthenticationException(
84+
// CAUTION: this message will be returned to the client
85+
// (so don't put any un-trusted messages / error strings here)
86+
throw new CustomUserMessageAuthenticationException(
8487
sprintf('API Key "%s" does not exist.', $apiKey)
8588
);
8689
}
@@ -101,6 +104,11 @@ value and then a User object is created::
101104
}
102105
}
103106

107+
.. versionadded:: 2.8
108+
The ``CustomUserMessageAuthenticationException`` class is new in Symfony 2.8
109+
and helps you return custom authentication messages. In 2.7 or earlier, throw
110+
an ``AuthenticationException`` or any sub-class (you can still do this in 2.8).
111+
104112
Once you've :ref:`configured <cookbook-security-api-key-config>` everything,
105113
you'll be able to authenticate by adding an apikey parameter to the query
106114
string, like ``http://example.com/admin/foo?apikey=37b51d194a7513e45b56f6524f2d51f2``.
@@ -291,7 +299,11 @@ you can use to create an error ``Response``.
291299
292300
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
293301
{
294-
return new Response("Authentication Failed.", 403);
302+
return new Response(
303+
// this contains information about *why* authentication failed
304+
// use it, or return your own message
305+
strtr($exception->getMessageKey(), $exception->getMessageData())
306+
, 403)
295307
}
296308
}
297309
@@ -543,7 +555,8 @@ to see if the stored token has a valid User object that can be used::
543555
}
544556

545557
if (!$username) {
546-
throw new AuthenticationException(
558+
// this message will be returned to the client
559+
throw new CustomUserMessageAuthenticationException(
547560
sprintf('API Key "%s" does not exist.', $apiKey)
548561
);
549562
}

cookbook/security/custom_password_authenticator.rst

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ the user::
3939
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
4040
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
4141
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
42-
use Symfony\Component\Security\Core\Exception\AuthenticationException;
42+
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
4343
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
4444
use Symfony\Component\Security\Core\User\UserProviderInterface;
4545
use Symfony\Component\Security\Http\Authentication\SimpleFormAuthenticatorInterface;
@@ -58,15 +58,19 @@ the user::
5858
try {
5959
$user = $userProvider->loadUserByUsername($token->getUsername());
6060
} catch (UsernameNotFoundException $e) {
61-
throw new AuthenticationException('Invalid username or password');
61+
// CAUTION: this message will be returned to the client
62+
// (so don't put any un-trusted messages / error strings here)
63+
throw new CustomUserMessageAuthenticationException('Invalid username or password');
6264
}
6365

6466
$passwordValid = $this->encoder->isPasswordValid($user, $token->getCredentials());
6567

6668
if ($passwordValid) {
6769
$currentHour = date('G');
6870
if ($currentHour < 14 || $currentHour > 16) {
69-
throw new AuthenticationException(
71+
// CAUTION: this message will be returned to the client
72+
// (so don't put any un-trusted messages / error strings here)
73+
throw new CustomUserMessageAuthenticationException(
7074
'You can only log in between 2 and 4!',
7175
100
7276
);
@@ -80,7 +84,9 @@ the user::
8084
);
8185
}
8286

83-
throw new AuthenticationException('Invalid username or password');
87+
// CAUTION: this message will be returned to the client
88+
// (so don't put any un-trusted messages / error strings here)
89+
throw new CustomUserMessageAuthenticationException('Invalid username or password');
8490
}
8591

8692
public function supportsToken(TokenInterface $token, $providerKey)
@@ -95,6 +101,11 @@ the user::
95101
}
96102
}
97103

104+
.. versionadded:: 2.8
105+
The ``CustomUserMessageAuthenticationException`` class is new in Symfony 2.8
106+
and helps you return custom authentication messages. In 2.7 or earlier, throw
107+
an ``AuthenticationException`` or any sub-class (you can still do this in 2.8).
108+
98109
How it Works
99110
------------
100111

cookbook/security/entity_provider.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ the username and then check the password (more on passwords in a moment):
216216
# manager_name: customer
217217
218218
firewalls:
219-
default:
219+
main:
220220
pattern: ^/
221221
http_basic: ~
222222
provider: our_db_provider
@@ -244,7 +244,7 @@ the username and then check the password (more on passwords in a moment):
244244
<entity class="AppBundle:User" property="username" />
245245
</provider>
246246
247-
<firewall name="default" pattern="^/" provider="our_db_provider">
247+
<firewall name="main" pattern="^/" provider="our_db_provider">
248248
<http-basic />
249249
</firewall>
250250
@@ -273,7 +273,7 @@ the username and then check the password (more on passwords in a moment):
273273
),
274274
),
275275
'firewalls' => array(
276-
'default' => array(
276+
'main' => array(
277277
'pattern' => '^/',
278278
'http_basic' => null,
279279
'provider' => 'our_db_provider',

cookbook/security/form_login_setup.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ First, enable form login under your firewall:
2323
# ...
2424
2525
firewalls:
26-
default:
26+
main:
2727
anonymous: ~
2828
form_login:
2929
login_path: /login
@@ -40,7 +40,7 @@ First, enable form login under your firewall:
4040
http://symfony.com/schema/dic/services/services-1.0.xsd">
4141
4242
<config>
43-
<firewall name="default">
43+
<firewall name="main">
4444
<anonymous />
4545
<form-login login-path="/login" check-path="/login_check" />
4646
</firewall>
@@ -52,7 +52,7 @@ First, enable form login under your firewall:
5252
// app/config/security.php
5353
$container->loadFromExtension('security', array(
5454
'firewalls' => array(
55-
'default' => array(
55+
'main' => array(
5656
'anonymous' => null,
5757
'form_login' => array(
5858
'login_path' => '/login',

cookbook/security/remember_me.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ the session lasts using a cookie with the ``remember_me`` firewall option:
1919
# ...
2020
2121
firewalls:
22-
default:
22+
main:
2323
# ...
2424
remember_me:
2525
secret: "%secret%"
@@ -43,7 +43,7 @@ the session lasts using a cookie with the ``remember_me`` firewall option:
4343
<config>
4444
<!-- ... -->
4545
46-
<firewall name="default">
46+
<firewall name="main">
4747
<!-- ... -->
4848
4949
<!-- 604800 is 1 week in seconds -->
@@ -65,7 +65,7 @@ the session lasts using a cookie with the ``remember_me`` firewall option:
6565
// ...
6666
6767
'firewalls' => array(
68-
'default' => array(
68+
'main' => array(
6969
// ...
7070
'remember_me' => array(
7171
'secret' => '%secret%',

0 commit comments

Comments
 (0)