getUser(); $targetUser = $subject; // if the user is anonymous or if the subject is not a user, do not grant access if (!$currentUser instanceof User || !$targetUser instanceof User) { return false; } // if the current user is trying to impersonate herself, do not grant access if ($currentUser === $targetUser) { return false; } // if the current user is already impersonating, do not grant access if ($this->security->isGranted('IS_IMPERSONATOR')) { return false; } // if the target user is superadmin, do not grant access if (true === $targetUser->isSuperAdmin()) { return false; } // a deleted account is excluded from every process, so impersonating it must not // become a way back into the teamer area if (true === $targetUser->isDeleted()) { return false; } // Admin is the only role allowed to impersonate if (false === $this->security->isGranted('ROLE_TEAM_ADMIN')) { return false; } return $currentUser->isSuperAdmin(); } }