/**
  * Authenticates the user
  *
  * @param type $user
  * @param type $password
  * @param type $redirectUrl
  *
  * @throws AuthenticationException
  */
 private function authenticate($user, $password, $redirectUrl)
 {
     $form = $this->client->request('GET', sprintf(self::CAS_URL . '?service=%s', $redirectUrl))->filterXPath('//form[@id="fm1"]')->form();
     $this->client->submit($form, array('username' => $user, 'password' => $password));
     $server = $this->client->getRequest()->getServer();
     if ($server['HTTP_HOST'] === parse_url(self::CAS_URL, PHP_URL_HOST)) {
         // The client was not redirected, i.e. authentication failed
         throw new AuthenticationException();
     }
 }