@@ -22,7 +22,7 @@ sections:
2222
2323These are followed by a number of small (but still captivating) sections,
2424like :ref: `logging out <book-security-logging-out >` and
25- :ref : `encoding user passwords <security-encoding-password >`.
25+ :doc : `encoding user passwords </ security/password_encoding >`.
2626
2727.. _book-security-firewalls :
2828
@@ -591,7 +591,7 @@ It will give you something like this:
591591 Everything will now work exactly like before. But if you have dynamic users
592592(e.g. from a database), how can you programmatically encode the password
593593before inserting them into the database? Don't worry, see
594- :ref: ` security-encoding-password ` for details.
594+ :doc: ` / security/password_encoding ` for details.
595595
596596.. tip ::
597597
@@ -1216,48 +1216,6 @@ is defined by the ``target`` parameter above (e.g. the ``homepage``).
12161216 browser cache or restarting your browser usually helps. Some web developer
12171217 tools might be helpful here too.
12181218
1219- .. _`security-encoding-password` :
1220-
1221- Dynamically Encoding a Password
1222- -------------------------------
1223-
1224- .. note ::
1225-
1226- For historical reasons, Symfony uses the term *"password encoding" * when it
1227- should really refer to *"password hashing" *. The "encoders" are in fact
1228- `cryptographic hash functions `_.
1229-
1230- If, for example, you're storing users in the database, you'll need to encode
1231- the users' passwords before inserting them. No matter what algorithm you
1232- configure for your user object, the hashed password can always be determined
1233- in the following way from a controller::
1234-
1235- // whatever *your* User object is
1236- $user = new AppBundle\Entity\User();
1237- $plainPassword = 'ryanpass';
1238- $encoder = $this->container->get('security.password_encoder');
1239- $encoded = $encoder->encodePassword($user, $plainPassword);
1240-
1241- $user->setPassword($encoded);
1242-
1243- .. versionadded :: 2.6
1244- The ``security.password_encoder `` service was introduced in Symfony 2.6.
1245-
1246- In order for this to work, just make sure that you have the encoder for your
1247- user class (e.g. ``AppBundle\Entity\User ``) configured under the ``encoders ``
1248- key in ``app/config/security.yml ``.
1249-
1250- The ``$encoder `` object also has an ``isPasswordValid `` method, which takes
1251- the ``User `` object as the first argument and the plain password to check
1252- as the second argument.
1253-
1254- .. caution ::
1255-
1256- When you allow a user to submit a plaintext password (e.g. registration
1257- form, change password form), you *must * have validation that guarantees
1258- that the password is 4096 characters or fewer. Read more details in
1259- :ref: `How to implement a simple Registration Form <cookbook-registration-password-max >`.
1260-
12611219.. _security-role-hierarchy :
12621220
12631221Hierarchical Roles
@@ -1315,98 +1273,6 @@ In the above configuration, users with ``ROLE_ADMIN`` role will also have the
13151273``ROLE_USER `` role. The ``ROLE_SUPER_ADMIN `` role has ``ROLE_ADMIN ``, ``ROLE_ALLOWED_TO_SWITCH ``
13161274and ``ROLE_USER `` (inherited from ``ROLE_ADMIN ``).
13171275
1318- Stateless Authentication
1319- ------------------------
1320-
1321- By default, Symfony relies on a cookie (the Session) to persist the security
1322- context of the user. But if you use certificates or HTTP authentication for
1323- instance, persistence is not needed as credentials are available for each
1324- request. In that case, and if you don't need to store anything else between
1325- requests, you can activate the stateless authentication (which means that no
1326- cookie will be ever created by Symfony):
1327-
1328- .. configuration-block ::
1329-
1330- .. code-block :: yaml
1331-
1332- # app/config/security.yml
1333- security :
1334- # ...
1335-
1336- firewalls :
1337- main :
1338- http_basic : ~
1339- stateless : true
1340-
1341- .. code-block :: xml
1342-
1343- <!-- app/config/security.xml -->
1344- <?xml version =" 1.0" encoding =" UTF-8" ?>
1345- <srv : container xmlns =" http://symfony.com/schema/dic/security"
1346- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1347- xmlns : srv =" http://symfony.com/schema/dic/services"
1348- xsi : schemaLocation =" http://symfony.com/schema/dic/services
1349- http://symfony.com/schema/dic/services/services-1.0.xsd" >
1350-
1351- <config >
1352- <!-- ... -->
1353-
1354- <firewall name =" main" stateless =" true" >
1355- <http-basic />
1356- </firewall >
1357- </config >
1358- </srv : container >
1359-
1360- .. code-block :: php
1361-
1362- // app/config/security.php
1363- $container->loadFromExtension('security', array(
1364- // ...
1365-
1366- 'firewalls' => array(
1367- 'main' => array('http_basic' => null, 'stateless' => true),
1368- ),
1369- ));
1370-
1371- .. note ::
1372-
1373- If you use a form login, Symfony will create a cookie even if you set
1374- ``stateless `` to ``true ``.
1375-
1376- .. _book-security-checking-vulnerabilities :
1377-
1378- Checking for Known Security Vulnerabilities in Dependencies
1379- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1380-
1381- When using lots of dependencies in your Symfony projects, some of them may
1382- contain security vulnerabilities. That's why Symfony includes a command called
1383- ``security:check `` that checks your ``composer.lock `` file to find any known
1384- security vulnerability in your installed dependencies:
1385-
1386- .. code-block :: bash
1387-
1388- $ php app/console security:check
1389-
1390- A good security practice is to execute this command regularly to be able to
1391- update or replace compromised dependencies as soon as possible. Internally,
1392- this command uses the public `security advisories database `_ published by the
1393- FriendsOfPHP organization.
1394-
1395- .. tip ::
1396-
1397- The ``security:check `` command terminates with a non-zero exit code if
1398- any of your dependencies is affected by a known security vulnerability.
1399- Therefore, you can easily integrate it in your build process.
1400-
1401- .. note ::
1402-
1403- To enable the ``security:check `` command, make sure the
1404- `SensioDistributionBundle `_ is installed.
1405-
1406- .. code-block :: bash
1407-
1408- $ composer require ' sensio/distribution-bundle'
1409-
14101276Final Words
14111277-----------
14121278
@@ -1461,8 +1327,14 @@ Authorization (Denying Access)
14611327 security/securing_services
14621328 security/access_control
14631329
1330+ Other Security Related Topics
1331+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1332+
1333+ .. toctree ::
1334+ :maxdepth:
1335+
1336+ password_encoding
1337+ security_checker
1338+
14641339.. _`frameworkextrabundle documentation` : https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html
1465- .. _`security advisories database` : https://github.com/FriendsOfPHP/security-advisories
1466- .. _`cryptographic hash functions` : https://en.wikipedia.org/wiki/Cryptographic_hash_function
14671340.. _`HWIOAuthBundle` : https://github.com/hwi/HWIOAuthBundle
1468- .. _`SensioDistributionBundle` : https://packagist.org/packages/sensio/distribution-bundle
0 commit comments