Exemplo n.º 1
0
 /**
  * Load the configuration of authentification, stored in the auth plugin config
  * @return array
  * @since 1.2.10
  */
 public static function loadConfig($newconfig = null)
 {
     if (self::$config === null || $newconfig) {
         if (!$newconfig) {
             $plugin = jApp::coord()->getPlugin('auth');
             if ($plugin === null) {
                 throw new jException('jelix~auth.error.plugin.missing');
             }
             $config =& $plugin->config;
         } else {
             $config = $newconfig;
         }
         if (!isset($config['session_name']) || $config['session_name'] == '') {
             $config['session_name'] = 'JELIX_USER';
         }
         if (!isset($config['persistant_cookie_path']) || $config['persistant_cookie_path'] == '') {
             if (jApp::config()) {
                 $config['persistant_cookie_path'] = jApp::urlBasePath();
             } else {
                 $config['persistant_cookie_path'] = '/';
             }
         }
         if (!isset($config['persistant_encryption_key'])) {
             if (isset(jApp::config()->coordplugin_auth) && isset(jApp::config()->coordplugin_auth['persistant_crypt_key'])) {
                 $config['persistant_crypt_key'] = trim(jApp::config()->coordplugin_auth['persistant_crypt_key']);
             } else {
                 $config['persistant_crypt_key'] = '';
             }
         }
         if (!isset($config['persistant_cookie_name'])) {
             $config['persistant_cookie_name'] = 'jauthSession';
         }
         // Read hash method configuration. If not empty, cryptPassword will use
         // the new API of PHP 5.5 (password_verify and so on...)
         $password_hash_method = isset($config['password_hash_method']) ? $config['password_hash_method'] : 0;
         if ($password_hash_method === '' || !is_numeric($password_hash_method)) {
             $password_hash_method = 0;
         } else {
             $password_hash_method = intval($password_hash_method);
         }
         if ($password_hash_method > 0) {
             require_once __DIR__ . '/password.php';
             if (!can_use_password_API()) {
                 $password_hash_method = 0;
             }
         }
         require_once __DIR__ . '/hash_equals.php';
         $password_hash_options = isset($config['password_hash_options']) ? $config['password_hash_options'] : '';
         if ($password_hash_options != '') {
             $list = '{"' . str_replace(array('=', ';'), array('":"', '","'), $config['password_hash_options']) . '"}';
             $json = new jJson(SERVICES_JSON_LOOSE_TYPE);
             $password_hash_options = @$json->decode($list);
             if (!$password_hash_options) {
                 $password_hash_options = array();
             }
         } else {
             $password_hash_options = array();
         }
         $config['password_hash_method'] = $password_hash_method;
         $config['password_hash_options'] = $password_hash_options;
         $config[$config['driver']]['password_hash_method'] = $password_hash_method;
         $config[$config['driver']]['password_hash_options'] = $password_hash_options;
         self::$config = $config;
     }
     return self::$config;
 }