Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[SecurityBundle] Method to retrieve firewall config by name #20585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add a method to retrieve firewall config by name
  • Loading branch information
julienfalque committed Nov 21, 2016
commit 56664f738c7514d601b01571b46f7d69ecb72dd8
18 changes: 18 additions & 0 deletions 18 src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ public function getFirewallConfig(Request $request)
return $context->getConfig();
}

/**
* @param string $name
*
* @throws \OutOfBoundsException
*
* @return FirewallConfig
*/
public function getFirewallConfigByName($name)
{
$contextId = 'security.firewall.map.context.'.$name;

if (!array_key_exists($contextId, $this->map)) {
throw new \OutOfBoundsException(sprintf('The firewall "%s" does not exist.', $name));
}

return $this->container->get($contextId)->getConfig();
}

private function getFirewallContext(Request $request)
{
if ($this->contexts->contains($request)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\SecurityBundle\Tests\Security;

use Symfony\Bundle\SecurityBundle\Security\FirewallConfig;
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;

class FirewallMapTest extends \PHPUnit_Framework_TestCase
{
public function testGetFirewallConfigByName()
{
$config = new FirewallConfig('foo', 'bar', 'baz');

$context = $this->getMockBuilder('Symfony\Bundle\SecurityBundle\Security\FirewallContext')
->disableOriginalConstructor()
->getMock()
;
$context
->expects($this->once())
->method('getConfig')
->will($this->returnValue($config))
;

$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container
->expects($this->once())
->method('get')
->with($this->equalTo('security.firewall.map.context.foo'))
->will($this->returnValue($context))
;

$map = new FirewallMap($container, array(
'security.firewall.map.context.foo' => $this->getMock('Symfony\Component\HttpFoundation\RequestMatcher'),
'security.firewall.map.context.bar' => $this->getMock('Symfony\Component\HttpFoundation\RequestMatcher'),
));

$this->assertSame($config, $map->getFirewallConfigByName('foo'));
}

/**
* @expectedException \OutOfBoundsException
*/
public function testGetFirewallConfigByNameWithUnknownName()
{
$map = new FirewallMap(
$this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'),
array()
);

$map->getFirewallConfigByName('foo');
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.