Skip to content
Snippets Groups Projects
Commit 753c4dae authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Adding support for logging with syslog

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@60 44740490-163a-0410-bde0-09ae8108e29a
parent a8b1c706
No related branches found
No related tags found
No related merge requests found
<?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
...@@ -30,6 +30,8 @@ class SimpleSAML_Session { ...@@ -30,6 +30,8 @@ class SimpleSAML_Session {
const STATE_LOGGEDOUT = 3; const STATE_LOGGEDOUT = 3;
private static $instance = null; private static $instance = null;
private $trackid = 0;
private $configuration = null; private $configuration = null;
...@@ -71,6 +73,47 @@ class SimpleSAML_Session { ...@@ -71,6 +73,47 @@ class SimpleSAML_Session {
} }
$this->sessionduration = $this->configuration->getValue('session.duration'); $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) { public function add_sp_session($entityid) {
...@@ -90,19 +133,21 @@ class SimpleSAML_Session { ...@@ -90,19 +133,21 @@ class SimpleSAML_Session {
return null; return null;
} }
public function get_sp_list() { public function get_sp_list($state = self::STATE_ONLINE) {
$list = array(); $list = array();
if (!$this->sp_at_idpsessions) return $list; if (!$this->sp_at_idpsessions) return $list;
foreach ($this->sp_at_idpsessions AS $entityid => $sp) { foreach ($this->sp_at_idpsessions AS $entityid => $sp) {
if ($sp == self::STATE_ONLINE) { if ($sp == $state) {
$list[] = $entityid; $list[] = $entityid;
} }
} }
return $list; return $list;
} }
public function set_sp_logout_completed($entityid) { public function set_sp_logout_completed($entityid) {
$this->sp_at_idpsessions[$entityid] = self::STATE_LOGGEDOUT; $this->sp_at_idpsessions[$entityid] = self::STATE_LOGGEDOUT;
} }
...@@ -113,30 +158,7 @@ class SimpleSAML_Session { ...@@ -113,30 +158,7 @@ class SimpleSAML_Session {
error_log('Dump sp sessions: ' . $entityid . ' status: ' . $sp); 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) { public function setShibAuthnRequest(SimpleSAML_XML_Shib13_AuthnRequest $req) {
$this->shibauthreq = $req; $this->shibauthreq = $req;
} }
......
...@@ -111,6 +111,11 @@ class SimpleSAML_Utilities { ...@@ -111,6 +111,11 @@ class SimpleSAML_Utilities {
return $key; return $key;
} }
public static function generateTrackID() {
$uniqueid = substr(md5(uniqid(rand(), true)), 0, 10);
return $uniqueid;
}
} }
?> ?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment