8000 merged branch kriswallsmith/security/access-map-interface (PR #3374) · symfony/symfony@df91627 · GitHub
[go: up one dir, main page]

Skip to content

Commit df91627

Browse files
committed
merged branch kriswallsmith/security/access-map-interface (PR #3374)
Commits ------- eb7aa1b [SecurityBundle] added interface to compiler 1e8236c [Security] added AccessMapInterface Discussion ---------- [Security] added AccessMapInterface I am optimizing the security layer at OpenSky and need to make this class smarter instead of running through all of the many access rules for each request. I would like to do this by creating a delegating access map composed of many inner maps and would rather implement an interface than extending a core class without using any of its functionality. ``` Bug fix: no Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: - Todo: - ``` --------------------------------------------------------------------------- by kriswallsmith at 2012-02-15T22:31:36Z For conversation: https://gist.github.com/1839490 --------------------------------------------------------------------------- by jwage at 2012-02-16T03:57:09Z :+1:
2 parents a5013bc + eb7aa1b commit df91627

File tree

7 files changed

+47
-13
lines changed
  • tests/Symfony/Tests/Component/Security/Http/Firewall
  • 7 files changed

    +47
    -13
    lines changed

    src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -171,6 +171,7 @@ private function createAuthorization($config, ContainerBuilder $container)
    171171
    }
    172172

    173173
    $this->addClassesToCompile(array(
    174+
    'Symfony\\Component\\Security\\Http\\AccessMapInterface',
    174175
    'Symfony\\Component\\Security\\Http\\AccessMap',
    175176
    ));
    176177

    src/Symfony/Component/Security/Http/AccessMap.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -20,7 +20,7 @@
    2020
    *
    2121
    * @author Fabien Potencier <fabien@symfony.com>
    2222
    */
    23-
    class AccessMap
    23+
    class AccessMap implements AccessMapInterface
    2424
    {
    2525
    private $map = array();
    2626

    Lines changed: 33 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,33 @@
    1+
    <?php
    2+
    3+
    /*
    4+
    * This file is part of the Symfony package.
    5+
    *
    6+
    * (c) Fabien Potencier <fabien@symfony.com>
    7+
    *
    8+
    * For the full copyright and license information, please view the LICENSE
    9+
    * file that was distributed with this source code.
    10+
    */
    11+
    12+
    namespace Symfony\Component\Security\Http;
    13+
    14+
    use Symfony\Component\HttpFoundation\Request;
    15+
    16+
    /**
    17+
    * AccessMap allows configuration of different access control rules for
    18+
    * specific parts of the website.
    19+
    *
    20+
    * @author Fabien Potencier <fabien@symfony.com>
    21+
    * @author Kris Wallsmith <kris@symfony.com>
    22+
    */
    23+
    interface AccessMapInterface
    24+
    {
    25+
    /**
    26+
    * Returns security attributes and required channel for the supplied request.
    27+
    *
    28+
    * @param Request $request The current request
    29+
    *
    30+
    * @return array A tuple of security attributes and the required channel
    31+
    */
    32+
    function getPatterns(Request $request);
    33+
    }

    src/Symfony/Component/Security/Http/Firewall/AccessListener.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -13,7 +13,7 @@
    1313

    1414
    use Symfony\Component\Security\Core\SecurityContextInterface;
    1515
    use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
    16-
    use Symfony\Component\Security\Http\AccessMap;
    16+
    use Symfony\Component\Security\Http\AccessMapInterface;
    1717
    use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
    1818
    use Symfony\Component\HttpKernel\Log\LoggerInterface;
    1919
    use Symfony\Component\HttpKernel\Event\GetResponseEvent;
    @@ -33,7 +33,7 @@ class AccessListener implements ListenerInterface
    3333
    private $authManager;
    3434
    private $logger;
    3535

    36-
    public function __construct(SecurityContextInterface $context, AccessDecisionManagerInterface $accessDecisionManager, AccessMap $map, AuthenticationManagerInterface $authManager, LoggerInterface $logger = null)
    36+
    public function __construct(SecurityContextInterface $context, AccessDecisionManagerInterface $accessDecisionManager, AccessMapInterface $map, AuthenticationManagerInterface $authManager, LoggerInterface $logger = null)
    3737
    {
    3838
    $this->context = $context;
    3939
    $this->accessDecisionManager = $accessDecisionManager;

    src/Symfony/Component/Security/Http/Firewall/ChannelListener.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -11,7 +11,7 @@
    1111

    1212
    namespace Symfony\Component\Security\Http\Firewall;
    1313

    14-
    use Symfony\Component\Security\Http\AccessMap;
    14+
    use Symfony\Component\Security\Http\AccessMapInterface;
    1515
    use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
    1616
    use Symfony\Component\HttpKernel\Log\LoggerInterface;
    1717
    use Symfony\Component\HttpKernel\Event\GetResponseEvent;
    @@ -28,7 +28,7 @@ class ChannelListener implements ListenerInterface
    2828
    private $authenticationEntryPoint;
    2929
    private $logger;
    3030

    31-
    public function __construct(AccessMap $map, AuthenticationEntryPointInterface $authenticationEntryPoint, LoggerInterface $logger = null)
    31+
    public function __construct(AccessMapInterface $map, AuthenticationEntryPointInterface $authenticationEntryPoint, LoggerInterface $logger = null)
    3232
    {
    3333
    $this->map = $map;
    3434
    $this->authenticationEntryPoint = $authenticationEntryPoint;

    tests/Symfony/Tests/Component/Security/Http/Firewall/AccessListenerTest.php

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -13,7 +13,7 @@ public function testHandleWhenTheAccessDecisionManagerDecidesToRefuseAccess()
    1313
    {
    1414
    $request = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false);
    1515

    16-
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMap');
    16+
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMapInterface');
    1717
    $accessMap
    1818
    ->expects($this->any())
    1919
    ->method('getPatterns')
    @@ -64,7 +64,7 @@ public function testHandleWhenTheTokenIsNotAuthenticated()
    6464
    {
    6565
    $request = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false);
    6666

    67-
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMap');
    67+
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMapInterface');
    6868
    $accessMap
    6969
    ->expects($this->any())
    7070
    ->method('getPatterns')
    @@ -135,7 +135,7 @@ public function testHandleWhenThereIsNoAccessMapEntryMatchingTheRequest()
    135135
    {
    136136
    $request = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false);
    137137

    138-
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMap');
    138+
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMapInterface');
    139139
    $accessMap
    140140
    ->expects($this->any())
    141141
    ->method('getPatterns')
    @@ -188,7 +188,7 @@ public function testHandleWhenTheSecurityContextHasNoToken()
    188188
    $listener = new AccessListener(
    189189
    $context,
    190190
    $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface'),
    191-
    $this->getMock('Symfony\Component\Security\Http\AccessMap'),
    191+
    $this->getMock('Symfony\Component\Security\Http\AccessMapInterface'),
    192192
    $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')
    193193
    );
    194194

    tests/Symfony/Tests/Component/Security/Http/Firewall/ChannelListenerTest.php

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -17,7 +17,7 @@ public function testHandleWithNotSecuredRequestAndHttpChannel()
    1717
    ->will($this->returnValue(false))
    1818
    ;
    1919

    20-
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMap');
    20+
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMapInterface');
    2121
    $accessMap
    2222
    ->expects($this-> E2ED ;any())
    2323
    ->method('getPatterns')
    @@ -55,7 +55,7 @@ public function testHandleWithSecuredRequestAndHttpsChannel()
    5555
    ->will($this->returnValue(true))
    5656
    ;
    5757

    58-
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMap');
    58+
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMapInterface');
    5959
    $accessMap
    6060
    ->expects($this->any())
    6161
    ->method('getPatterns')
    @@ -95,7 +95,7 @@ public function testHandleWithNotSecuredRequestAndHttpsChannel()
    9595

    9696
    $response = new Response();
    9797

    98-
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMap');
    98+
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMapInterface');
    9999
    $accessMap
    100100
    ->expects($this->any())
    101101
    ->method('getPatterns')
    @@ -138,7 +138,7 @@ public function testHandleWithSecuredRequestAndHttpChannel()
    138138

    139139
    $response = new Response();
    140140

    141-
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMap');
    141+
    $accessMap = $this->getMock('Symfony\Component\Security\Http\AccessMapInterface');
    142142
    $accessMap
    143143
    ->expects($this->any())
    144144
    ->method('getPatterns')

    0 commit comments

    Comments
     (0)
    0