Example #1
0
 public function testGetRolesWithUserInterfaceUser()
 {
     $user = new User('paul', 'xxxx', array('ROLE_SINGLE'));
     $token = new ConnectToken($user, 'xxxx', null, 'xxxx', null, array('ROLE_USER', 'ROLE_ADMIN'));
     $roles = $token->getRoles();
     $this->assertCount(1, $roles);
     $this->assertEquals('ROLE_SINGLE', $roles[0]->getRole());
 }
 public function authenticate(TokenInterface $token)
 {
     try {
         $localUser = $this->userProvider->loadUserByUsername($token->getUser());
         $authorizedToken = new ConnectToken($localUser, $token->getAccessToken(), $token->getApiUser(), $this->providerKey, $token->getScope(), $localUser->getRoles());
         $authorizedToken->setAttributes($token->getAttributes());
         return $authorizedToken;
     } catch (\Exception $repositoryProblem) {
         throw new AuthenticationServiceException($repositoryProblem->getMessage(), $token, 0, $repositoryProblem);
     }
 }
 public function authenticate(TokenInterface $token)
 {
     try {
         $localUser = $this->userProvider->loadUserByUsername($token->getUser());
         $authorizedToken = new ConnectToken($localUser, $token->getAccessToken(), $token->getApiUser(), $this->providerKey, $token->getScope(), $localUser->getRoles());
         $authorizedToken->setAttributes($token->getAttributes());
         return $authorizedToken;
     } catch (\Exception $repositoryProblem) {
         if (!method_exists('Symfony\\Component\\Security\\Core\\Exception\\AuthenticationServiceException', 'setToken')) {
             throw new AuthenticationServiceException($repositoryProblem->getMessage(), $token, 0, $repositoryProblem);
         } else {
             $e = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem);
             $e->setToken($token);
             throw $e;
         }
     }
 }