|
12 | 12 | namespace FOS\UserBundle\Controller; |
13 | 13 |
|
14 | 14 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
15 | | -use Symfony\Component\HttpFoundation\Request; |
16 | 15 | use Symfony\Component\HttpFoundation\Response; |
17 | | -use Symfony\Component\HttpFoundation\Session\Session; |
18 | | -use Symfony\Component\Security\Core\Exception\AuthenticationException; |
19 | | -use Symfony\Component\Security\Core\Security; |
20 | 16 | use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; |
| 17 | +use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; |
21 | 18 |
|
22 | 19 | /** |
23 | 20 | * Controller managing security. |
|
29 | 26 | */ |
30 | 27 | class SecurityController extends AbstractController |
31 | 28 | { |
| 29 | + private $authenticationUtils; |
32 | 30 | private $tokenManager; |
33 | 31 |
|
34 | | - public function __construct(CsrfTokenManagerInterface $tokenManager = null) |
| 32 | + public function __construct(AuthenticationUtils $authenticationUtils, CsrfTokenManagerInterface $tokenManager = null) |
35 | 33 | { |
| 34 | + $this->authenticationUtils = $authenticationUtils; |
36 | 35 | $this->tokenManager = $tokenManager; |
37 | 36 | } |
38 | 37 |
|
39 | 38 | /** |
40 | 39 | * @return Response |
41 | 40 | */ |
42 | | - public function loginAction(Request $request) |
| 41 | + public function loginAction() |
43 | 42 | { |
44 | | - /** @var $session Session */ |
45 | | - $session = $request->getSession(); |
46 | | - |
47 | | - $authErrorKey = Security::AUTHENTICATION_ERROR; |
48 | | - $lastUsernameKey = Security::LAST_USERNAME; |
49 | | - |
50 | | - // get the error if any (works with forward and redirect -- see below) |
51 | | - if ($request->attributes->has($authErrorKey)) { |
52 | | - $error = $request->attributes->get($authErrorKey); |
53 | | - } elseif (null !== $session && $session->has($authErrorKey)) { |
54 | | - $error = $session->get($authErrorKey); |
55 | | - $session->remove($authErrorKey); |
56 | | - } else { |
57 | | - $error = null; |
58 | | - } |
59 | | - |
60 | | - if (!$error instanceof AuthenticationException) { |
61 | | - $error = null; // The value does not come from the security component. |
62 | | - } |
63 | | - |
64 | | - // last username entered by the user |
65 | | - $lastUsername = (null === $session) ? '' : $session->get($lastUsernameKey); |
| 43 | + $error = $this->authenticationUtils->getLastAuthenticationError(); |
| 44 | + $lastUsername = $this->authenticationUtils->getLastUsername(); |
66 | 45 |
|
67 | 46 | $csrfToken = $this->tokenManager |
68 | 47 | ? $this->tokenManager->getToken('authenticate')->getValue() |
|
0 commit comments