@@ -25,7 +25,7 @@ How Symfony Uses Voters
25
25
26
26
In order to use voters, you have to understand how Symfony works with them.
27
27
All voters are called each time you use the ``isGranted() `` method on Symfony's
28
- authorization checker (i.e. the ``security.authorization_checker `` service). Each
28
+ authorization checker (i.e. the ``security.authorization_checker `` service). Each
29
29
one decides if the current user should have access to some resource.
30
30
31
31
Ultimately, Symfony uses one of three different approaches on what to do
@@ -116,18 +116,26 @@ the security layer.
116
116
To recap, here's what's expected from the three abstract methods:
117
117
118
118
The :method: `Symfony\\ Component\\ Security\\ Core\\ Authorization\\ Voter\\ AbstractVoter::getSupportedClasses `
119
- method tells Symfony that your voter should be called whenever an object of one of the given classes
120
- is passed to `isGranted ` For example, if you return ['\A cme\D emoBundle\M odel\P roduct'],
121
- Symfony will call your voter when a `Product ` object is passed to `isGranted `.
119
+ method tells Symfony that your voter should be called whenever an object of one
120
+ of the given classes is passed to ``isGranted() ``. For example, if you return
121
+ ``array('AppBundle\Model\Product') ``, Symfony will call your voter when a
122
+ ``Product `` object is passed to ``isGranted() ``.
122
123
123
124
The :method: `Symfony\\ Component\\ Security\\ Core\\ Authorization\\ Voter\\ AbstractVoter::getSupportedAttributes `
124
- method tells Symfony that your voter should be called whenever one of these strings is passes as the
125
- first argument to `isGranted `. For example, if you return `array('CREATE', 'READ') `, then
126
- Symfony will call your voter when one of these is passed to `isGranted `.
125
+ method tells Symfony that your voter should be called whenever one of these
126
+ strings is passed as the first argument to ``isGranted() ``. For example, if you
127
+ return ``array('CREATE', 'READ') ``, then Symfony will call your voter when one
128
+ of these is passed to ``isGranted() ``.
127
129
128
130
The :method: `Symfony\\ Component\\ Security\\ Core\\ Authorization\\ Voter\\ AbstractVoter::isGranted `
129
131
method must implement the business logic that verifies whether or not a given
130
- user is allowed access to a given attribute on a given object. This method must return a boolean.
132
+ user is allowed access to a given attribute (e.g. ``CREATE `` or ``READ ``) on a
133
+ given object. This method must return a boolean.
134
+
135
+ .. note ::
136
+
137
+ Currently, to use the ``AbstractVoter `` base class, you must be creating a
138
+ voter where an object is always passed to ``isGranted() ``.
131
139
132
140
Declaring the Voter as a Service
133
141
--------------------------------
@@ -206,7 +214,8 @@ from the authorization checker is called.
206
214
}
207
215
208
216
.. versionadded :: 2.6
209
- The ``security.authorization_checker `` service was introduced in Symfony 2.6. Prior
210
- to Symfony 2.6, you had to use the ``isGranted() `` method of the ``security.context `` service.
217
+ The ``security.authorization_checker `` service was introduced in Symfony 2.6.
218
+ Prior to Symfony 2.6, you had to use the ``isGranted() `` method of the
219
+ ``security.context `` service.
211
220
212
221
It's that easy!
0 commit comments