diff --git a/src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php b/src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php index 6cbfa60..216fccf 100644 --- a/src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php +++ b/src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php @@ -495,7 +495,8 @@ 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(); } @@ -503,6 +504,19 @@ private function getImpersonatorUserFromSecurityToken($token) 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];