diff --git a/lib/SimpleSAML/Logger.php b/lib/SimpleSAML/Logger.php new file mode 100644 index 0000000000000000000000000000000000000000..7b2daad00f95f01d1dbce39ad260c6b152971b63 --- /dev/null +++ b/lib/SimpleSAML/Logger.php @@ -0,0 +1,55 @@ +<?php + +/** + * SimpleSAMLphp + * + * LICENSE: See the COPYING file included in this distribution. + * + * @author Andreas Ĺkre Solberg, UNINETT AS. <andreas.solberg@uninett.no> + */ + +require_once('SimpleSAML/Configuration.php'); + + +/** + * A logger class. + */ +class SimpleSAML_Logger { + + + private $configuration = null; + private $loglevel = LOG_NOTICE; + + public function __construct() { + + $this->configuration = SimpleSAML_Configuration::getInstance(); + $this->loglevel = $this->configuration->getValue('logging.level'); + + define_syslog_variables(); + openlog("simpleSAMLphp", LOG_PID, $this->configuration->getValue('logging.facility') ); + + } + + /* + * Log a message to syslog. + */ + public function log($priority, $trackid, $module, $submodule, $eventtype, $content, $message) { + if ($priority < $this->loglevel) return; + + $contentstring = ''; + if (is_array($content)) { + $contentstring = implode('|', $content); + } else { + $contentstring = $content; + } + + $logstring = implode(',', array($priority, $trackid, $module, $submodule, $eventtype, $contentstring, $message)); + syslog($priority, $logstring); + + } + + + +} + +?> \ No newline at end of file diff --git a/lib/SimpleSAML/Session.php b/lib/SimpleSAML/Session.php index e37d30c4a41b954600adda2fa3a081a6e6f6d12b..fbffec94927ad4e84f685250815c57c178e4fa25 100644 --- a/lib/SimpleSAML/Session.php +++ b/lib/SimpleSAML/Session.php @@ -30,6 +30,8 @@ class SimpleSAML_Session { const STATE_LOGGEDOUT = 3; private static $instance = null; + + private $trackid = 0; private $configuration = null; @@ -71,6 +73,47 @@ class SimpleSAML_Session { } $this->sessionduration = $this->configuration->getValue('session.duration'); + + $this->trackid = SimpleSAML_Utilities::generateTrackID(); + } + + + + public function getInstance($allowcreate = false) { + if (isset(self::$instance)) { + return self::$instance; + } elseif(isset($_SESSION['SimpleSAMLphp_SESSION'])) { + self::$instance = $_SESSION['SimpleSAMLphp_SESSION']; + return self::$instance; + } + if ($allowcreate) { + self::init('saml2'); + return self::$instance; + } else { + return null; + } + } + + public static function init($protocol, $message = null, $authenticated = false) { + + $preinstance = self::getInstance(); + + if (isset($preinstance)) { + if (isset($message)) $preinstance->authnresponse = $message; + if (isset($authenticated)) $preinstance->setAuthenticated($authenticated); + } else { + self::$instance = new SimpleSAML_Session($protocol, $message, $authenticated); + $_SESSION['SimpleSAMLphp_SESSION'] = self::$instance; + } + } + + + + + + + public function getTrackID() { + return $this->trackid; } public function add_sp_session($entityid) { @@ -90,19 +133,21 @@ class SimpleSAML_Session { return null; } - public function get_sp_list() { + public function get_sp_list($state = self::STATE_ONLINE) { $list = array(); if (!$this->sp_at_idpsessions) return $list; foreach ($this->sp_at_idpsessions AS $entityid => $sp) { - if ($sp == self::STATE_ONLINE) { + if ($sp == $state) { $list[] = $entityid; } } return $list; } + + public function set_sp_logout_completed($entityid) { $this->sp_at_idpsessions[$entityid] = self::STATE_LOGGEDOUT; } @@ -113,30 +158,7 @@ class SimpleSAML_Session { error_log('Dump sp sessions: ' . $entityid . ' status: ' . $sp); } } - - public function getInstance() { - if (isset(self::$instance)) { - return self::$instance; - } elseif(isset($_SESSION['SimpleSAMLphp_SESSION'])) { - self::$instance = $_SESSION['SimpleSAMLphp_SESSION']; - return self::$instance; - } - return null; - } - - public static function init($protocol, $message = null, $authenticated = true) { - - $preinstance = self::getInstance(); - - if (isset($preinstance)) { - if (isset($message)) $preinstance->authnresponse = $message; - if (isset($authenticated)) $preinstance->setAuthenticated($authenticated); - } else { - self::$instance = new SimpleSAML_Session($protocol, $message, $authenticated); - $_SESSION['SimpleSAMLphp_SESSION'] = self::$instance; - } - } - + public function setShibAuthnRequest(SimpleSAML_XML_Shib13_AuthnRequest $req) { $this->shibauthreq = $req; } diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 9fdf2d557694fcbfb4e669424272f356365820d9..91a1ef64052aa312bcaf60fffb8c2450a262834e 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -111,6 +111,11 @@ class SimpleSAML_Utilities { return $key; } + public static function generateTrackID() { + $uniqueid = substr(md5(uniqid(rand(), true)), 0, 10); + return $uniqueid; + } + } ?> \ No newline at end of file