public function handle(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $session = $request->getSession();
     $bag_configuration = new BagConfiguration();
     if ($session->getBag($bag_configuration->getNamespace(BagManagerConfigurationInterface::ATTRIBUTE_NAMESPACE))->has('sfGuardSecurityUser')) {
         $sf1_guard_security_user = $session->getBag($bag_configuration->getNamespace(BagManagerConfigurationInterface::ATTRIBUTE_NAMESPACE))->get('sfGuardSecurityUser');
         $username = $sf1_guard_security_user['username'];
         $token = new MinisterioUserBridgeToken();
         $token->setUser($username);
         try {
             $authToken = $this->authenticationManager->authenticate($token);
             $this->tokenStorage->setToken($authToken);
             $event->getDispatcher()->dispatch(self::AUTHENTICATED_EVENT, new MinisterioUserBridgeAuthenticatedEvent($authToken));
             return;
         } catch (AuthenticationException $failed) {
             // ... you might log something here
             // To deny the authentication clear the token. This will redirect to the login page.
             // Make sure to only clear your token, not those of other authentication listeners.
             // $token = $this->tokenStorage->getToken();
             // if ($token instanceof WsseUserToken && $this->providerKey === $token->getProviderKey()) {
             //     $this->tokenStorage->setToken(null);
             // }
             // return;
         }
     }
     // By default deny authorization
     $response = new Response("", Response::HTTP_TEMPORARY_REDIRECT, array("Location" => $this->container->getParameter('logout_url')));
     $event->setResponse($response);
 }
 public function authenticate(TokenInterface $token)
 {
     $user = $this->userProvider->loadUserByUsername($token->getUsername());
     if ($user && $user->isAuthenticated()) {
         $authenticatedToken = new MinisterioUserBridgeToken($user->getRoles());
         $authenticatedToken->setUser($user);
         return $authenticatedToken;
     }
     throw new AuthenticationException('The Ministerio User Bridge authentication failed.');
 }