/**
  * @param TokenInterface $token
  * @param UserProviderInterface $userProvider
  * @param string $providerKey
  *
  * @return PreAuthenticatedToken
  */
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     if (!($user = $token->getUser()) instanceof UserInterface) {
         $user = $this->userProvider->loadUserByUsername($token->getCredentials());
     }
     return new PreAuthenticatedToken($user, $token->getCredentials(), $providerKey, $user->getRoles());
 }
 /**
  * Load the new user from IRIS and set them as logged in.
  *
  * @param string $username
  * @param string $password
  *
  * @return void
  */
 private function authenticateUser($username, $password)
 {
     $user = $this->userProvider->loadUserByUsername($username, $password);
     // TODO: move this security.context related code into the security bundle
     $token = new UsernamePasswordToken($user, $user->getPassword(), 'login_secured', $user->getRoles());
     $this->container->get('security.context')->setToken($token);
 }