/**
  * @test
  */
 public function it_can_authenticate_a_uitid_token()
 {
     $this->userService->expects($this->once())->method('getUser')->with('1')->willReturn($this->user);
     $authenticated = $this->authenticator->authenticate($this->unauthenticatedToken);
     $expected = new UiTIDToken($this->user->getRoles());
     $expected->setUser($this->user);
     $this->assertEquals($expected, $authenticated);
 }
 /**
  * @inheritdoc
  */
 public function authenticate(TokenInterface $token)
 {
     $userId = $token->getUser();
     $user = $this->userService->getUser($userId);
     if (is_null($user)) {
         throw new AuthenticationException(sprintf('User with id %s does not exist.', $userId));
     }
     $token = new UiTIDToken($user->getRoles());
     $token->setUser($user);
     return $token;
 }
 /**
  * @param GetResponseEvent $event
  */
 public function handle(GetResponseEvent $event)
 {
     $user = $this->userSessionService->getMinimalUserInfo();
     if (!is_null($user)) {
         $token = new UiTIDToken();
         $token->setUser((string) $user->getId());
         try {
             $authToken = $this->authenticationManager->authenticate($token);
             $this->tokenStorage->setToken($authToken);
             return;
         } catch (AuthenticationException $exception) {
         }
     }
     $response = new Response('Unauthorized access.', Response::HTTP_UNAUTHORIZED);
     $event->setResponse($response);
 }
 /**
  * @test
  */
 public function it_grants_access_when_authenticated()
 {
     $this->userSessionService->setMinimalUserInfo($this->minimalUserInfo);
     $user = new User();
     $user->id = $this->minimalUserInfo->getId();
     $authToken = new UiTIDToken($user->getRoles());
     $authToken->setUser($user);
     $this->authenticationManager->expects($this->once())->method('authenticate')->with($this->minimalToken)->willReturn($authToken);
     $this->tokenStorage->expects($this->once())->method('setToken')->with($authToken);
     // Make sure no Response is set, so the request can be handled by the
     // actual controllers.
     $this->event->expects($this->never())->method('setResponse');
     $this->listener->handle($this->event);
 }