5

Using “normal” — not “remember me” authentication — I can set a success and failure handlers, adding this to the security.yml file:

form_login:
    # ...
    success_handler: authentication_handler
    failure_handler: authentication_handler

But I couldn't find a way for listening for “remember me” reauthentication, when a user's session is expired and a “remember me” cookie is used to reauthenticate again. Any ideas on how can I achieve this?

Elnur Abdurrakhimov
  • 44,533
  • 10
  • 148
  • 133

2 Answers2

4

Create a Listener for the security.interactive_login event. That gets triggered on both simple and "remember me" logins (see Symfony\Component\Security\Http\Firewall\RememberMeListener.php @line:77).

In the listener you can separate the two by checking the cookie. You can find more about the listener here.

stollr
  • 6,534
  • 4
  • 43
  • 59
nezuvian
  • 137
  • 1
  • 8
0

I haven't tried this but maybe you could attach listener to success_handler but make sure you inject SecurityContext service via <argument> in service config.

Then, is soon as you enter you service method you do:

if ( $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED') ){
    // I am remembered visitor
}else{
    // I am the new visitor
}

Again, this is just an idea but sounds like it could do...

Jovan Perovic
  • 19,846
  • 5
  • 44
  • 85
  • The problem is that the `success_handler` attached to `form_login` is not being called when a user is being relogged in by a “remember me” cookie. – Elnur Abdurrakhimov May 14 '12 at 03:27