Exemplo n.º 1
0
 /**
  * Retrieve the preferred translation of a given text.
  *
  * @param array $translations The translations, as an associative array with language => text mappings.
  *
  * @return string The preferred translation.
  *
  * @throws \Exception If there's no suitable translation.
  */
 public function getPreferredTranslation($translations)
 {
     assert('is_array($translations)');
     // look up translation of tag in the selected language
     $selected_language = $this->language->getLanguage();
     if (array_key_exists($selected_language, $translations)) {
         return $translations[$selected_language];
     }
     // look up translation of tag in the default language
     $default_language = $this->language->getDefaultLanguage();
     if (array_key_exists($default_language, $translations)) {
         return $translations[$default_language];
     }
     // check for english translation
     if (array_key_exists('en', $translations)) {
         return $translations['en'];
     }
     // pick the first translation available
     if (count($translations) > 0) {
         $languages = array_keys($translations);
         return $translations[$languages[0]];
     }
     // we don't have anything to return
     throw new \Exception('Nothing to return from translation.');
 }
Exemplo n.º 2
0
 /**
  * @param $language
  * @deprecated This method will be removed in SSP 2.0. Please use \SimpleSAML\Locale\Language::setLanguageCookie()
  * instead.
  */
 public static function setLanguageCookie($language)
 {
     \SimpleSAML\Locale\Language::setLanguageCookie($language);
 }
Exemplo n.º 3
0
 /**
  * This method will return the language selected by the user, or the default language. It looks first for a cached
  * language code, then checks for a language cookie, then it tries to calculate the preferred language from HTTP
  * headers.
  *
  * @return string The language selected by the user according to the processing rules specified, or the default
  * language in any other case.
  */
 public function getLanguage()
 {
     // language is set in object
     if (isset($this->language)) {
         return $this->language;
     }
     // run custom getLanguage function if defined
     if (isset($this->customFunction) && is_callable($this->customFunction)) {
         $customLanguage = call_user_func($this->customFunction, $this);
         if ($customLanguage !== null && $customLanguage !== false) {
             return $customLanguage;
         }
     }
     // language is provided in a stored cookie
     $languageCookie = Language::getLanguageCookie();
     if ($languageCookie !== null) {
         $this->language = $languageCookie;
         return $languageCookie;
     }
     // check if we can find a good language from the Accept-Language HTTP header
     $httpLanguage = $this->getHTTPLanguage();
     if ($httpLanguage !== null) {
         return $httpLanguage;
     }
     // language is not set, and we get the default language from the configuration
     return $this->getDefaultLanguage();
 }
Exemplo n.º 4
0
 /**
  * Test SimpleSAML\Locale\Language::setLanguage().
  */
 public function testSetLanguage()
 {
     // test with valid configuration, no cookies set
     $c = \SimpleSAML_Configuration::loadFromArray(array('language.available' => array('en', 'nn', 'es'), 'language.parameter.name' => 'xyz', 'language.parameter.setcookie' => false), '', 'simplesaml');
     $_GET['xyz'] = 'Es';
     // test also that lang code is transformed to lower caps
     $l = new Language($c);
     $this->assertEquals('es', $l->getLanguage());
     // test with valid configuration, no cookies, language set unavailable
     $_GET['xyz'] = 'unavailable';
     $l = new Language($c);
     $this->assertEquals('en', $l->getLanguage());
 }
    SimpleSAML_Logger::debug('casserver:' . $message);
    throw new Exception($message);
}
$as = new SimpleSAML_Auth_Simple($casconfig->getValue('authsource'));
if (array_key_exists('scope', $_GET) && is_string($_GET['scope'])) {
    $scopes = $casconfig->getValue('scopes', array());
    if (array_key_exists($_GET['scope'], $scopes)) {
        $idpList = $scopes[$_GET['scope']];
    } else {
        $message = 'Scope parameter provided to CAS server is not listed as legal scope: [scope] = ' . var_export($_GET['scope'], true);
        SimpleSAML_Logger::debug('casserver:' . $message);
        throw new Exception($message);
    }
}
if (array_key_exists('language', $_GET) && is_string($_GET['language'])) {
    \SimpleSAML\Locale\Language::setLanguageCookie($_GET['language']);
}
$ticketStoreConfig = $casconfig->getValue('ticketstore', array('class' => 'casserver:FileSystemTicketStore'));
$ticketStoreClass = SimpleSAML_Module::resolveClass($ticketStoreConfig['class'], 'Cas_Ticket');
$ticketStore = new $ticketStoreClass($casconfig);
$ticketFactoryClass = SimpleSAML_Module::resolveClass('casserver:TicketFactory', 'Cas_Ticket');
$ticketFactory = new $ticketFactoryClass($casconfig);
$session = SimpleSAML_Session::getSessionFromRequest();
$sessionTicket = $ticketStore->getTicket($session->getSessionId());
$sessionRenewId = $sessionTicket ? $sessionTicket['renewId'] : null;
$requestRenewId = isset($_REQUEST['renewId']) ? $_REQUEST['renewId'] : null;
if (!$as->isAuthenticated() || $forceAuthn && $sessionRenewId != $requestRenewId) {
    $query = array();
    if ($sessionRenewId && $forceAuthn) {
        $query['renewId'] = $sessionRenewId;
    }