Reputation: 17282
I've successfully switched to user with _switch_user=thomas
.
However, the following always return false when it should return true:
$security = $this->get('security.context');
$impersonated = $security->isGranted('ROLE_PREVIOUS_ADMIN');
die(var_dump($impersonated)); // == false
Why can't I get the ROLE_PREVIOUS_ADMIN in the security context?
EDIT I log in with:
[email protected]
since:
providers:
main:
entity:
property: email
my param is the default:
switch_user: true
I correctly switch, that is not the problem.
The problem is after I've impersonated, the user does not have the ROLE_PREVIOUS_ADMIN
Upvotes: 1
Views: 197
Reputation: 145398
Most probably you haven't implemented the EquatableInterface
for User
class:
class User implements UserInterface, EquatableInterface, \Serializable {
// ...
public function isEqualTo(UserInterface $user) {
return $this->email === $user->getEmail();
}
public function serialize() {
return serialize(array(
$this->id,
$this->email,
));
}
public function unserialize($serialized) {
list($this->id, $this->email) = unserialize($serialized);
}
// ...
}
Upvotes: 1
Reputation: 20191
User
object? What is the username value?config.yml
that impersonation param is indeed called _switch_user
.You might be opening you page without actually switching user.
Upvotes: 0