0

I want to log out the user if the IP has changed.

I managed to make it by creating a field lastLoginIp in the Users table, setting it in the onAuthenticationSuccess, and then checking in the User::isEqualTo() method:

if($user->getLastLoginIp() !== Utils::getIp()) {
    return false;
}

The problem is that it broke impersonation, because of course the IP of the admin is different than the IP of the user.

How can this be implemented? (and the user must not get logged out if somebody impersonates him)

the_nuts
  • 5,634
  • 1
  • 36
  • 68
  • Can you elaborate on how "somebody impersonates him"? – Arleigh Hix Sep 15 '19 at 21:34
  • @ArleighHix in my application the admins and the "account managers" can impersonate the regular users, using the Symfony impersonation feature (https://symfony.com/doc/current/security/impersonating_user.html – the_nuts Sep 22 '19 at 16:44

1 Answers1

0

Why not skip ip check if is granted ROLE_PREVIOUS_ADMIN?

    if ($this->security->isGranted('ROLE_PREVIOUS_ADMIN')) {
        return true;
    }
Harold
  • 669
  • 1
  • 7
  • 31