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