JMSSecurityExtraExtension.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /*
  3. * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. namespace JMS\SecurityExtraBundle\DependencyInjection;
  18. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  19. use Symfony\Component\Config\FileLocator;
  20. use Symfony\Component\Config\Definition\Processor;
  21. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  22. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  23. use Symfony\Component\DependencyInjection\ContainerBuilder;
  24. /**
  25. * JMSSecurityExtraExtension.
  26. *
  27. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  28. */
  29. class JMSSecurityExtraExtension extends Extension
  30. {
  31. public function load(array $configs, ContainerBuilder $container)
  32. {
  33. $processor = new Processor();
  34. $config = $processor->process($this->getConfigTree(), $configs);
  35. $loader = new XmlFileLoader($container, new FileLocator(array(__DIR__.'/../Resources/config/')));
  36. $loader->load('services.xml');
  37. $container->setParameter('security.extra.secure_all_services', $config['secure_all_services']);
  38. if (!$config['secure_controllers']) {
  39. $container->removeDefinition('security.extra.controller_listener');
  40. $this->addClassesToCompile(array(
  41. 'JMS\\SecurityExtraBundle\\Security\\Authorization\\Interception\\MethodInvocation',
  42. 'JMS\\SecurityExtraBundle\\Security\\Authorization\\Interception\\MethodSecurityInterceptor',
  43. 'JMS\\SecurityExtraBundle\\Security\\Authorization\\AfterInvocation\\AfterInvocationManager',
  44. 'JMS\\SecurityExtraBundle\\Security\\Authorization\\AfterInvocation\\AfterInvocationManagerInterface',
  45. 'JMS\\SecurityExtraBundle\\Security\\Authorization\\AfterInvocation\\AfterInvocationProviderInterface',
  46. 'JMS\\SecurityExtraBundle\\Security\\Authorization\\RunAsManager',
  47. 'JMS\\SecurityExtraBundle\\Security\\Authorization\\RunAsManagerInterface',
  48. ));
  49. } else {
  50. $this->addClassesToCompile(array(
  51. 'JMS\\SecurityExtraBundle\\Controller\\ControllerListener',
  52. 'JMS\\SecurityExtraBundle\\Metadata\\Driver\\AnnotationConverter',
  53. 'JMS\\SecurityExtraBundle\\Security\\Authorization\\Interception\\MethodInvocation',
  54. ));
  55. }
  56. if ($config['enable_iddqd_attribute']) {
  57. $container
  58. ->getDefinition('security.extra.iddqd_voter')
  59. ->addTag('security.voter')
  60. ;
  61. // FIXME: Also add an iddqd after invocation provider
  62. }
  63. }
  64. private function getConfigTree()
  65. {
  66. $tb = new TreeBuilder();
  67. return $tb
  68. ->root('jms_security_extra')
  69. ->children()
  70. ->booleanNode('secure_controllers')->defaultTrue()->end()
  71. ->booleanNode('secure_all_services')->defaultFalse()->end()
  72. ->booleanNode('enable_iddqd_attribute')->defaultFalse()->end()
  73. ->end()
  74. ->end()
  75. ->buildTree();
  76. }
  77. }