Example #1
0
 /**
  * Return current user if it exists.
  * 
  * @return User instance or false
  */
 public static function user()
 {
     if (is_null(self::$user)) {
         // Not already cached
         self::$user = false;
         // Authentication logic
         $event = new Event('auth_check');
         $auth = $event->trigger(function () {
             // No authentification is required by application
             if (!Config::get('auth_sp_type')) {
                 return array();
             }
             // Check for local authentificaiton (script)
             if (AuthLocal::isAuthenticated()) {
                 return array('local', AuthLocal::attributes());
             }
             // Check for remote application/user
             if ((Config::get('auth_remote_application_enabled') || Config::get('auth_remote_user_enabled')) && AuthRemote::isAuthenticated() && (AuthRemote::application() && Config::get('auth_remote_application_enabled') || !AuthRemote::application() && Config::get('auth_remote_user_enabled'))) {
                 return array('remote', AuthRemote::attributes(), AuthRemote::application() && AuthRemote::isAdmin());
             }
             // Check for SP autentification
             if (AuthSP::isAuthenticated()) {
                 return array('sp', AuthSP::attributes());
             }
             return array();
         });
         self::$type = array_shift($auth);
         self::$attributes = array_shift($auth);
         if (count($auth)) {
             self::$isAdmin = array_shift($auth);
         }
         if (self::$attributes && array_key_exists('uid', self::$attributes)) {
             $user_filter = Config::get('auth_user_filter');
             if ($user_filter) {
                 self::$allowed = false;
                 if (is_string($user_filter)) {
                     if (preg_match('`^([^:]+):(.+)$`', $user_filter, $p)) {
                         self::$allowed = array_key_exists($p[1], self::$attributes) && preg_match('`' . $p[2] . '`', self::$attributes[$p[1]]);
                     }
                 } else {
                     self::$allowed = !(bool) $user_filter;
                 }
                 if (!self::$allowed) {
                     self::$type = null;
                     return;
                 }
             }
             // Set user if got uid attribute
             self::$user = User::fromAttributes(self::$attributes);
             // Save user additionnal attributes if enabled
             if (self::isSP() && Config::get('auth_sp_save_user_additional_attributes') && array_key_exists('additional', self::$attributes) && self::$user->additional_attributes != self::$attributes['additional']) {
                 self::$user->additional_attributes = self::$attributes['additional'];
                 self::$user->save();
             }
         }
     }
     return self::$user;
 }
Example #2
0
 /**
  * Load selected service provider delegation class and return its class name.
  * 
  * @return string delegation class name
  */
 private static function loadDelegationClass()
 {
     if (self::$loaded) {
         return self::$loaded;
     }
     $type = Config::get('auth_sp_type');
     if (!$type) {
         throw new ConfigBadParameterException('auth_sp_type');
     }
     $class = 'AuthSP' . ucfirst($type);
     $file = NOTES_BASE . '/classes/auth/' . $class . '.class.php';
     if (!file_exists($file)) {
         throw new AuthSPMissingDelegationClassException($class);
     }
     require_once $file;
     self::$loaded = $class;
     return $class;
 }
Example #3
0
 /**
  * This function allows to know if the user is authentified
  * 
  * @return boolean True if authentified, false otherwhise
  */
 public static function user()
 {
     if (is_null(self::$attributes)) {
         // Not already cached
         // Used to break infinite loop on Exceptions
         self::$attributes = array();
         if (!self::getFromCache()) {
             // Authentication logic
             if (AuthLocalApplication::isAuthenticated()) {
                 // SP
                 self::$attributes = AuthLocalApplication::attributes();
                 self::$isLocal = true;
             } else {
                 if (AuthSP::isAuthenticated()) {
                     // SP
                     self::$attributes = AuthSP::attributes();
                     self::$isSP = true;
                 }
             }
             if (!self::$attributes || !array_key_exists('email', self::$attributes)) {
                 return false;
             }
             self::$user = User::fromAttributes(self::$attributes);
             if (Config::get('use_application_cache')) {
                 $currentTime = time();
                 self::$creationTime = $currentTime;
                 self::$expiredTime = $currentTime + Config::get('notes_auth_cache_expired');
                 self::$sessionKey = Utilities::generateSessionKey(56);
             }
             self::storeCache();
         }
     }
     return self::$user;
 }
Example #4
0
<?php

/**
 * This file is part of the BaseProject project.
 * 2015 
 * Copyright (c) RENATER
 */
/**
 * Client side configuration handling
 */
require_once '../includes/core/init.php';
header('Content-Type: text/javascript');
$config = (new Event('client_config'))->trigger(function () {
    return array('application_url' => Config::get('application_url'), 'default_language' => Config::get('default_language'), 'max_cookie_duration' => Config::get('max_cookie_duration'), 'application_name' => Config::get('application_name'), 'logon_url' => AuthSP::logonURL(), 'logoff_url' => AuthSP::logoffURL());
});
?>
 
if(!('app' in window)) window.app = {};

window.app.config = <?php 
echo json_encode($config);
?>
;