4
4
How to Create a Custom Access Denied Handler
5
5
============================================
6
6
7
- When your application throw an ``AccessDeniedException `` you can catch this exception
7
+ When your application throws an ``AccessDeniedException ``, you can catch this exception
8
8
with a service to return a custom Response.
9
9
10
10
On each firewall context you can define a custom access denied handler.
@@ -19,6 +19,14 @@ On each firewall context you can define a custom access denied handler.
19
19
# ...
20
20
access_denied_handler : custom_handler.service.id
21
21
22
+ .. code-block :: xml
23
+
24
+ <config >
25
+ <firewall name =" foo" >
26
+ <access_denied_handler >custom_handler.service.id</access_denied_handler >
27
+ </firewall >
28
+ </config >
29
+
22
30
.. code-block :: php
23
31
24
32
// app/config/security.php
@@ -32,20 +40,20 @@ On each firewall context you can define a custom access denied handler.
32
40
));
33
41
34
42
35
- Your handler must implement the interface
43
+ Your handler must implement the
36
44
:class: `Symfony\\ Component\\ Security\\ Http\\ Authorization\\ AccessDeniedHandlerInterface `.
37
- This interface define one method called ``handle() `` that can do whatever you want.
38
- You can use it to send a mail, log a message, or generally return a custom Response.
39
-
45
+ This interface defines one method called ``handle() `` that implements the logic you want
46
+ to execute when access is denied to the current user ( send a mail, log a message, or
47
+ generally return a custom Response).
40
48
41
49
.. code-block :: php
42
50
43
51
namespace AppBundle\Security;
44
52
45
- use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
46
53
use Symfony\Component\HttpFoundation\Request;
47
54
use Symfony\Component\HttpFoundation\Response;
48
55
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
56
+ use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
49
57
50
58
class AccessDeniedHandler implements AccessDeniedHandlerInterface
51
59
{
0 commit comments