@@ -39,15 +39,15 @@ role. Before you add security, the class looks something like this:
39
39
// ...
40
40
}
41
41
42
- Your goal is to check the user's role when the ``sendNewsletter() `` method is
43
- called. The first step towards this is to inject the ``security.context ``
42
+ Your goal is to check the user's role when the ``sendNewsletter() `` method is
43
+ called. The first step towards this is to inject the ``security.context ``
44
44
service into the object. Since it won't make sense *not * to perform the security
45
45
check, this is an ideal candidate for constructor injection, which guarantees
46
46
that the security context object will be available inside the ``NewsletterManager ``
47
47
class::
48
48
49
49
namespace Acme\HelloBundle\Newsletter;
50
-
50
+
51
51
use Symfony\Component\Security\Core\SecurityContextInterface;
52
52
53
53
class NewsletterManager
@@ -126,7 +126,7 @@ The injected service can then be used to perform the security check when the
126
126
if (false === $this->securityContext->isGranted('ROLE_NEWSLETTER_ADMIN')) {
127
127
throw new AccessDeniedException();
128
128
}
129
-
129
+
130
130
//--
131
131
}
132
132
@@ -139,9 +139,9 @@ be prompted to log in.
139
139
Securing Methods Using Annotations
140
140
----------------------------------
141
141
142
- You can also secure method calls in any service with annotations by using the
143
- optional `SecurityExtraBundle `_ bundle. This bundle is included in the Symfony2
144
- Standard Distribution.
142
+ You can also secure method calls in any service with annotations by using the
143
+ optional `JMSSecurityExtraBundle `_ bundle. This bundle is included in the
144
+ Symfony2 Standard Distribution.
145
145
146
146
To enable the annotations functionality, :ref: `tag<book-service-container-tags> `
147
147
the service you want to secure with the ``security.secure_service `` tag
@@ -184,7 +184,7 @@ the :ref:`sidebar<securing-services-annotations-sidebar>` below):
184
184
array(new Reference('security.context'))
185
185
));
186
186
$definition->addTag('security.secure_service');
187
- $container->setDefinition('newsletter_manager', $definition);
187
+ $container->setDefinition('newsletter_manager', $definition);
188
188
189
189
You can then achieve the same results as above using an annotation::
190
190
@@ -195,12 +195,12 @@ You can then achieve the same results as above using an annotation::
195
195
196
196
class NewsletterManager
197
197
{
198
-
198
+
199
199
/**
200
200
* @Secure(roles="ROLE_NEWSLETTER_ADMIN")
201
201
*/
202
202
public function sendNewsletter()
203
- {
203
+ {
204
204
//--
205
205
}
206
206
@@ -210,12 +210,12 @@ You can then achieve the same results as above using an annotation::
210
210
.. note ::
211
211
212
212
The annotations work because a proxy class is created for your class
213
- which performs the security checks. This means that, whilst you can use
213
+ which performs the security checks. This means that, whilst you can use
214
214
annotations on public and protected methods, you cannot use them with
215
215
private methods or methods marked final.
216
216
217
- The ``SecurityExtraBundle `` also allows you to secure the parameters and return
218
- values of methods. For more information, see the `SecurityExtraBundle `_
217
+ The ``JMSSecurityExtraBundle `` also allows you to secure the parameters and return
218
+ values of methods. For more information, see the `JMSSecurityExtraBundle `_
219
219
documentation.
220
220
221
221
.. _securing-services-annotations-sidebar :
@@ -235,7 +235,7 @@ documentation.
235
235
jms_security_extra :
236
236
# ...
237
237
secure_all_services : true
238
-
238
+
239
239
.. code-block :: xml
240
240
241
241
<!-- app/config/config.xml -->
@@ -245,18 +245,18 @@ documentation.
245
245
xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
246
246
247
247
<jms_security_extra secure_controllers =" true" secure_all_services =" true" />
248
-
249
- </srv : container >
248
+
249
+ </srv : container >
250
250
251
251
.. code-block :: php
252
-
252
+
253
253
// app/config/config.php
254
- $container->loadFromExtension('jms_security_extra', array(
254
+ $container->loadFromExtension('jms_security_extra', array(
255
255
// ...
256
256
'secure_all_services' => true,
257
257
));
258
258
259
259
The disadvantage of this method is that, if activated, the initial page
260
260
load may be very slow depending on how many services you have defined.
261
261
262
- .. _`SecurityExtraBundle ` : https://github.com/schmittjoh/SecurityExtraBundle
262
+ .. _`JMSSecurityExtraBundle ` : https://github.com/schmittjoh/JMSSecurityExtraBundle
0 commit comments