/**
  * Handles basic authentication.
  *
  * @param GetResponseEvent $event A GetResponseEvent instance
  */
 public function handle(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (false === ($username = $request->headers->get('PHP_AUTH_USER', false))) {
         return;
     }
     if (null !== ($token = $this->securityContext->getToken())) {
         if ($token instanceof OrganizationContextTokenInterface && $token->isAuthenticated() && $token->getUsername() === $username) {
             return;
         }
     }
     $this->logProcess($username);
     try {
         $organization = $request->headers->get('PHP_AUTH_ORGANIZATION') ? $this->manager->getOrganizationById($request->headers->get('PHP_AUTH_ORGANIZATION')) : $this->manager->getOrganizationRepo()->getFirst();
         $token = $this->authenticationManager->authenticate(new UsernamePasswordOrganizationToken($username, $request->headers->get('PHP_AUTH_PW'), $this->providerKey, $organization));
         $this->securityContext->setToken($token);
     } catch (AuthenticationException $failed) {
         $token = $this->securityContext->getToken();
         if ($token instanceof UsernamePasswordToken && $this->providerKey === $token->getProviderKey()) {
             $this->securityContext->setToken(null);
         }
         $this->logError($username, $failed->getMessage());
         if ($this->ignoreFailure) {
             return;
         }
         $event->setResponse($this->authenticationEntryPoint->start($request, $failed));
     }
 }