@@ -61,19 +61,18 @@ and compare the IP address against a set of blacklisted IP addresses:
61
61
// src/Acme/DemoBundle/Security/Authorization/Voter/ClientIpVoter.php
62
62
namespace Acme\DemoBundle\Security\Authorization\Voter;
63
63
64
- use Symfony\Component\DependencyInjection\ContainerInterface ;
64
+ use Symfony\Component\HttpFoundation\RequestStack ;
65
65
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
66
66
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
67
67
68
68
class ClientIpVoter implements VoterInterface
69
69
{
70
- private $container;
71
-
70
+ protected $requestStack;
72
71
private $blacklistedIp;
73
-
74
- public function __construct(ContainerInterface $container , array $blacklistedIp = array())
72
+
73
+ public function __construct(RequestStack $requestStack , array $blacklistedIp = array())
75
74
{
76
- $this->container = $container ;
75
+ $this->requestStack = $requestStack ;
77
76
$this->blacklistedIp = $blacklistedIp;
78
77
}
79
78
@@ -91,7 +90,7 @@ and compare the IP address against a set of blacklisted IP addresses:
91
90
92
91
public function vote(TokenInterface $token, $object, array $attributes)
93
92
{
94
- $request = $this->container->get('request' );
93
+ $request = $this->requestStack->getCurrentRequest( );
95
94
if (in_array($request->getClientIp(), $this->blacklistedIp)) {
96
95
return VoterInterface::ACCESS_DENIED;
97
96
}
@@ -128,7 +127,7 @@ and tag it as a ``security.voter``:
128
127
services :
129
128
security.access.blacklist_voter :
130
129
class : Acme\DemoBundle\Security\Authorization\Voter\ClientIpVoter
131
- arguments : ["@service_container ", [123.123.123.123, 171.171.171.171]]
130
+ arguments : ["@request_stack ", [123.123.123.123, 171.171.171.171]]
132
131
public : false
133
132
tags :
134
133
- { name: security.voter }
@@ -138,7 +137,7 @@ and tag it as a ``security.voter``:
138
137
<!-- src/Acme/AcmeBundle/Resources/config/services.xml -->
139
138
<service id =" security.access.blacklist_voter"
140
139
class =" Acme\DemoBundle\Security\Authorization\Voter\ClientIpVoter" public =" false" >
141
- <argument type =" service" id =" service_container " strict =" false" />
140
+ <argument type =" service" id =" request_stack " strict =" false" />
142
141
<argument type =" collection" >
143
142
<argument >123.123.123.123</argument >
144
143
<argument >171.171.171.171</argument >
@@ -155,7 +154,7 @@ and tag it as a ``security.voter``:
155
154
$definition = new Definition(
156
155
'Acme\DemoBundle\Security\Authorization\Voter\ClientIpVoter',
157
156
array(
158
- new Reference('service_container '),
157
+ new Reference('request_stack '),
159
158
array('123.123.123.123', '171.171.171.171'),
160
159
),
161
160
);
0 commit comments