Skip to content

Commit

Permalink
[SecurityBundle] added validation for check paths
Browse files Browse the repository at this point in the history
  • Loading branch information
schmittjoh committed Jun 1, 2011
1 parent d2fa6c3 commit 6f8871d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Bundle\SecurityBundle\DependencyInjection;

use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\ConfigurationInterface;
Expand Down Expand Up @@ -242,16 +244,44 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
->end()
;

$abstractFactoryKeys = array();
foreach ($factories as $factoriesAtPosition) {
foreach ($factoriesAtPosition as $factory) {
$name = str_replace('-', '_', $factory->getKey());
$factoryNode = $firewallNodeBuilder->arrayNode($name)
->canBeUnset()
;

if ($factory instanceof AbstractFactory) {
$abstractFactoryKeys[] = str_replace('-', '_', $factory->getKey());
}

$factory->addConfiguration($factoryNode);
}
}

// check for unreachable check paths
$firewallNodeBuilder
->end()
->validate()
->ifTrue(function($v) {
return true === $v['security'] && isset($v['pattern']) && !isset($v['request_matcher']);
})
->then(function($firewall) use($abstractFactoryKeys) {
foreach ($abstractFactoryKeys as $k) {
if (!isset($firewall[$k]['check_path'])) {
continue;
}

if (!preg_match('#'.$firewall['pattern'].'#', $firewall[$k]['check_path'])) {
throw new \Exception(sprintf('The check_path "%s" for login method "%s" is not matched by the firewall pattern "%s".', $firewall[$k]['check_path'], $k, $firewall['pattern']));
}
}

return $firewall;
})
->end()
;
}

private function addProvidersSection(ArrayNodeDefinition $rootNode)
Expand Down
Expand Up @@ -12,9 +12,7 @@
namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory;

use Symfony\Component\Config\Definition\Builder\NodeDefinition;

use Symfony\Component\DependencyInjection\DefinitionDecorator;

use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down
Expand Up @@ -387,7 +387,7 @@ private function createAuthenticationListeners($container, $id, $firewall, &$aut
}

if (false === $hasListeners) {
throw new \LogicException(sprintf('No authentication listener registered for pattern "%s".', isset($firewall['pattern']) ? $firewall['pattern'] : ''));
throw new \LogicException(sprintf('No authentication listener registered for firewall "%s".', $id));
}

return array($listeners, $defaultEntryPoint);
Expand Down
Expand Up @@ -39,10 +39,14 @@ public function __construct(NodeDefinition $node)
*
* @return ExprBuilder
*/
public function always()
public function always(\Closure $then = null)
{
$this->ifPart = function($v) { return true; };

if (null !== $then) {
$this->thenPart = $then;
}

return $this;
}

Expand Down

0 comments on commit 6f8871d

Please sign in to comment.