Initial commit with Symfony 2.1+Vendors
Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\SecurityExtraBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\MainConfiguration as BaseConfiguration;
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
|
||||
/**
|
||||
* Enhances the access_control section configuration.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class AccessControlConfiguration implements ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* Generates the configuration tree builder.
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$tb = new TreeBuilder();
|
||||
$rootNode = $tb->root('security');
|
||||
|
||||
$rootNode
|
||||
->ignoreExtraKeys()
|
||||
->fixXmlConfig('rule', 'access_control')
|
||||
->children()
|
||||
->arrayNode('access_control')
|
||||
->cannotBeOverwritten()
|
||||
->prototype('array')
|
||||
->fixXmlConfig('role')
|
||||
->validate()
|
||||
->always(function($v) {
|
||||
if (!empty($v['roles']) && isset($v['access'])) {
|
||||
throw new \Exception('"roles", and "access" cannot be set at the same time.');
|
||||
}
|
||||
|
||||
if (empty($v['roles'])) {
|
||||
unset($v['roles']);
|
||||
}
|
||||
|
||||
return $v;
|
||||
})
|
||||
->end()
|
||||
->children()
|
||||
->scalarNode('requires_channel')->defaultNull()->end()
|
||||
->scalarNode('path')->defaultNull()->end()
|
||||
->scalarNode('host')->defaultNull()->end()
|
||||
->scalarNode('ip')->defaultNull()->end()
|
||||
->arrayNode('methods')
|
||||
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->arrayNode('roles')
|
||||
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->scalarNode('access')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $tb;
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\SecurityExtraBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Collects after invocation providers.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class AddAfterInvocationProvidersPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('security.access.after_invocation_manager')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$providers = array();
|
||||
foreach (array_keys($container->findTaggedServiceIds('security.after_invocation.provider')) as $id) {
|
||||
if ('security.access.after_invocation.acl_provider' === $id && !$container->has('security.acl.provider')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$providers[] = new Reference($id);
|
||||
}
|
||||
|
||||
$container
|
||||
->getDefinition('security.access.after_invocation_manager')
|
||||
->setArguments(array($providers))
|
||||
;
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\SecurityExtraBundle\DependencyInjection\Compiler;
|
||||
|
||||
use JMS\SecurityExtraBundle\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
|
||||
class AddExpressionCompilersPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('security.expressions.compiler')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$compilerDef = $container->getDefinition('security.expressions.compiler');
|
||||
foreach ($container->findTaggedServiceIds('security.expressions.function_compiler')
|
||||
as $id => $attr) {
|
||||
$compilerDef->addMethodCall('addFunctionCompiler', array(new Reference($id)));
|
||||
}
|
||||
|
||||
foreach ($container->findTaggedServiceIds('security.expressions.type_compiler')
|
||||
as $id => $attr) {
|
||||
$compilerDef->addMethodCall('addTypeCompiler', array(new Reference($id)));
|
||||
}
|
||||
|
||||
$serviceMap = $parameterMap = array();
|
||||
foreach ($container->findTaggedServiceIds('security.expressions.variable') as $id => $attributes) {
|
||||
foreach ($attributes as $attr) {
|
||||
if (!isset($attr['variable']) || (!isset($attr['service']) && !isset($attr['parameter']))) {
|
||||
throw new RuntimeException(sprintf('"variable", and either "service" or "parameter" must be given for tag "security.expressions.variable" for service id "%s".', $id));
|
||||
}
|
||||
|
||||
if (isset($attr['service'])) {
|
||||
$serviceMap[$attr['variable']] = $attr['service'];
|
||||
$container
|
||||
->findDefinition($attr['service'])
|
||||
->setPublic(true)
|
||||
;
|
||||
} else {
|
||||
$parameterMap[$attr['variable']] = $attr['parameter'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$container->getDefinition('security.expressions.variable_compiler')
|
||||
->addMethodCall('setMaps', array($serviceMap, $parameterMap));
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\SecurityExtraBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
|
||||
/**
|
||||
* Collects secured services.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class CollectSecuredServicesPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$securedClasses = array();
|
||||
foreach ($container->findTaggedServiceIds('security.secure_service') as $id => $attr) {
|
||||
$securedClasses[] = $container->getDefinition($id)->getClass();
|
||||
}
|
||||
|
||||
$container
|
||||
->getDefinition('security.access.pointcut')
|
||||
->addMethodCall('setSecuredClasses', array($securedClasses))
|
||||
;
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\SecurityExtraBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
|
||||
class DisableVotersPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if ($container->getParameter('security.role_voter.disabled')) {
|
||||
$container->removeDefinition('security.access.role_hierarchy_voter');
|
||||
$container->removeDefinition('security.access.simple_role_voter');
|
||||
}
|
||||
|
||||
if ($container->getParameter('security.authenticated_voter.disabled')) {
|
||||
$container->removeDefinition('security.access.authenticated_voter');
|
||||
}
|
||||
|
||||
if ($container->hasDefinition('security.acl.voter.basic_permissions')) {
|
||||
if ($container->getParameter('security.acl_voter.disabled')) {
|
||||
$container->removeDefinition('security.acl.voter.basic_permissions');
|
||||
} else {
|
||||
$container->getDefinition('security.acl.voter.basic_permissions')
|
||||
->setClass('JMS\SecurityExtraBundle\Security\Acl\Voter\AclVoter');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace JMS\SecurityExtraBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
|
||||
class IntegrationPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasAlias('security.acl.provider')
|
||||
&& !$container->hasDefinition('security.acl.provider')) {
|
||||
$container->removeDefinition('security.acl.permission_evaluator');
|
||||
}
|
||||
|
||||
if ($container->hasDefinition('security.role_hierarchy')) {
|
||||
$container->getDefinition('security.role_hierarchy')
|
||||
->setPublic(true);
|
||||
}
|
||||
}
|
||||
}
|
64
vendor/jms/security-extra-bundle/JMS/SecurityExtraBundle/DependencyInjection/Configuration.php
vendored
Normal file
64
vendor/jms/security-extra-bundle/JMS/SecurityExtraBundle/DependencyInjection/Configuration.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\SecurityExtraBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$tb = new TreeBuilder();
|
||||
$tb
|
||||
->root('jms_security_extra')
|
||||
->validate()
|
||||
->always(function($v) {
|
||||
if ($v['method_access_control'] && !$v['expressions']) {
|
||||
throw new \Exception('You need to enable expressions if you want to configure method access via the DI config.');
|
||||
}
|
||||
|
||||
return $v;
|
||||
})
|
||||
->end()
|
||||
->children()
|
||||
->booleanNode('secure_all_services')->defaultFalse()->end()
|
||||
->booleanNode('enable_iddqd_attribute')->defaultFalse()->end()
|
||||
->scalarNode('cache_dir')->cannotBeEmpty()->defaultValue('%kernel.cache_dir%/jms_security')->end()
|
||||
->booleanNode('expressions')->defaultFalse()->end()
|
||||
->arrayNode('voters')
|
||||
->addDefaultsIfNotSet()
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->booleanNode('disable_authenticated')->defaultFalse()->end()
|
||||
->booleanNode('disable_role')->defaultFalse()->end()
|
||||
->booleanNode('disable_acl')->defaultFalse()->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('method_access_control')
|
||||
->useAttributeAsKey('pattern')
|
||||
->prototype('scalar')->isRequired()->cannotBeEmpty()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $tb;
|
||||
}
|
||||
}
|
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\SecurityExtraBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
use JMS\SecurityExtraBundle\Exception\RuntimeException;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* JMSSecurityExtraExtension.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class JMSSecurityExtraExtension extends Extension
|
||||
{
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$bundles = $container->getParameter('kernel.bundles');
|
||||
if (!isset($bundles['JMSAopBundle'])) {
|
||||
throw new RuntimeException('The JMSSecurityExtraBundle requires the JMSAopBundle, please make sure to enable it in your AppKernel.');
|
||||
}
|
||||
|
||||
$config = $this->processConfiguration(new Configuration(), $configs);
|
||||
|
||||
$loader = new XmlFileLoader($container, new FileLocator(array(__DIR__.'/../Resources/config/')));
|
||||
$loader->load('services.xml');
|
||||
|
||||
$container->setParameter('security.access.secure_all_services', $config['secure_all_services']);
|
||||
|
||||
$cacheDir = $container->getParameterBag()->resolveValue($config['cache_dir']);
|
||||
if (!is_dir($cacheDir)) {
|
||||
if (false === @mkdir($cacheDir, 0777, true)) {
|
||||
throw new RuntimeException(sprintf('Could not create cache directory "%s".', $cacheDir));
|
||||
}
|
||||
}
|
||||
$container->setParameter('security.extra.cache_dir', $cacheDir);
|
||||
|
||||
if ($config['expressions']) {
|
||||
$loader->load('security_expressions.xml');
|
||||
|
||||
if (!is_dir($cacheDir.'/expressions')) {
|
||||
if (false === @mkdir($cacheDir.'/expressions', 0777, true)) {
|
||||
throw new RuntimeException(sprintf('Could not create cache directory "%s".', $cacheDir.'/expressions'));
|
||||
}
|
||||
}
|
||||
|
||||
$container->getDefinition('security.expressions.voter')
|
||||
->addMethodCall('setCacheDir', array($cacheDir.'/expressions'));
|
||||
}
|
||||
|
||||
$disableAllVoters = !isset($config['voters']);
|
||||
$container->setParameter('security.authenticated_voter.disabled',
|
||||
$disableAllVoters || $config['voters']['disable_authenticated']);
|
||||
$container->setParameter('security.role_voter.disabled',
|
||||
$disableAllVoters || $config['voters']['disable_role']);
|
||||
$container->setParameter('security.acl_voter.disabled',
|
||||
$disableAllVoters || $config['voters']['disable_acl']);
|
||||
|
||||
if ($config['enable_iddqd_attribute']) {
|
||||
$container
|
||||
->getDefinition('security.extra.iddqd_voter')
|
||||
->addTag('security.voter')
|
||||
;
|
||||
|
||||
// FIXME: Also add an iddqd after invocation provider
|
||||
}
|
||||
|
||||
if ($config['method_access_control']) {
|
||||
$driverDef = $container->getDefinition('security.extra.driver_chain');
|
||||
$args = $driverDef->getArguments();
|
||||
array_unshift($args[0], new Reference('security.extra.config_driver'));
|
||||
$driverDef->setArguments($args);
|
||||
|
||||
$container->setParameter('security.access.method_access_control',
|
||||
$config['method_access_control']);
|
||||
}
|
||||
}
|
||||
}
|
130
vendor/jms/security-extra-bundle/JMS/SecurityExtraBundle/DependencyInjection/SecurityExtension.php
vendored
Normal file
130
vendor/jms/security-extra-bundle/JMS/SecurityExtraBundle/DependencyInjection/SecurityExtension.php
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\SecurityExtraBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension as BaseSecurityExtension;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
/**
|
||||
* Enhances the access_control section of the SecurityBundle.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class SecurityExtension extends Extension
|
||||
{
|
||||
private $extension;
|
||||
|
||||
public function __construct(BaseSecurityExtension $extension)
|
||||
{
|
||||
$this->extension = $extension;
|
||||
}
|
||||
|
||||
public function getAlias()
|
||||
{
|
||||
return $this->extension->getAlias();
|
||||
}
|
||||
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->extension->getNamespace();
|
||||
}
|
||||
|
||||
public function getXsdValidationBasePath()
|
||||
{
|
||||
return $this->extension->getXsdValidationBasePath();
|
||||
}
|
||||
|
||||
public function getClassesToCompile()
|
||||
{
|
||||
return array_merge(parent::getClassesToCompile(), $this->extension->getClassesToCompile());
|
||||
}
|
||||
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$parentConfigs = array();
|
||||
|
||||
foreach ($configs as $config) {
|
||||
if (isset($config['rule'])) {
|
||||
unset($config['rule']);
|
||||
}
|
||||
if (isset($config['access_control'])) {
|
||||
unset($config['access_control']);
|
||||
}
|
||||
|
||||
$parentConfigs[] = $config;
|
||||
}
|
||||
$this->extension->load($parentConfigs, $container);
|
||||
|
||||
$config = $this->processConfiguration(new AccessControlConfiguration(), $configs);
|
||||
$this->createAuthorization($config, $container);
|
||||
}
|
||||
|
||||
public function __call($method, array $args)
|
||||
{
|
||||
return call_user_func_array(array($this->extension, $method), $args);
|
||||
}
|
||||
|
||||
private function createAuthorization($config, ContainerBuilder $container)
|
||||
{
|
||||
if (!$config['access_control']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addClassesToCompile(array(
|
||||
'Symfony\\Component\\Security\\Http\\AccessMap',
|
||||
));
|
||||
|
||||
foreach ($config['access_control'] as $access) {
|
||||
$matcher = $this->invokeParent('createRequestMatcher', array(
|
||||
$container,
|
||||
$access['path'],
|
||||
$access['host'],
|
||||
count($access['methods']) === 0 ? null : $access['methods'],
|
||||
$access['ip']
|
||||
));
|
||||
|
||||
if (isset($access['roles'])) {
|
||||
$attributes = $access['roles'];
|
||||
} else {
|
||||
$def = new DefinitionDecorator('security.expressions.expression');
|
||||
$def->addArgument($access['access']);
|
||||
$container->setDefinition($exprId = 'security.expressions.expression.'.sha1($access['access']), $def);
|
||||
|
||||
$attributes = array(new Reference($exprId));
|
||||
}
|
||||
|
||||
$container->getDefinition('security.access_map')
|
||||
->addMethodCall('add', array($matcher, $attributes, $access['requires_channel']));
|
||||
}
|
||||
}
|
||||
|
||||
private function invokeParent($method, array $args = array())
|
||||
{
|
||||
$ref = new \ReflectionMethod($this->extension, $method);
|
||||
$ref->setAccessible(true);
|
||||
|
||||
return $ref->invokeArgs($this->extension, $args);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user