Пример #1
0
 /**
  * Handles access authorization.
  *
  * @param GetResponseEvent $event A GetResponseEvent instance
  *
  * @throws AccessDeniedException
  * @throws AuthenticationCredentialsNotFoundException
  */
 public function handle(GetResponseEvent $event)
 {
     if (null === ($token = $this->tokenStorage->getToken())) {
         throw new AuthenticationCredentialsNotFoundException('A Token was not found in the TokenStorage.');
     }
     $request = $event->getRequest();
     list($attributes) = $this->map->getPatterns($request);
     if (null === $attributes) {
         return;
     }
     if (!$token->isAuthenticated()) {
         $token = $this->authManager->authenticate($token);
         $this->tokenStorage->setToken($token);
     }
     if (!$this->accessDecisionManager->decide($token, $attributes, $request)) {
         $exception = new AccessDeniedException();
         $exception->setAttributes($attributes);
         $exception->setObject($request);
         throw $exception;
     }
 }