getRoles() public method

Returns the roles stored in token data.
public getRoles ( ) : array
return array
Ejemplo n.º 1
0
 /**
  * This method compares the $tokenData against the current user and returns true if users are identical,
  * otherwise false is returned.
  *
  * @param TokenData $tokenData
  *
  * @return bool
  */
 public function isTokenValid(TokenData $tokenData)
 {
     $roles = [];
     foreach ($this->roles as $role) {
         $roles[] = $role->getRole();
     }
     $currentUser = $this->str($this->getUsername() . implode(',', $roles))->hash('md5');
     $tokenRoles = [];
     foreach ($tokenData->getRoles() as $role) {
         $tokenRoles[] = $role->getRole();
     }
     $tokenUser = $this->str($tokenData->getUsername() . implode(',', $tokenRoles))->hash('md5');
     return $currentUser == $tokenUser;
 }
Ejemplo n.º 2
0
 /**
  * @param TokenData $tokenData
  *
  * @dataProvider dataProvider
  */
 public function testGetRoles($tokenData)
 {
     $roles = $tokenData->getRoles();
     $this->assertSame('ROLE_MOCK', $roles[0]->getRole());
 }