Skip to content

Commit

Permalink
Merge pull request #75 from jefersonfdasilv/master
Browse files Browse the repository at this point in the history
Resolves error due to TokenInterface with BC in Symfony 5
  • Loading branch information
l3pp4rd committed Feb 4, 2021
2 parents 6f0e570 + c46cebd commit d80a751
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,28 @@ private function getImpersonatorUserFromSecurityToken($token)
if(!$token instanceof TokenInterface) {
return null;
}
foreach ($token->getRoles() as $role) {

foreach ($this->getRoles($token) as $role) {
if ($role instanceof SwitchUserRole) {
return $role->getSource()->getUser();
}
}
return null;
}

/**
* @param TokenInterface $token
* @return array
*/
private function getRoles(TokenInterface $token)
{
if(method_exists($token, 'getRoleNames')){
return $token->getRoleNames();
}

return $token->getRoles();
}

public function getSubscribedEvents()
{
return [Events::onFlush];
Expand Down

0 comments on commit d80a751

Please sign in to comment.