@@ -354,13 +354,13 @@ to service ids that do not exist yet: ``wsse.security.authentication.provider``
354
354
355
355
# src/Acme/DemoBundle/Resources/config/services.yml
356
356
services :
357
- wsse.security.authentication.provider :
358
- class : Acme\DemoBundle\Security\Authentication\Provider\WsseProvider
359
- arguments : ['', %kernel.cache_dir%/security/nonces]
357
+ wsse.security.authentication.provider :
358
+ class : Acme\DemoBundle\Security\Authentication\Provider\WsseProvider
359
+ arguments : ['', %kernel.cache_dir%/security/nonces]
360
360
361
- wsse.security.authentication.listener :
362
- class : Acme\DemoBundle\Security\Firewall\WsseListener
363
- arguments : [@security.context, @security.authentication.manager]
361
+ wsse.security.authentication.listener :
362
+ class : Acme\DemoBundle\Security\Firewall\WsseListener
363
+ arguments : [@security.context, @security.authentication.manager]
364
364
365
365
366
366
.. code-block :: xml
@@ -370,19 +370,19 @@ to service ids that do not exist yet: ``wsse.security.authentication.provider``
370
370
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
371
371
xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
372
372
373
- <services >
374
- <service id =" wsse.security.authentication.provider"
375
- class =" Acme\DemoBundle\Security\Authentication\Provider\WsseProvider" public =" false" >
376
- <argument /> <!-- User Provider -->
377
- <argument >%kernel.cache_dir%/security/nonces</argument >
378
- </service >
379
-
380
- <service id =" wsse.security.authentication.listener"
381
- class =" Acme\DemoBundle\Security\Firewall\WsseListener" public =" false" >
382
- <argument type =" service" id =" security.context" />
383
- <argument type =" service" id =" security.authentication.manager" />
384
- </service >
385
- </services >
373
+ <services >
374
+ <service id =" wsse.security.authentication.provider"
375
+ class =" Acme\DemoBundle\Security\Authentication\Provider\WsseProvider" public =" false" >
376
+ <argument /> <!-- User Provider -->
377
+ <argument >%kernel.cache_dir%/security/nonces</argument >
378
+ </service >
379
+
380
+ <service id =" wsse.security.authentication.listener"
381
+ class =" Acme\DemoBundle\Security\Firewall\WsseListener" public =" false" >
382
+ <argument type =" service" id =" security.context" />
383
+ <argument type =" service" id =" security.authentication.manager" />
384
+ </service >
385
+ </services >
386
386
</container >
387
387
388
388
.. code-block :: php
@@ -392,17 +392,22 @@ to service ids that do not exist yet: ``wsse.security.authentication.provider``
392
392
use Symfony\Component\DependencyInjection\Reference;
393
393
394
394
$container->setDefinition('wsse.security.authentication.provider',
395
- new Definition(
396
- 'Acme\DemoBundle\Security\Authentication\Provider\WsseProvider',
397
- array('', '%kernel.cache_dir%/security/nonces')
398
- ));
395
+ new Definition(
396
+ 'Acme\DemoBundle\Security\Authentication\Provider\WsseProvider', array(
397
+ '',
398
+ '%kernel.cache_dir%/security/nonces',
399
+ )
400
+ )
401
+ );
399
402
400
403
$container->setDefinition('wsse.security.authentication.listener',
401
- new Definition(
402
- 'Acme\DemoBundle\Security\Firewall\WsseListener', array(
403
- new Reference('security.context'),
404
- new Reference('security.authentication.manager'))
405
- ));
404
+ new Definition(
405
+ 'Acme\DemoBundle\Security\Firewall\WsseListener', array(
406
+ new Reference('security.context'),
407
+ new Reference('security.authentication.manager'),
408
+ )
409
+ )
410
+ );
406
411
407
412
Now that your services are defined, tell your security context about your
408
413
factory. Factories must be included in an individual configuration file,
@@ -435,6 +440,20 @@ factory service, tagged as ``security.listener.factory``:
435
440
</services >
436
441
</container >
437
442
443
+ .. code-block :: php
444
+
445
+ // src/Acme/DemoBundle/Resources/config/security_factories.php
446
+ use Symfony\Component\DependencyInjection\Definition;
447
+ use Symfony\Component\DependencyInjection\Reference;
448
+
449
+ $definition = new Definition('Acme\DemoBundle\DependencyInjection\Security\Factory\WsseFactory', array(
450
+ '',
451
+ '%kernel.cache_dir%/security/nonces',
452
+ ));
453
+ $definition->addTag('security.listener.factory');
454
+
455
+ $container->setDefinition('security.authentication.factory.wsse', $definition);
456
+
438
457
Now, import the factory configuration via the the ``factories `` key in your
439
458
security configuration:
440
459
@@ -467,13 +486,36 @@ security configuration:
467
486
468
487
You are finished! You can now define parts of your app as under WSSE protection.
469
488
470
- .. code -block :: yaml
489
+ .. configuration -block ::
471
490
472
- security :
473
- firewalls :
474
- wsse_secured :
475
- pattern : /api/.*
476
- wsse : true
491
+ .. code-block :: yaml
492
+
493
+ security :
494
+ firewalls :
495
+ wsse_secured :
496
+ pattern : /api/.*
497
+ wsse : true
498
+
499
+ .. code-block :: xml
500
+
501
+ <config >
502
+ <firewall name =" wsse_secured"
503
+ pattern =" /api/.*"
504
+ wsse =" true"
505
+ />
506
+ </config >
507
+
508
+ .. code-block :: php
509
+
510
+ $container->loadFromExtension('security', array(
511
+ 'firewalls' => array(
512
+ 'wsse_secured' => array(
513
+ 'pattern' => '/api/.*',
514
+ 'wsse' => true,
515
+ ),
516
+ ),
517
+ ));
518
+
477
519
478
520
Congratulations! You have written your very own custom security authentication
479
521
provider!
@@ -546,13 +588,38 @@ in order to put it to use.
546
588
The lifetime of each wsse request is now configurable, and can be
547
589
set to any desirable value per firewall.
548
590
549
- .. code-block :: yaml
591
+ .. configuration-block ::
592
+
593
+ .. code-block :: yaml
594
+
595
+ security :
596
+ firewalls :
597
+ wsse_secured :
598
+ pattern : /api/.*
599
+ wsse : { lifetime: 30 }
600
+
601
+ .. code-block :: xml
602
+
603
+ <config >
604
+ <firewall name =" wsse_secured"
605
+ pattern =" /api/.*"
606
+ >
607
+ <wsse lifetime =" 30" />
608
+ </firewall >
609
+ </config >
550
610
551
- security :
552
- firewalls :
553
- wsse_secured :
554
- pattern : /api/.*
555
- wsse : { lifetime: 30 }
611
+ .. code-block :: php
612
+
613
+ $container->loadFromExtension('security', array(
614
+ 'firewalls' => array(
615
+ 'wsse_secured' => array(
616
+ 'pattern' => '/api/.*',
617
+ 'wsse' => array(
618
+ 'lifetime' => 30,
619
+ ),
620
+ ),
621
+ ),
622
+ ));
556
623
557
624
The rest is up to you! Any relevant configuration items can be defined
558
625
in the factory and consumed or passed to the other classes in the container.
0 commit comments