示例#1
0
 /**
  * {@inheritdoc}
  */
 public function authenticate(TokenInterface $token)
 {
     /** @var OAuthToken $token */
     if (!$this->supports($token)) {
         return null;
     }
     try {
         $tokenString = $token->getToken();
         /** @var AccessToken $accessToken */
         if ($accessToken = $this->serverService->verifyAccessToken($tokenString)) {
             $userRepository = $this->entityManager->getRepository(ClassPath::USER);
             $scope = $accessToken->getScope();
             /** @var User $user */
             $user = $userRepository->find($accessToken->getUserId());
             if (!empty($user)) {
                 try {
                     $this->userChecker->checkPreAuth($user);
                 } catch (AccountStatusException $e) {
                     throw new OAuth2AuthenticateException(OAuth2::HTTP_UNAUTHORIZED, OAuth2::TOKEN_TYPE_BEARER, $this->serverService->getVariable(OAuth2::CONFIG_WWW_REALM), 'access_denied', $e->getMessage());
                 }
                 $token->setUser($user);
             }
             $roles = null !== $user ? $user->getRoles() : array();
             if (!empty($scope)) {
                 foreach (explode(' ', $scope) as $role) {
                     $roles[] = 'ROLE_' . strtoupper($role);
                 }
             }
             $token = new OAuthToken($roles);
             $token->setAuthenticated(true);
             $token->setToken($tokenString);
             if (null !== $user) {
                 try {
                     $this->userChecker->checkPostAuth($user);
                 } catch (AccountStatusException $e) {
                     throw new OAuth2AuthenticateException(OAuth2::HTTP_UNAUTHORIZED, OAuth2::TOKEN_TYPE_BEARER, $this->serverService->getVariable(OAuth2::CONFIG_WWW_REALM), 'access_denied', $e->getMessage());
                 }
                 $token->setUser($user);
             }
             return $token;
         }
     } catch (OAuth2ServerException $e) {
         if (!method_exists('Symfony\\Component\\Security\\Core\\Exception\\AuthenticationException', 'setToken')) {
             // Symfony 2.1
             throw new AuthenticationException('OAuth2 authentication failed', null, 0, $e);
         }
         throw new AuthenticationException('OAuth2 authentication failed', 0, $e);
     }
     throw new AuthenticationException('OAuth2 authentication failed');
 }
示例#2
0
 /**
  * @deprecated
  * @param string $class
  * @return Repository
  */
 protected function getRepository($class)
 {
     trigger_error('Function HireVoice\\Neo4j\\Repository::getRepository is deprecated. Use HireVoice\\Neo4j\\EntityManager::getRepository instead!', E_USER_DEPRECATED);
     return $this->entityManager->getRepository($class);
 }
示例#3
0
 /**
  * @inheritdoc
  */
 public function loadUserByUsername($username)
 {
     /** @var UserRepository $repository */
     $repository = $this->entityManager->getRepository(ClassPath::USER);
     return $repository->findByEmail($username);
 }