Skip to content

Commit 984eeb0

Browse files
committed
minor #7898 Remove use of deprecated security.exception_listener.class parameter (ndench)
This PR was submitted for the 3.2 branch but it was merged into the 2.7 branch instead (closes #7898). Discussion ---------- Remove use of deprecated security.exception_listener.class parameter Reference: symfony/symfony#15534 Commits ------- 6fc36d0 Remove use of deprecated security.exception_listener.class parameter
2 parents c33a3db + 6fc36d0 commit 984eeb0

File tree

1 file changed

+40
-33
lines changed

1 file changed

+40
-33
lines changed

security/target_path.rst

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,7 @@ URI was an XMLHttpRequest which returned a non-HTML or partial HTML response,
1515
the user is redirected back to a page which the browser cannot render.
1616

1717
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()``::
5019

5120
// src/AppBundle/Security/Firewall/ExceptionListener.php
5221
namespace AppBundle\Security\Firewall;
@@ -69,4 +38,42 @@ Next, create your own ``ExceptionListener``::
6938
}
7039
}
7140

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

Comments
 (0)