@@ -15,38 +15,7 @@ URI was an XMLHttpRequest which returned a non-HTML or partial HTML response,
15
15
the user is redirected back to a page which the browser cannot render.
16
16
17
17
To get around this behavior, you would simply need to extend the ``ExceptionListener ``
18
- class and override the default method named ``setTargetPath() ``.
19
-
20
- First, override the ``security.exception_listener.class `` parameter in your
21
- configuration file. This can be done from your main configuration file (in
22
- ``app/config ``) or from a configuration file being imported from a bundle:
23
-
24
- .. configuration-block ::
25
-
26
- .. code-block :: yaml
27
-
28
- # app/config/services.yml
29
- parameters :
30
- # ...
31
- security.exception_listener.class : AppBundle\Security\Firewall\ExceptionListener
32
-
33
- .. code-block :: xml
34
-
35
- <!-- app/config/services.xml -->
36
- <parameters >
37
- <!-- ... -->
38
- <parameter key =" security.exception_listener.class" >AppBundle\Security\Firewall\ExceptionListener</parameter >
39
- </parameters >
40
-
41
- .. code-block :: php
42
-
43
- // app/config/services.php
44
- use AppBundle\Security\Firewall\ExceptionListener;
45
-
46
- // ...
47
- $container->setParameter('security.exception_listener.class', ExceptionListener::class);
48
-
49
- Next, create your own ``ExceptionListener ``::
18
+ class and override the default method named ``setTargetPath() ``::
50
19
51
20
// src/AppBundle/Security/Firewall/ExceptionListener.php
52
21
namespace AppBundle\Security\Firewall;
@@ -69,4 +38,42 @@ Next, create your own ``ExceptionListener``::
69
38
}
70
39
}
71
40
72
- Add as much or as little logic here as required for your scenario!
41
+ By preventing ``setTargetPath() `` from being called on the parent, the Security component
42
+ won't retain the request URI. Add as much or as little logic here as required for your scenario!
43
+
44
+ Next, create the ``ExceptionListenerPass `` to replace the definition of the default
45
+ ``ExceptionListener `` with the one you just created. Make sure to use the name of
46
+ the firewall in your security configuration::
47
+
48
+ // src/AppBundle/DependencyInjection/Compiler/ExceptionListenerPass.php
49
+ namespace AppBundle\DependencyInjection\Compiler;
50
+
51
+ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
52
+ use Symfony\Component\DependencyInjection\ContainerBuilder;
53
+ use AppBundle\Security\Firewall\ExceptionListener;
54
+
55
+ class ExceptionListenerPass implements CompilerPassInterface
56
+ {
57
+ public function process(ContainerBuilder $container)
58
+ {
59
+ // Use the name of your firewall for the suffix e.g. 'secured_area'
60
+ $definition = $container->getDefinition('security.exception_listener.secured_area');
61
+ $definition->setClass(ExceptionListener::class);
62
+ }
63
+ }
64
+
65
+ Finally, add a compiler pass to tie it all together::
66
+
67
+ // src/AppBundle/AppBundle.php
68
+ namespace AppBundle;
69
+
70
+ use AppBundle\DependencyInjection\Compiler\ExceptionListenerPass;
71
+
72
+ class AppBundle extends Bundle
73
+ {
74
+ public function build(ContainerBuilder $container)
75
+ {
76
+ $container->addCompilerPass(new ExceptionListenerPass());
77
+ }
78
+ }
79
+
0 commit comments