@@ -46,8 +46,10 @@ values:
46
46
* ``VoterInterface::ACCESS_DENIED ``: The user is not allowed to access the application
47
47
48
48
In this example, we will check if the user's IP address matches against a list of
49
- blacklisted addresses. We will return ``VoterInterface::ACCESS_DENIED `` or
50
- ``VoterInterface::ACCESS_GRANTED `` depending on this criteria.
49
+ blacklisted addresses. If the user's IP is blacklisted, we will return
50
+ ``VoterInterface::ACCESS_DENIED ``, otherwise we will return
51
+ ``VoterInterface::ACCESS_ABSTAIN `` as this voter purpose is only to deny users,
52
+ not to grant them.
51
53
52
54
Creating a Custom Voter
53
55
-----------------------
@@ -89,7 +91,7 @@ and compare the IP address against a set of blacklisted IP addresses:
89
91
return VoterInterface::ACCESS_DENIED;
90
92
}
91
93
92
- return VoterInterface::ACCESS_GRANTED ;
94
+ return VoterInterface::ACCESS_ABSTAIN ;
93
95
}
94
96
}
95
97
@@ -155,29 +157,3 @@ and tag it as a "security.voter":
155
157
configuration file (e.g. ``app/config/config.yml ``). For more information
156
158
see :ref: `service-container-imports-directive `. To read more about defining
157
159
services in general, see the :doc: `/book/service_container ` chapter.
158
-
159
- Finally, we need to change the authentication strategy. By default, the
160
- security component calls each voter until one of them grants access to the
161
- user. In our case, we want to force *all * voters to grant the user access
162
- before deciding that the user should actually have access to the application.
163
- To do that, we need to change the strategy by overriding the
164
- ``security.access.decision_manager.strategy `` parameter:
165
-
166
- .. configuration-block ::
167
-
168
- .. code-block :: yaml
169
-
170
- # src/Acme/AcmeBundle/Resources/config/services.yml
171
- parameters :
172
- security.access.decision_manager.strategy : unanimous
173
-
174
- .. code-block :: xml
175
-
176
- <!-- src/Acme/AcmeBundle/Resources/config/services.xml -->
177
- <parameter key =" security.access.decision_manager.strategy" >unanimous</parameter >
178
-
179
- .. code-block :: php
180
-
181
- // src/Acme/AcmeBundle/Resources/config/services.php
182
-
183
- $container->setParameter('security.access.decision_manager.strategy', 'unanimous');
0 commit comments