2222use Symfony \Component \HttpFoundation \Response ;
2323
2424use CCDNUser \SecurityBundle \Component \Authentication \Tracker \LoginFailureTracker ;
25+ use Symfony \Component \Security \Http \Authentication \DefaultAuthenticationFailureHandler ;
2526
2627/**
2728 *
3435 * @link https://github.com/codeconsortium/CCDNUserSecurityBundle
3536 *
3637 */
37- class LoginFailureHandler implements AuthenticationFailureHandlerInterface
38+ class LoginFailureHandler extends DefaultAuthenticationFailureHandler
3839{
39- /**
40- *
41- * @access protected
42- * @var \Symfony\Component\Routing\RouterInterface $router
43- */
44- protected $ router ;
45-
4640 /**
4741 *
4842 * @access protected
4943 * @var \CCDNUser\SecurityBundle\Component\Authentication\Tracker\LoginFailureTracker $loginFailureTracker
5044 */
5145 protected $ loginFailureTracker ;
5246
53- /**
54- *
55- * @access protected
56- * @var array $routeLogin
57- */
58- protected $ routeLogin ;
59-
6047 /**
6148 *
6249 * @access public
63- * @param \Symfony\Component\Routing\RouterInterface $router
6450 * @param \CCDNUser\SecurityBundle\Component\Authentication\Tracker\LoginFailureTracker $loginFailureTracker
65- * @param array $routeLogin
6651 */
67- public function __construct ( RouterInterface $ router , LoginFailureTracker $ loginFailureTracker, $ routeLogin )
52+ public function setLoginFailureTracker ( LoginFailureTracker $ loginFailureTracker )
6853 {
69- $ this ->router = $ router ;
7054 $ this ->loginFailureTracker = $ loginFailureTracker ;
71- $ this ->routeLogin = $ routeLogin ;
7255 }
7356
7457 /**
@@ -90,29 +73,8 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
9073
9174 // Make a note of the failed login.
9275 $ this ->loginFailureTracker ->addAttempt ($ ipAddress , $ username );
93- $ request ->getSession ()->set (SecurityContext::AUTHENTICATION_ERROR , $ exception );
94-
95- // Send response back to browser depending on wether this is XML request or not.
96- if ($ request ->isXmlHttpRequest () || $ request ->request ->get ('_format ' ) === 'json ' ) {
97- $ response = new Response (
98- json_encode (
99- array (
100- 'status ' => 'failed ' ,
101- 'errors ' => array ($ exception ->getMessage ())
102- )
103- )
104- );
105-
106- $ response ->headers ->set ('Content-Type ' , 'application/json ' );
107- } else {
108- $ response = new RedirectResponse (
109- $ this ->router ->generate (
110- $ this ->routeLogin ['name ' ],
111- $ this ->routeLogin ['params ' ]
112- )
113- );
114- }
11576
116- return $ response ;
77+ // Let Symfony decide what to do next
78+ return parent ::onAuthenticationFailure ($ request , $ exception );
11779 }
11880}
0 commit comments