Skip to content

Commit 77555a6

Browse files
committed
[#5486] Even more code block improvements
1 parent b787249 commit 77555a6

13 files changed

+117
-94
lines changed

cookbook/security/access_control.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ pattern so that it is only accessible by requests from the local server itself:
193193
<!-- ... -->
194194
<rule path="^/internal"
195195
role="IS_AUTHENTICATED_ANONYMOUSLY"
196-
ips="127.0.0.1, ::1" />
196+
ips="127.0.0.1, ::1"
197+
/>
198+
197199
<rule path="^/internal" role="ROLE_NO_ACCESS" />
198200
</config>
199201
</srv:container>
@@ -269,7 +271,8 @@ the user will be redirected to ``https``:
269271
270272
<rule path="^/cart/checkout"
271273
role="IS_AUTHENTICATED_ANONYMOUSLY"
272-
requires-channel="https" />
274+
requires-channel="https"
275+
/>
273276
</srv:container>
274277
275278
.. code-block:: php

cookbook/security/acl.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ First, you need to configure the connection the ACL system is supposed to use:
7070
<config>
7171
<!-- ... -->
7272
73-
<acl>
74-
<connection>default</connection>
75-
</acl>
73+
<acl connection="default" />
7674
</config>
7775
</srv:container>
7876

cookbook/security/csrf_in_login_form.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ After this, you have protected your login form against CSRF attacks.
156156
<firewall name="secured_area">
157157
<!-- ... -->
158158
<form-login csrf-parameter="_csrf_security_token"
159-
intention="a_private_string" />
159+
intention="a_private_string"
160+
/>
160161
</firewall>
161162
</config>
162163
</srv:container>

cookbook/security/custom_authentication_provider.rst

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,17 @@ to service ids that do not exist yet: ``wsse.security.authentication.provider``
423423
424424
<services>
425425
<service id="wsse.security.authentication.provider"
426-
class="AppBundle\Security\Authentication\Provider\WsseProvider" public="false">
426+
class="AppBundle\Security\Authentication\Provider\WsseProvider"
427+
public="false"
428+
>
427429
<argument /> <!-- User Provider -->
428430
<argument>%kernel.cache_dir%/security/nonces</argument>
429431
</service>
430432
431433
<service id="wsse.security.authentication.listener"
432434
class="AppBundle\Security\Firewall\WsseListener"
433-
public="false">
434-
435+
public="false"
436+
>
435437
<argument type="service" id="security.context" />
436438
<argument type="service" id="security.authentication.manager" />
437439
</service>
@@ -444,29 +446,25 @@ to service ids that do not exist yet: ``wsse.security.authentication.provider``
444446
use Symfony\Component\DependencyInjection\Definition;
445447
use Symfony\Component\DependencyInjection\Reference;
446448
447-
$container
448-
->setDefinition('wsse.security.authentication.provider',
449-
new Definition(
450-
'AppBundle\Security\Authentication\Provider\WsseProvider', array(
451-
'', // User Provider
452-
'%kernel.cache_dir%/security/nonces',
453-
)
454-
)
449+
$definition = new Definition(
450+
'AppBundle\Security\Authentication\Provider\WsseProvider',
451+
array(
452+
'', // User Provider
453+
'%kernel.cache_dir%/security/nonces',
455454
)
456-
->setPublic(false)
457-
;
458-
459-
$container
460-
->setDefinition('wsse.security.authentication.listener',
461-
new Definition(
462-
'AppBundle\Security\Firewall\WsseListener', array(
463-
new Reference('security.context'),
464-
new Reference('security.authentication.manager'),
465-
)
466-
)
455+
);
456+
$definition->setPublic(false);
457+
$container->setDefinition('wsse.security.authentication.provider', $definition)
458+
459+
$definition = new Definition(
460+
'AppBundle\Security\Firewall\WsseListener',
461+
array(
462+
new Reference('security.context'),
463+
new Reference('security.authentication.manager'),
467464
)
468-
->setPublic(false)
469-
;
465+
);
466+
$definition->setPublic(false);
467+
$container->setDefinition('wsse.security.authentication.listener', $definition);
470468
471469
Now that your services are defined, tell your security context about your
472470
factory in your bundle class:
@@ -524,7 +522,8 @@ You are finished! You can now define parts of your app as under WSSE protection.
524522
name="wsse_secured"
525523
pattern="^/api/"
526524
stateless="true"
527-
wsse="true" />
525+
wsse="true"
526+
/>
528527
</config>
529528
</srv:container>
530529

cookbook/security/custom_provider.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ Now you make the user provider available as a service:
191191
192192
<services>
193193
<service id="webservice_user_provider"
194-
class="Acme\WebserviceUserBundle\Security\User\WebserviceUserProvider" />
194+
class="Acme\WebserviceUserBundle\Security\User\WebserviceUserProvider"
195+
/>
195196
</services>
196197
</container>
197198
@@ -294,7 +295,8 @@ users, e.g. by filling in a login form. You can do this by adding a line to the
294295
<!-- ... -->
295296
296297
<encoder class="Acme\WebserviceUserBundle\Security\User\WebserviceUser"
297-
algorithm="sha512" />
298+
algorithm="sha512"
299+
/>
298300
</config>
299301
</srv:container>
300302
@@ -366,7 +368,8 @@ options, the password may be encoded multiple times and encoded to base64.
366368
<encoder class="Acme\WebserviceUserBundle\Security\User\WebserviceUser"
367369
algorithm="sha512"
368370
encode-as-base64="false"
369-
iterations="1" />
371+
iterations="1"
372+
/>
370373
</config>
371374
</srv:container>
372375

cookbook/security/entity_provider.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ the username and then check the password (more on passwords in a moment):
239239
<!-- ... -->
240240
241241
<provider name="our_db_provider">
242-
<!-- if you're using multiple entity managers -->
243-
<!-- manager-name="customer" -->
242+
<!-- if you're using multiple entity managers, add:
243+
manager-name="customer" -->
244244
<entity class="AppBundle:User" property="username" />
245245
</provider>
246246

cookbook/security/force_https.rst

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -59,49 +59,49 @@ role:
5959

6060
.. configuration-block::
6161

62-
.. code-block:: yaml
63-
64-
# app/config/security.yml
65-
66-
security:
67-
# ...
68-
69-
access_control:
70-
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
71-
72-
.. code-block:: xml
73-
74-
<!-- app/config/security.xml -->
75-
<?xml version="1.0" encoding="UTF-8"?>
76-
<srv:container xmlns="http://symfony.com/schema/dic/security"
77-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
78-
xmlns:srv="http://symfony.com/schema/dic/services"
79-
xsi:schemaLocation="http://symfony.com/schema/dic/services
80-
http://symfony.com/schema/dic/services/services-1.0.xsd">
81-
82-
<config>
83-
<!-- ... -->
84-
85-
<rule path="^/login"
86-
role="IS_AUTHENTICATED_ANONYMOUSLY"
87-
requires_channel="https" />
88-
</config>
89-
</srv:container>
90-
91-
.. code-block:: php
92-
93-
// app/config/security.php
94-
$container->loadFromExtension('security', array(
95-
// ...
96-
97-
'access_control' => array(
98-
array(
99-
'path' => '^/login',
100-
'role' => 'IS_AUTHENTICATED_ANONYMOUSLY',
101-
'requires_channel' => 'https',
102-
),
62+
.. code-block:: yaml
63+
64+
# app/config/security.yml
65+
security:
66+
# ...
67+
68+
access_control:
69+
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
70+
71+
.. code-block:: xml
72+
73+
<!-- app/config/security.xml -->
74+
<?xml version="1.0" encoding="UTF-8"?>
75+
<srv:container xmlns="http://symfony.com/schema/dic/security"
76+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
77+
xmlns:srv="http://symfony.com/schema/dic/services"
78+
xsi:schemaLocation="http://symfony.com/schema/dic/services
79+
http://symfony.com/schema/dic/services/services-1.0.xsd">
80+
81+
<config>
82+
<!-- ... -->
83+
84+
<rule path="^/login"
85+
role="IS_AUTHENTICATED_ANONYMOUSLY"
86+
requires_channel="https"
87+
/>
88+
</config>
89+
</srv:container>
90+
91+
.. code-block:: php
92+
93+
// app/config/security.php
94+
$container->loadFromExtension('security', array(
95+
// ...
96+
97+
'access_control' => array(
98+
array(
99+
'path' => '^/login',
100+
'role' => 'IS_AUTHENTICATED_ANONYMOUSLY',
101+
'requires_channel' => 'https',
103102
),
104-
));
103+
),
104+
));
105105
106106
It is also possible to specify using HTTPS in the routing configuration,
107107
see :doc:`/cookbook/routing/scheme` for more details.

cookbook/security/form_login_setup.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ for the login page:
456456
<firewall name="login_firewall" pattern="^/login$">
457457
<anonymous />
458458
</firewall>
459+
459460
<firewall name="secured_area" pattern="^/">
460461
<form-login />
461462
</firewall>

cookbook/security/impersonating_user.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,23 @@ how to change the sticky locale:
191191
.. code-block:: xml
192192
193193
<!-- app/config/services.xml -->
194-
<service id="app.switch_user_listener" class="AppBundle\EventListener\SwitchUserListener">
195-
<tag name="kernel.event_listener" event="security.switch_user" method="onSwitchUser" />
196-
</service>
194+
<?xml version="1.0" encoding="UTF-8" ?>
195+
<container xmlns="http://symfony.com/schema/dic/services"
196+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
197+
xsi:schemaLocation="http://symfony.com/schema/dic/services
198+
http://symfony.com/schema/dic/services/services-1.0.xsd"
199+
>
200+
<services>
201+
<service id="app.switch_user_listener"
202+
class="AppBundle\EventListener\SwitchUserListener"
203+
>
204+
<tag name="kernel.event_listener"
205+
event="security.switch_user"
206+
method="onSwitchUser"
207+
/>
208+
</service>
209+
</services>
210+
</container>
197211
198212
.. code-block:: php
199213

cookbook/security/multiple_user_providers.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ a new provider that chains the two together:
4141
<provider>user_db</provider>
4242
</chain>
4343
</provider>
44+
4445
<provider name="in_memory">
4546
<memory>
4647
<user name="foo" password="test" />
4748
</memory>
4849
</provider>
50+
4951
<provider name="user_db">
5052
<entity class="Acme\UserBundle\Entity\User" property="username" />
5153
</provider>

cookbook/security/remember_me.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ the session lasts using a cookie with the ``remember_me`` firewall option:
4848
4949
<!-- 604800 is 1 week in seconds -->
5050
<remember-me
51-
key = "%secret%"
52-
lifetime = "604800"
53-
path = "/" />
51+
key="%secret%"
52+
lifetime="604800"
53+
path="/" />
5454
<!-- by default, the feature is enabled by checking a checkbox
5555
in the login form (see below), add always-remember-me="true"
5656
to always enable it. -->

cookbook/security/securing_services.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Then in your service configuration, you can inject the service:
8686
8787
<services>
8888
<service id="newsletter_manager" class="AppBundle\Newsletter\NewsletterManager">
89-
<argument type="service" id="security.context"/>
89+
<argument type="service" id="security.context" />
9090
</service>
9191
</services>
9292
</container>
@@ -241,7 +241,8 @@ documentation.
241241
<container xmlns="http://symfony.com/schema/dic/services"
242242
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
243243
xmlns:jms-security-extra="http://example.org/schema/dic/jms_security_extra"
244-
xsi:schemaLocation="http://www.example.com/symfony/schema/ http://www.example.com/symfony/schema/hello-1.0.xsd">
244+
xsi:schemaLocation="http://symfony.com/schema/dic/services
245+
http://symfony.com/schema/dic/services/services-1.0.xsd">
245246
246247
<!-- ... -->
247248
<jms-security-extra:config secure-all-services="true" />

cookbook/security/voters.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,16 @@ and tag it with ``security.voter``:
198198
.. code-block:: php
199199
200200
// app/config/services.php
201-
$container
202-
->register(
203-
'security.access.post_voter',
204-
'AppBundle\Security\Authorization\Voter\PostVoter'
205-
)
201+
use Symfony\Component\DependencyInjection\Definition;
202+
203+
$definition = new Definition('AppBundle\Security\Authorization\Voter\PostVoter');
204+
$definition
205+
->setPublic(false)
206206
->addTag('security.voter')
207207
;
208208
209+
$container->setDefinition('security.access.post_voter', $definition);
210+
209211
How to Use the Voter in a Controller
210212
------------------------------------
211213

@@ -283,10 +285,9 @@ security configuration:
283285
xmlns:srv="http://symfony.com/schema/dic/services"
284286
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
285287
xsi:schemaLocation="http://symfony.com/schema/dic/services
286-
http://symfony.com/schema/dic/services/services-1.0.xsd
287-
http://symfony.com/schema/dic/security
288-
http://symfony.com/schema/dic/security/security-1.0.xsd"
288+
http://symfony.com/schema/dic/services/services-1.0.xsd"
289289
>
290+
290291
<config>
291292
<access-decision-manager strategy="unanimous">
292293
</config>

0 commit comments

Comments
 (0)