runff 1.0 commit
This commit is contained in:
85
lib/SimpleSAML/Error/Assertion.php
Executable file
85
lib/SimpleSAML/Error/Assertion.php
Executable file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class for creating exceptions from assertion failures.
|
||||
*
|
||||
* @author Olav Morken, UNINETT AS.
|
||||
* @package SimpleSAMLphp
|
||||
*/
|
||||
class SimpleSAML_Error_Assertion extends SimpleSAML_Error_Exception
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* The assertion which failed, or null if only an expression was passed to the
|
||||
* assert-function.
|
||||
*/
|
||||
private $assertion;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for the assertion exception.
|
||||
*
|
||||
* Should only be called from the onAssertion handler.
|
||||
*
|
||||
* @param string|null $assertion The assertion which failed, or null if the assert-function was
|
||||
* given an expression.
|
||||
*/
|
||||
public function __construct($assertion = null)
|
||||
{
|
||||
assert($assertion === null || is_string($assertion));
|
||||
|
||||
$msg = 'Assertion failed: ' . var_export($assertion, true);
|
||||
parent::__construct($msg);
|
||||
|
||||
$this->assertion = $assertion;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the assertion which failed.
|
||||
*
|
||||
* @return string|null The assertion which failed, or null if the assert-function was called with an expression.
|
||||
*/
|
||||
public function getAssertion()
|
||||
{
|
||||
return $this->assertion;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Install this assertion handler.
|
||||
*
|
||||
* This function will register this assertion handler. If will not enable assertions if they are
|
||||
* disabled.
|
||||
*/
|
||||
public static function installHandler()
|
||||
{
|
||||
|
||||
assert_options(ASSERT_WARNING, 0);
|
||||
assert_options(ASSERT_QUIET_EVAL, 0);
|
||||
assert_options(ASSERT_CALLBACK, array('SimpleSAML_Error_Assertion', 'onAssertion'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle assertion.
|
||||
*
|
||||
* This function handles an assertion.
|
||||
*
|
||||
* @param string $file The file assert was called from.
|
||||
* @param int $line The line assert was called from.
|
||||
* @param mixed $message The expression which was passed to the assert-function.
|
||||
*/
|
||||
public static function onAssertion($file, $line, $message)
|
||||
{
|
||||
|
||||
if (!empty($message)) {
|
||||
$exception = new self($message);
|
||||
} else {
|
||||
$exception = new self();
|
||||
}
|
||||
|
||||
$exception->logError();
|
||||
}
|
||||
}
|
||||
70
lib/SimpleSAML/Error/AuthSource.php
Executable file
70
lib/SimpleSAML/Error/AuthSource.php
Executable file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Baseclass for auth source exceptions.
|
||||
*
|
||||
* @package SimpleSAMLphp_base
|
||||
*
|
||||
*/
|
||||
class SimpleSAML_Error_AuthSource extends SimpleSAML_Error_Error
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Authsource module name.
|
||||
*/
|
||||
private $authsource;
|
||||
|
||||
|
||||
/**
|
||||
* Reason why this request was invalid.
|
||||
*/
|
||||
private $reason;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new AuthSource error.
|
||||
*
|
||||
* @param string $authsource Authsource module name from where this error was thrown.
|
||||
* @param string $reason Description of the error.
|
||||
*/
|
||||
public function __construct($authsource, $reason, $cause = null)
|
||||
{
|
||||
assert(is_string($authsource));
|
||||
assert(is_string($reason));
|
||||
|
||||
$this->authsource = $authsource;
|
||||
$this->reason = $reason;
|
||||
parent::__construct(
|
||||
array(
|
||||
'AUTHSOURCEERROR',
|
||||
'%AUTHSOURCE%' => htmlspecialchars(var_export($this->authsource, true)),
|
||||
'%REASON%' => htmlspecialchars(var_export($this->reason, true))
|
||||
),
|
||||
$cause
|
||||
);
|
||||
|
||||
$this->message = "Error with authentication source '$authsource': $reason";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the authsource module name from where this error was thrown.
|
||||
*
|
||||
* @return string Authsource module name.
|
||||
*/
|
||||
public function getAuthSource()
|
||||
{
|
||||
return $this->authsource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the reason why the request was invalid.
|
||||
*
|
||||
* @return string The reason why the request was invalid.
|
||||
*/
|
||||
public function getReason()
|
||||
{
|
||||
return $this->reason;
|
||||
}
|
||||
}
|
||||
46
lib/SimpleSAML/Error/BadRequest.php
Executable file
46
lib/SimpleSAML/Error/BadRequest.php
Executable file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Exception which will show a 400 Bad Request error page.
|
||||
*
|
||||
* This exception can be thrown from within an module page handler. The user will then be
|
||||
* shown a 400 Bad Request error page.
|
||||
*
|
||||
* @author Olav Morken, UNINETT AS.
|
||||
* @package SimpleSAMLphp
|
||||
*/
|
||||
class SimpleSAML_Error_BadRequest extends SimpleSAML_Error_Error
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Reason why this request was invalid.
|
||||
*/
|
||||
private $reason;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new BadRequest error.
|
||||
*
|
||||
* @param string $reason Description of why the request was unacceptable.
|
||||
*/
|
||||
public function __construct($reason)
|
||||
{
|
||||
assert(is_string($reason));
|
||||
|
||||
$this->reason = $reason;
|
||||
parent::__construct(array('BADREQUEST', '%REASON%' => $this->reason));
|
||||
$this->httpCode = 400;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the reason why the request was invalid.
|
||||
*
|
||||
* @return string The reason why the request was invalid.
|
||||
*/
|
||||
public function getReason()
|
||||
{
|
||||
return $this->reason;
|
||||
}
|
||||
}
|
||||
12
lib/SimpleSAML/Error/BadUserInput.php
Executable file
12
lib/SimpleSAML/Error/BadUserInput.php
Executable file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception indicating illegal innput from user.
|
||||
*
|
||||
* @author Thomas Graff <thomas.graff@uninett.no>
|
||||
* @package SimpleSAMLphp_base
|
||||
*
|
||||
*/
|
||||
class SimpleSAML_Error_BadUserInput extends SimpleSAML_Error_User
|
||||
{
|
||||
|
||||
}
|
||||
35
lib/SimpleSAML/Error/CannotSetCookie.php
Executable file
35
lib/SimpleSAML/Error/CannotSetCookie.php
Executable file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception to indicate that we cannot set a cookie.
|
||||
*
|
||||
* @author Jaime Pérez Crespo <jaime.perez@uninett.no>
|
||||
* @package SimpleSAMLphp
|
||||
*/
|
||||
|
||||
namespace SimpleSAML\Error;
|
||||
|
||||
class CannotSetCookie extends \SimpleSAML_Error_Exception
|
||||
{
|
||||
|
||||
/**
|
||||
* The exception was thrown for unknown reasons.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const UNKNOWN = 0;
|
||||
|
||||
/**
|
||||
* The exception was due to the HTTP headers being already sent, and therefore we cannot send additional headers to
|
||||
* set the cookie.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const HEADERS_SENT = 1;
|
||||
|
||||
/**
|
||||
* The exception was due to trying to set a secure cookie over an insecure channel.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const SECURE_COOKIE = 2;
|
||||
}
|
||||
77
lib/SimpleSAML/Error/ConfigurationError.php
Executable file
77
lib/SimpleSAML/Error/ConfigurationError.php
Executable file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* This exception represents a configuration error.
|
||||
*
|
||||
* @author Jaime Perez Crespo, UNINETT AS <jaime.perez@uninett.no>
|
||||
* @package SimpleSAMLphp
|
||||
*/
|
||||
|
||||
namespace SimpleSAML\Error;
|
||||
|
||||
class ConfigurationError extends \SimpleSAML_Error_Error
|
||||
{
|
||||
|
||||
/**
|
||||
* The reason for this exception.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
protected $reason;
|
||||
|
||||
/**
|
||||
* The configuration file that caused this exception.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
protected $config_file;
|
||||
|
||||
|
||||
/**
|
||||
* ConfigurationError constructor.
|
||||
*
|
||||
* @param string|null $reason The reason for this exception.
|
||||
* @param string|null $file The configuration file that originated this error.
|
||||
* @param array|null $config The configuration array that led to this problem.
|
||||
*/
|
||||
public function __construct($reason = null, $file = null, array $config = null)
|
||||
{
|
||||
$file_str = '';
|
||||
$reason_str = '.';
|
||||
$params = array('CONFIG');
|
||||
if ($file !== null) {
|
||||
$params['%FILE%'] = $file;
|
||||
$basepath = dirname(dirname(dirname(dirname(__FILE__)))).'/';
|
||||
$file_str = '('.str_replace($basepath, '', $file).') ';
|
||||
}
|
||||
if ($reason !== null) {
|
||||
$params['%REASON%'] = $reason;
|
||||
$reason_str = ': '.$reason;
|
||||
}
|
||||
$this->reason = $reason;
|
||||
$this->config_file = $file;
|
||||
parent::__construct($params);
|
||||
$this->message = 'The configuration '.$file_str.'is invalid'.$reason_str;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the reason for this exception.
|
||||
*
|
||||
* @return null|string The reason for this exception.
|
||||
*/
|
||||
public function getReason()
|
||||
{
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the configuration file that caused this exception.
|
||||
*
|
||||
* @return null|string The configuration file that caused this exception.
|
||||
*/
|
||||
public function getConfFile()
|
||||
{
|
||||
return $this->config_file;
|
||||
}
|
||||
}
|
||||
79
lib/SimpleSAML/Error/CriticalConfigurationError.php
Executable file
79
lib/SimpleSAML/Error/CriticalConfigurationError.php
Executable file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* This exception represents a configuration error that we cannot recover from.
|
||||
*
|
||||
* Throwing a critical configuration error indicates that the configuration available is not usable, and as such
|
||||
* SimpleSAMLphp should not try to use it. However, in certain situations we might find a specific configuration
|
||||
* error that makes part of the configuration unusable, while the rest we can still use. In those cases, we can
|
||||
* just pass a configuration array to the constructor, making sure the offending configuration options are removed,
|
||||
* reset to defaults or guessed to some usable value.
|
||||
*
|
||||
* If, for example, we have an error in the 'baseurlpath' configuration option, we can still load the configuration
|
||||
* and substitute the value of that option with one guessed from the environment, using
|
||||
* \SimpleSAML\Utils\HTTP::guessPath(). Doing so, the error is still critical, but at least we can recover up to a
|
||||
* certain point and inform about the error in an ordered manner, without blank pages, logs out of place or even
|
||||
* segfaults.
|
||||
*
|
||||
* @author Jaime Perez Crespo, UNINETT AS <jaime.perez@uninett.no>
|
||||
* @package SimpleSAMLphp
|
||||
*/
|
||||
|
||||
namespace SimpleSAML\Error;
|
||||
|
||||
class CriticalConfigurationError extends ConfigurationError
|
||||
{
|
||||
|
||||
/**
|
||||
* This is the bare minimum configuration that we can use.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $minimum_config = array(
|
||||
'logging.handler' => 'errorlog',
|
||||
'logging.level' => \SimpleSAML\Logger::DEBUG,
|
||||
'errorreporting' => false,
|
||||
'debug' => true,
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* CriticalConfigurationError constructor.
|
||||
*
|
||||
* @param string|null $reason The reason for this critical error.
|
||||
* @param string|null $file The configuration file that originated this error.
|
||||
* @param array|null The configuration array that led to this problem.
|
||||
*/
|
||||
public function __construct($reason = null, $file = null, $config = null)
|
||||
{
|
||||
if ($config === null) {
|
||||
$config = self::$minimum_config;
|
||||
$config['baseurlpath'] = \SimpleSAML\Utils\HTTP::guessBasePath();
|
||||
}
|
||||
|
||||
\SimpleSAML_Configuration::loadFromArray(
|
||||
$config,
|
||||
'',
|
||||
'simplesaml'
|
||||
);
|
||||
parent::__construct($reason, $file);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Exception $exception
|
||||
*
|
||||
* @return CriticalConfigurationError
|
||||
*/
|
||||
public static function fromException(\Exception $exception)
|
||||
{
|
||||
$reason = null;
|
||||
$file = null;
|
||||
if ($exception instanceof ConfigurationError) {
|
||||
$reason = $exception->getReason();
|
||||
$file = $exception->getConfFile();
|
||||
} else {
|
||||
$reason = $exception->getMessage();
|
||||
}
|
||||
return new CriticalConfigurationError($reason, $file);
|
||||
}
|
||||
}
|
||||
296
lib/SimpleSAML/Error/Error.php
Executable file
296
lib/SimpleSAML/Error/Error.php
Executable file
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Class that wraps SimpleSAMLphp errors in exceptions.
|
||||
*
|
||||
* @author Olav Morken, UNINETT AS.
|
||||
* @package SimpleSAMLphp
|
||||
*/
|
||||
class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception
|
||||
{
|
||||
/**
|
||||
* The error code.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $errorCode;
|
||||
|
||||
/**
|
||||
* The http code.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $httpCode = 500;
|
||||
|
||||
/**
|
||||
* The error title tag in dictionary.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $dictTitle;
|
||||
|
||||
/**
|
||||
* The error description tag in dictionary.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $dictDescr;
|
||||
|
||||
/**
|
||||
* The name of module that threw the error.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $module = null;
|
||||
|
||||
/**
|
||||
* The parameters for the error.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $parameters;
|
||||
|
||||
/**
|
||||
* Name of custom include template for the error.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $includeTemplate = null;
|
||||
|
||||
/**
|
||||
* Constructor for this error.
|
||||
*
|
||||
* The error can either be given as a string, or as an array. If it is an array, the first element in the array
|
||||
* (with index 0), is the error code, while the other elements are replacements for the error text.
|
||||
*
|
||||
* @param mixed $errorCode One of the error codes defined in the errors dictionary.
|
||||
* @param Exception $cause The exception which caused this fatal error (if any). Optional.
|
||||
* @param int|null $httpCode The HTTP response code to use. Optional.
|
||||
*/
|
||||
public function __construct($errorCode, Exception $cause = null, $httpCode = null)
|
||||
{
|
||||
assert(is_string($errorCode) || is_array($errorCode));
|
||||
|
||||
if (is_array($errorCode)) {
|
||||
$this->parameters = $errorCode;
|
||||
unset($this->parameters[0]);
|
||||
$this->errorCode = $errorCode[0];
|
||||
} else {
|
||||
$this->parameters = array();
|
||||
$this->errorCode = $errorCode;
|
||||
}
|
||||
|
||||
if (isset($httpCode)) {
|
||||
$this->httpCode = $httpCode;
|
||||
}
|
||||
|
||||
$moduleCode = explode(':', $this->errorCode, 2);
|
||||
if (count($moduleCode) === 2) {
|
||||
$this->module = $moduleCode[0];
|
||||
$this->dictTitle = '{'.$this->module.':errors:title_'.$moduleCode[1].'}';
|
||||
$this->dictDescr = '{'.$this->module.':errors:descr_'.$moduleCode[1].'}';
|
||||
} else {
|
||||
$this->dictTitle = SimpleSAML\Error\ErrorCodes::getErrorCodeTitle($this->errorCode);
|
||||
$this->dictDescr = SimpleSAML\Error\ErrorCodes::getErrorCodeDescription($this->errorCode);
|
||||
}
|
||||
|
||||
if (!empty($this->parameters)) {
|
||||
$msg = $this->errorCode.'(';
|
||||
foreach ($this->parameters as $k => $v) {
|
||||
if ($k === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$msg .= var_export($k, true).' => '.var_export($v, true).', ';
|
||||
}
|
||||
$msg = substr($msg, 0, -2).')';
|
||||
} else {
|
||||
$msg = $this->errorCode;
|
||||
}
|
||||
parent::__construct($msg, -1, $cause);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the error code given when throwing this error.
|
||||
*
|
||||
* @return string The error code.
|
||||
*/
|
||||
public function getErrorCode()
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the error parameters given when throwing this error.
|
||||
*
|
||||
* @return array The parameters.
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the error title tag in dictionary.
|
||||
*
|
||||
* @return string The error title tag.
|
||||
*/
|
||||
public function getDictTitle()
|
||||
{
|
||||
return $this->dictTitle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the error description tag in dictionary.
|
||||
*
|
||||
* @return string The error description tag.
|
||||
*/
|
||||
public function getDictDescr()
|
||||
{
|
||||
return $this->dictDescr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the HTTP return code for this error.
|
||||
*
|
||||
* This should be overridden by subclasses who want a different return code than 500 Internal Server Error.
|
||||
*/
|
||||
protected function setHTTPCode()
|
||||
{
|
||||
// Some mostly used HTTP codes
|
||||
$httpCodesMap = array(
|
||||
400 => 'HTTP/1.0 400 Bad Request',
|
||||
403 => 'HTTP/1.0 403 Forbidden',
|
||||
404 => 'HTTP/1.0 404 Not Found',
|
||||
405 => 'HTTP/1.0 405 Method Not Allowed',
|
||||
500 => 'HTTP/1.0 500 Internal Server Error',
|
||||
501 => 'HTTP/1.0 501 Method Not Implemented',
|
||||
503 => 'HTTP/1.0 503 Service Temporarily Unavailable',
|
||||
);
|
||||
|
||||
$httpCode = $this->httpCode;
|
||||
|
||||
if (function_exists('http_response_code')) {
|
||||
http_response_code($httpCode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!array_key_exists($this->httpCode, $httpCodesMap)) {
|
||||
$httpCode = 500;
|
||||
SimpleSAML\Logger::warning('HTTP response code not defined: '.var_export($this->httpCode, true));
|
||||
}
|
||||
|
||||
header($httpCodesMap[$httpCode]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save an error report.
|
||||
*
|
||||
* @return array The array with the error report data.
|
||||
*/
|
||||
protected function saveError()
|
||||
{
|
||||
$data = $this->format(true);
|
||||
$emsg = array_shift($data);
|
||||
$etrace = implode("\n", $data);
|
||||
|
||||
$reportId = bin2hex(openssl_random_pseudo_bytes(4));
|
||||
SimpleSAML\Logger::error('Error report with id '.$reportId.' generated.');
|
||||
|
||||
$config = SimpleSAML_Configuration::getInstance();
|
||||
$session = SimpleSAML_Session::getSessionFromRequest();
|
||||
|
||||
if (isset($_SERVER['HTTP_REFERER'])) {
|
||||
$referer = $_SERVER['HTTP_REFERER'];
|
||||
// remove anything after the first '?' or ';', just in case it contains any sensitive data
|
||||
$referer = explode('?', $referer, 2);
|
||||
$referer = $referer[0];
|
||||
$referer = explode(';', $referer, 2);
|
||||
$referer = $referer[0];
|
||||
} else {
|
||||
$referer = 'unknown';
|
||||
}
|
||||
$errorData = array(
|
||||
'exceptionMsg' => $emsg,
|
||||
'exceptionTrace' => $etrace,
|
||||
'reportId' => $reportId,
|
||||
'trackId' => $session->getTrackID(),
|
||||
'url' => \SimpleSAML\Utils\HTTP::getSelfURLNoQuery(),
|
||||
'version' => $config->getVersion(),
|
||||
'referer' => $referer,
|
||||
);
|
||||
$session->setData('core:errorreport', $reportId, $errorData);
|
||||
|
||||
return $errorData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display this error.
|
||||
*
|
||||
* This method displays a standard SimpleSAMLphp error page and exits.
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
$this->setHTTPCode();
|
||||
|
||||
// log the error message
|
||||
$this->logError();
|
||||
|
||||
$errorData = $this->saveError();
|
||||
$config = SimpleSAML_Configuration::getInstance();
|
||||
|
||||
$data = array();
|
||||
$data['showerrors'] = $config->getBoolean('showerrors', true);
|
||||
$data['error'] = $errorData;
|
||||
$data['errorCode'] = $this->errorCode;
|
||||
$data['parameters'] = $this->parameters;
|
||||
$data['module'] = $this->module;
|
||||
$data['dictTitle'] = $this->dictTitle;
|
||||
$data['dictDescr'] = $this->dictDescr;
|
||||
$data['includeTemplate'] = $this->includeTemplate;
|
||||
$data['clipboard.js'] = true;
|
||||
|
||||
// check if there is a valid technical contact email address
|
||||
if ($config->getBoolean('errorreporting', true) &&
|
||||
$config->getString('technicalcontact_email', 'na@example.org') !== 'na@example.org'
|
||||
) {
|
||||
// enable error reporting
|
||||
$baseurl = \SimpleSAML\Utils\HTTP::getBaseURL();
|
||||
$data['errorReportAddress'] = $baseurl.'errorreport.php';
|
||||
}
|
||||
|
||||
$data['email'] = '';
|
||||
$session = SimpleSAML_Session::getSessionFromRequest();
|
||||
$authorities = $session->getAuthorities();
|
||||
foreach ($authorities as $authority) {
|
||||
$attributes = $session->getAuthData($authority, 'Attributes');
|
||||
if ($attributes !== null && array_key_exists('mail', $attributes) && count($attributes['mail']) > 0) {
|
||||
$data['email'] = $attributes['mail'][0];
|
||||
break; // enough, don't need to get all available mails, if more than one
|
||||
}
|
||||
}
|
||||
|
||||
$show_function = $config->getArray('errors.show_function', null);
|
||||
if (isset($show_function)) {
|
||||
assert(is_callable($show_function));
|
||||
call_user_func($show_function, $config, $data);
|
||||
assert(false);
|
||||
} else {
|
||||
$t = new SimpleSAML_XHTML_Template($config, 'error.php', 'errors');
|
||||
$t->data = array_merge($t->data, $data);
|
||||
$t->data['dictTitleTranslated'] = $t->getTranslator()->t($t->data['dictTitle']);
|
||||
$t->data['dictDescrTranslated'] = $t->getTranslator()->t($t->data['dictDescr'], $t->data['parameters']);
|
||||
$t->show();
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
188
lib/SimpleSAML/Error/ErrorCodes.php
Executable file
188
lib/SimpleSAML/Error/ErrorCodes.php
Executable file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
/**
|
||||
* Class that maps SimpleSAMLphp error codes to translateable strings.
|
||||
*
|
||||
* @author Hanne Moa, UNINETT AS. <hanne.moa@uninett.no>
|
||||
* @package SimpleSAMLphp
|
||||
*/
|
||||
|
||||
namespace SimpleSAML\Error;
|
||||
|
||||
class ErrorCodes
|
||||
{
|
||||
/**
|
||||
* Fetch all default translation strings for error code titles.
|
||||
*
|
||||
* @return array A map from error code to error code title
|
||||
*/
|
||||
final public static function defaultGetAllErrorCodeTitles()
|
||||
{
|
||||
return array(
|
||||
'ACSPARAMS' => \SimpleSAML\Locale\Translate::noop('{errors:title_ACSPARAMS}'),
|
||||
'ARSPARAMS' => \SimpleSAML\Locale\Translate::noop('{errors:title_ARSPARAMS}'),
|
||||
'AUTHSOURCEERROR' => \SimpleSAML\Locale\Translate::noop('{errors:title_AUTHSOURCEERROR}'),
|
||||
'BADREQUEST' => \SimpleSAML\Locale\Translate::noop('{errors:title_BADREQUEST}'),
|
||||
'CASERROR' => \SimpleSAML\Locale\Translate::noop('{errors:title_CASERROR}'),
|
||||
'CONFIG' => \SimpleSAML\Locale\Translate::noop('{errors:title_CONFIG}'),
|
||||
'CREATEREQUEST' => \SimpleSAML\Locale\Translate::noop('{errors:title_CREATEREQUEST}'),
|
||||
'DISCOPARAMS' => \SimpleSAML\Locale\Translate::noop('{errors:title_DISCOPARAMS}'),
|
||||
'GENERATEAUTHNRESPONSE' => \SimpleSAML\Locale\Translate::noop('{errors:title_GENERATEAUTHNRESPONSE}'),
|
||||
'INVALIDCERT' => \SimpleSAML\Locale\Translate::noop('{errors:title_INVALIDCERT}'),
|
||||
'LDAPERROR' => \SimpleSAML\Locale\Translate::noop('{errors:title_LDAPERROR}'),
|
||||
'LOGOUTINFOLOST' => \SimpleSAML\Locale\Translate::noop('{errors:title_LOGOUTINFOLOST}'),
|
||||
'LOGOUTREQUEST' => \SimpleSAML\Locale\Translate::noop('{errors:title_LOGOUTREQUEST}'),
|
||||
'MEMCACHEDOWN' => \SimpleSAML\Locale\Translate::noop('{errors:title_MEMCACHEDOWN}'),
|
||||
'METADATA' => \SimpleSAML\Locale\Translate::noop('{errors:title_METADATA}'),
|
||||
'METADATANOTFOUND' => \SimpleSAML\Locale\Translate::noop('{errors:title_METADATANOTFOUND}'),
|
||||
'NOACCESS' => \SimpleSAML\Locale\Translate::noop('{errors:title_NOACCESS}'),
|
||||
'NOCERT' => \SimpleSAML\Locale\Translate::noop('{errors:title_NOCERT}'),
|
||||
'NORELAYSTATE' => \SimpleSAML\Locale\Translate::noop('{errors:title_NORELAYSTATE}'),
|
||||
'NOSTATE' => \SimpleSAML\Locale\Translate::noop('{errors:title_NOSTATE}'),
|
||||
'NOTFOUND' => \SimpleSAML\Locale\Translate::noop('{errors:title_NOTFOUND}'),
|
||||
'NOTFOUNDREASON' => \SimpleSAML\Locale\Translate::noop('{errors:title_NOTFOUNDREASON}'),
|
||||
'NOTSET' => \SimpleSAML\Locale\Translate::noop('{errors:title_NOTSET}'),
|
||||
'NOTVALIDCERT' => \SimpleSAML\Locale\Translate::noop('{errors:title_NOTVALIDCERT}'),
|
||||
'PROCESSASSERTION' => \SimpleSAML\Locale\Translate::noop('{errors:title_PROCESSASSERTION}'),
|
||||
'PROCESSAUTHNREQUEST' => \SimpleSAML\Locale\Translate::noop('{errors:title_PROCESSAUTHNREQUEST}'),
|
||||
'RESPONSESTATUSNOSUCCESS' => \SimpleSAML\Locale\Translate::noop('{errors:title_RESPONSESTATUSNOSUCCESS}'),
|
||||
'SLOSERVICEPARAMS' => \SimpleSAML\Locale\Translate::noop('{errors:title_SLOSERVICEPARAMS}'),
|
||||
'SSOPARAMS' => \SimpleSAML\Locale\Translate::noop('{errors:title_SSOPARAMS}'),
|
||||
'UNHANDLEDEXCEPTION' => \SimpleSAML\Locale\Translate::noop('{errors:title_UNHANDLEDEXCEPTION}'),
|
||||
'UNKNOWNCERT' => \SimpleSAML\Locale\Translate::noop('{errors:title_UNKNOWNCERT}'),
|
||||
'USERABORTED' => \SimpleSAML\Locale\Translate::noop('{errors:title_USERABORTED}'),
|
||||
'WRONGUSERPASS' => \SimpleSAML\Locale\Translate::noop('{errors:title_WRONGUSERPASS}'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch all translation strings for error code titles.
|
||||
*
|
||||
* Extend this to add error codes.
|
||||
*
|
||||
* @return array A map from error code to error code title
|
||||
*/
|
||||
public static function getAllErrorCodeTitles()
|
||||
{
|
||||
return self::defaultGetAllErrorCodeTitles();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch all default translation strings for error code descriptions.
|
||||
*
|
||||
* @return string A map from error code to error code description
|
||||
*/
|
||||
final public static function defaultGetAllErrorCodeDescriptions()
|
||||
{
|
||||
return array(
|
||||
'ACSPARAMS' => \SimpleSAML\Locale\Translate::noop('{errors:descr_ACSPARAMS}'),
|
||||
'ARSPARAMS' => \SimpleSAML\Locale\Translate::noop('{errors:descr_ARSPARAMS}'),
|
||||
'AUTHSOURCEERROR' => \SimpleSAML\Locale\Translate::noop('{errors:descr_AUTHSOURCEERROR}'),
|
||||
'BADREQUEST' => \SimpleSAML\Locale\Translate::noop('{errors:descr_BADREQUEST}'),
|
||||
'CASERROR' => \SimpleSAML\Locale\Translate::noop('{errors:descr_CASERROR}'),
|
||||
'CONFIG' => \SimpleSAML\Locale\Translate::noop('{errors:descr_CONFIG}'),
|
||||
'CREATEREQUEST' => \SimpleSAML\Locale\Translate::noop('{errors:descr_CREATEREQUEST}'),
|
||||
'DISCOPARAMS' => \SimpleSAML\Locale\Translate::noop('{errors:descr_DISCOPARAMS}'),
|
||||
'GENERATEAUTHNRESPONSE' => \SimpleSAML\Locale\Translate::noop('{errors:descr_GENERATEAUTHNRESPONSE}'),
|
||||
'INVALIDCERT' => \SimpleSAML\Locale\Translate::noop('{errors:descr_INVALIDCERT}'),
|
||||
'LDAPERROR' => \SimpleSAML\Locale\Translate::noop('{errors:descr_LDAPERROR}'),
|
||||
'LOGOUTINFOLOST' => \SimpleSAML\Locale\Translate::noop('{errors:descr_LOGOUTINFOLOST}'),
|
||||
'LOGOUTREQUEST' => \SimpleSAML\Locale\Translate::noop('{errors:descr_LOGOUTREQUEST}'),
|
||||
'MEMCACHEDOWN' => \SimpleSAML\Locale\Translate::noop('{errors:descr_MEMCACHEDOWN}'),
|
||||
'METADATA' => \SimpleSAML\Locale\Translate::noop('{errors:descr_METADATA}'),
|
||||
'METADATANOTFOUND' => \SimpleSAML\Locale\Translate::noop('{errors:descr_METADATANOTFOUND}'),
|
||||
'NOACCESS' => \SimpleSAML\Locale\Translate::noop('{errors:descr_NOACCESS}'),
|
||||
'NOCERT' => \SimpleSAML\Locale\Translate::noop('{errors:descr_NOCERT}'),
|
||||
'NORELAYSTATE' => \SimpleSAML\Locale\Translate::noop('{errors:descr_NORELAYSTATE}'),
|
||||
'NOSTATE' => \SimpleSAML\Locale\Translate::noop('{errors:descr_NOSTATE}'),
|
||||
'NOTFOUND' => \SimpleSAML\Locale\Translate::noop('{errors:descr_NOTFOUND}'),
|
||||
'NOTFOUNDREASON' => \SimpleSAML\Locale\Translate::noop('{errors:descr_NOTFOUNDREASON}'),
|
||||
'NOTSET' => \SimpleSAML\Locale\Translate::noop('{errors:descr_NOTSET}'),
|
||||
'NOTVALIDCERT' => \SimpleSAML\Locale\Translate::noop('{errors:descr_NOTVALIDCERT}'),
|
||||
'PROCESSASSERTION' => \SimpleSAML\Locale\Translate::noop('{errors:descr_PROCESSASSERTION}'),
|
||||
'PROCESSAUTHNREQUEST' => \SimpleSAML\Locale\Translate::noop('{errors:descr_PROCESSAUTHNREQUEST}'),
|
||||
'RESPONSESTATUSNOSUCCESS' => \SimpleSAML\Locale\Translate::noop('{errors:descr_RESPONSESTATUSNOSUCCESS}'),
|
||||
'SLOSERVICEPARAMS' => \SimpleSAML\Locale\Translate::noop('{errors:descr_SLOSERVICEPARAMS}'),
|
||||
'SSOPARAMS' => \SimpleSAML\Locale\Translate::noop('{errors:descr_SSOPARAMS}'),
|
||||
'UNHANDLEDEXCEPTION' => \SimpleSAML\Locale\Translate::noop('{errors:descr_UNHANDLEDEXCEPTION}'),
|
||||
'UNKNOWNCERT' => \SimpleSAML\Locale\Translate::noop('{errors:descr_UNKNOWNCERT}'),
|
||||
'USERABORTED' => \SimpleSAML\Locale\Translate::noop('{errors:descr_USERABORTED}'),
|
||||
'WRONGUSERPASS' => \SimpleSAML\Locale\Translate::noop('{errors:descr_WRONGUSERPASS}'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all translation strings for error code descriptions.
|
||||
*
|
||||
* Extend this to add error codes.
|
||||
*
|
||||
* @return string A map from error code to error code description
|
||||
*/
|
||||
public static function getAllErrorCodeDescriptions()
|
||||
{
|
||||
return self::defaultGetAllErrorCodeDescriptions();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a map of both errorcode titles and descriptions
|
||||
*
|
||||
* Convenience-method for template-callers
|
||||
*
|
||||
* @return array An array containing both errorcode maps.
|
||||
*/
|
||||
public static function getAllErrorCodeMessages()
|
||||
{
|
||||
return array(
|
||||
'title' => self::getAllErrorCodeTitles(),
|
||||
'descr' => self::getAllErrorCodeDescriptions(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a translation string for a title for a given error code.
|
||||
*
|
||||
* @param string $errorCode The error code to look up
|
||||
*
|
||||
* @return string A string to translate
|
||||
*/
|
||||
public static function getErrorCodeTitle($errorCode)
|
||||
{
|
||||
$errorCodeTitles = self::getAllErrorCodeTitles();
|
||||
return $errorCodeTitles[$errorCode];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a translation string for a description for a given error code.
|
||||
*
|
||||
* @param string $errorCode The error code to look up
|
||||
*
|
||||
* @return string A string to translate
|
||||
*/
|
||||
public static function getErrorCodeDescription($errorCode)
|
||||
{
|
||||
$errorCodeDescriptions = self::getAllErrorCodeDescriptions();
|
||||
return $errorCodeDescriptions[$errorCode];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get both title and description for a specific error code
|
||||
*
|
||||
* Convenience-method for template-callers
|
||||
*
|
||||
* @param string $errorCode The error code to look up
|
||||
*
|
||||
* @return array An array containing both errorcode strings.
|
||||
*/
|
||||
public static function getErrorCodeMessage($errorCode)
|
||||
{
|
||||
return array(
|
||||
'title' => self::getErrorCodeTitle($errorCode),
|
||||
'descr' => self::getErrorCodeDescription($errorCode),
|
||||
);
|
||||
}
|
||||
}
|
||||
316
lib/SimpleSAML/Error/Exception.php
Executable file
316
lib/SimpleSAML/Error/Exception.php
Executable file
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Base class for SimpleSAMLphp Exceptions
|
||||
*
|
||||
* This class tries to make sure that every exception is serializable.
|
||||
*
|
||||
* @author Thomas Graff <thomas.graff@uninett.no>
|
||||
* @package SimpleSAMLphp
|
||||
*/
|
||||
class SimpleSAML_Error_Exception extends Exception
|
||||
{
|
||||
|
||||
/**
|
||||
* The backtrace for this exception.
|
||||
*
|
||||
* We need to save the backtrace, since we cannot rely on
|
||||
* serializing the Exception::trace-variable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $backtrace;
|
||||
|
||||
|
||||
/**
|
||||
* The cause of this exception.
|
||||
*
|
||||
* @var SimpleSAML_Error_Exception
|
||||
*/
|
||||
private $cause;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for this error.
|
||||
*
|
||||
* Note that the cause will be converted to a SimpleSAML_Error_UnserializableException unless it is a subclass of
|
||||
* SimpleSAML_Error_Exception.
|
||||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Error code
|
||||
* @param Exception|null $cause The cause of this exception.
|
||||
*/
|
||||
public function __construct($message, $code = 0, Exception $cause = null)
|
||||
{
|
||||
assert(is_string($message));
|
||||
assert(is_int($code));
|
||||
|
||||
parent::__construct($message, $code);
|
||||
|
||||
$this->initBacktrace($this);
|
||||
|
||||
if ($cause !== null) {
|
||||
$this->cause = SimpleSAML_Error_Exception::fromException($cause);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert any exception into a SimpleSAML_Error_Exception.
|
||||
*
|
||||
* @param Exception $e The exception.
|
||||
*
|
||||
* @return SimpleSAML_Error_Exception The new exception.
|
||||
*/
|
||||
public static function fromException(Exception $e)
|
||||
{
|
||||
|
||||
if ($e instanceof SimpleSAML_Error_Exception) {
|
||||
return $e;
|
||||
}
|
||||
return new SimpleSAML_Error_UnserializableException($e);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the backtrace from the given exception.
|
||||
*
|
||||
* @param Exception $exception The exception we should fetch the backtrace from.
|
||||
*/
|
||||
protected function initBacktrace(Exception $exception)
|
||||
{
|
||||
|
||||
$this->backtrace = array();
|
||||
|
||||
// position in the top function on the stack
|
||||
$pos = $exception->getFile().':'.$exception->getLine();
|
||||
|
||||
foreach ($exception->getTrace() as $t) {
|
||||
$function = $t['function'];
|
||||
if (array_key_exists('class', $t)) {
|
||||
$function = $t['class'].'::'.$function;
|
||||
}
|
||||
|
||||
$this->backtrace[] = $pos.' ('.$function.')';
|
||||
|
||||
if (array_key_exists('file', $t)) {
|
||||
$pos = $t['file'].':'.$t['line'];
|
||||
} else {
|
||||
$pos = '[builtin]';
|
||||
}
|
||||
}
|
||||
|
||||
$this->backtrace[] = $pos.' (N/A)';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the backtrace.
|
||||
*
|
||||
* @return array An array where each function call is a single item.
|
||||
*/
|
||||
public function getBacktrace()
|
||||
{
|
||||
return $this->backtrace;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the cause of this exception.
|
||||
*
|
||||
* @return SimpleSAML_Error_Exception|null The cause of this exception.
|
||||
*/
|
||||
public function getCause()
|
||||
{
|
||||
return $this->cause;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the class of this exception.
|
||||
*
|
||||
* @return string The name of the class.
|
||||
*/
|
||||
public function getClass()
|
||||
{
|
||||
return get_class($this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format this exception for logging.
|
||||
*
|
||||
* Create an array of lines for logging.
|
||||
*
|
||||
* @param boolean $anonymize Whether the resulting messages should be anonymized or not.
|
||||
*
|
||||
* @return array Log lines that should be written out.
|
||||
*/
|
||||
public function format($anonymize = false)
|
||||
{
|
||||
$ret = array(
|
||||
$this->getClass().': '.$this->getMessage(),
|
||||
);
|
||||
return array_merge($ret, $this->formatBacktrace($anonymize));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format the backtrace for logging.
|
||||
*
|
||||
* Create an array of lines for logging from the backtrace.
|
||||
*
|
||||
* @param boolean $anonymize Whether the resulting messages should be anonymized or not.
|
||||
*
|
||||
* @return array All lines of the backtrace, properly formatted.
|
||||
*/
|
||||
public function formatBacktrace($anonymize = false)
|
||||
{
|
||||
$ret = array();
|
||||
$basedir = SimpleSAML_Configuration::getInstance()->getBaseDir();
|
||||
|
||||
$e = $this;
|
||||
do {
|
||||
if ($e !== $this) {
|
||||
$ret[] = 'Caused by: '.$e->getClass().': '.$e->getMessage();
|
||||
}
|
||||
$ret[] = 'Backtrace:';
|
||||
|
||||
$depth = count($e->backtrace);
|
||||
foreach ($e->backtrace as $i => $trace) {
|
||||
if ($anonymize) {
|
||||
$trace = str_replace($basedir, '', $trace);
|
||||
}
|
||||
|
||||
$ret[] = ($depth - $i - 1).' '.$trace;
|
||||
}
|
||||
$e = $e->cause;
|
||||
} while ($e !== null);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print the backtrace to the log if the 'debug' option is enabled in the configuration.
|
||||
*/
|
||||
protected function logBacktrace($level = \SimpleSAML\Logger::DEBUG)
|
||||
{
|
||||
// see if debugging is enabled for backtraces
|
||||
$debug = SimpleSAML_Configuration::getInstance()->getArrayize('debug', array('backtraces' => false));
|
||||
|
||||
if (!(in_array('backtraces', $debug, true) // implicitly enabled
|
||||
|| (array_key_exists('backtraces', $debug) && $debug['backtraces'] === true) // explicitly set
|
||||
// TODO: deprecate the old style and remove it in 2.0
|
||||
|| (array_key_exists(0, $debug) && $debug[0] === true) // old style 'debug' configuration option
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$backtrace = $this->formatBacktrace();
|
||||
|
||||
$callback = array('\SimpleSAML\Logger');
|
||||
$functions = array(
|
||||
\SimpleSAML\Logger::ERR => 'error',
|
||||
\SimpleSAML\Logger::WARNING => 'warning',
|
||||
\SimpleSAML\Logger::INFO => 'info',
|
||||
\SimpleSAML\Logger::DEBUG => 'debug',
|
||||
);
|
||||
$callback[] = $functions[$level];
|
||||
|
||||
foreach ($backtrace as $line) {
|
||||
call_user_func($callback, $line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print the exception to the log, by default with log level error.
|
||||
*
|
||||
* Override to allow errors extending this class to specify the log level themselves.
|
||||
*
|
||||
* @param int $default_level The log level to use if this method was not overridden.
|
||||
*/
|
||||
public function log($default_level)
|
||||
{
|
||||
$fn = array(
|
||||
SimpleSAML\Logger::ERR => 'logError',
|
||||
SimpleSAML\Logger::WARNING => 'logWarning',
|
||||
SimpleSAML\Logger::INFO => 'logInfo',
|
||||
SimpleSAML\Logger::DEBUG => 'logDebug',
|
||||
);
|
||||
call_user_func(array($this, $fn[$default_level]), $default_level);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print the exception to the log with log level error.
|
||||
*
|
||||
* This function will write this exception to the log, including a full backtrace.
|
||||
*/
|
||||
public function logError()
|
||||
{
|
||||
SimpleSAML\Logger::error($this->getClass().': '.$this->getMessage());
|
||||
$this->logBacktrace(\SimpleSAML\Logger::ERR);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print the exception to the log with log level warning.
|
||||
*
|
||||
* This function will write this exception to the log, including a full backtrace.
|
||||
*/
|
||||
public function logWarning()
|
||||
{
|
||||
SimpleSAML\Logger::warning($this->getClass().': '.$this->getMessage());
|
||||
$this->logBacktrace(\SimpleSAML\Logger::WARNING);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print the exception to the log with log level info.
|
||||
*
|
||||
* This function will write this exception to the log, including a full backtrace.
|
||||
*/
|
||||
public function logInfo()
|
||||
{
|
||||
SimpleSAML\Logger::info($this->getClass().': '.$this->getMessage());
|
||||
$this->logBacktrace(\SimpleSAML\Logger::INFO);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print the exception to the log with log level debug.
|
||||
*
|
||||
* This function will write this exception to the log, including a full backtrace.
|
||||
*/
|
||||
public function logDebug()
|
||||
{
|
||||
SimpleSAML\Logger::debug($this->getClass().': '.$this->getMessage());
|
||||
$this->logBacktrace(\SimpleSAML\Logger::DEBUG);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function for serialization.
|
||||
*
|
||||
* This function builds a list of all variables which should be serialized. It will serialize all variables except
|
||||
* the Exception::trace variable.
|
||||
*
|
||||
* @return array Array with the variables that should be serialized.
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
|
||||
$ret = array_keys((array) $this);
|
||||
|
||||
foreach ($ret as $i => $e) {
|
||||
if ($e === "\0Exception\0trace") {
|
||||
unset($ret[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
12
lib/SimpleSAML/Error/InvalidCredential.php
Executable file
12
lib/SimpleSAML/Error/InvalidCredential.php
Executable file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception indicating wrong password given by user.
|
||||
*
|
||||
* @author Thomas Graff <thomas.graff@uninett.no>
|
||||
* @package SimpleSAMLphp_base
|
||||
*
|
||||
*/
|
||||
class SimpleSAML_Error_InvalidCredential extends SimpleSAML_Error_User
|
||||
{
|
||||
|
||||
}
|
||||
27
lib/SimpleSAML/Error/MetadataNotFound.php
Executable file
27
lib/SimpleSAML/Error/MetadataNotFound.php
Executable file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Error for missing metadata.
|
||||
*
|
||||
* @package SimpleSAMLphp
|
||||
*/
|
||||
class SimpleSAML_Error_MetadataNotFound extends SimpleSAML_Error_Error
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Create the error
|
||||
*
|
||||
* @param string $entityId The entityID we were unable to locate.
|
||||
*/
|
||||
public function __construct($entityId)
|
||||
{
|
||||
assert(is_string($entityId));
|
||||
|
||||
$this->includeTemplate = 'core:no_metadata.tpl.php';
|
||||
parent::__construct(array(
|
||||
'METADATANOTFOUND',
|
||||
'%ENTITYID%' => htmlspecialchars(var_export($entityId, true))
|
||||
));
|
||||
}
|
||||
}
|
||||
15
lib/SimpleSAML/Error/NoPassive.php
Executable file
15
lib/SimpleSAML/Error/NoPassive.php
Executable file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Class SimpleSAML_Error_NoPassive
|
||||
*
|
||||
* @deprecated This class has been deprecated and will be removed in SimpleSAMLphp 2.0. Please use
|
||||
* SimpleSAML\Module\saml\Error\NoPassive instead.
|
||||
*
|
||||
* @see \SimpleSAML\Module\saml\Error\NoPassive
|
||||
*/
|
||||
class SimpleSAML_Error_NoPassive extends SimpleSAML_Error_Exception
|
||||
{
|
||||
|
||||
}
|
||||
21
lib/SimpleSAML/Error/NoState.php
Executable file
21
lib/SimpleSAML/Error/NoState.php
Executable file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Exception which will show a page telling the user
|
||||
* that we don't know what to do.
|
||||
*
|
||||
* @package SimpleSAMLphp
|
||||
*/
|
||||
class SimpleSAML_Error_NoState extends SimpleSAML_Error_Error
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Create the error
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->includeTemplate = 'core:no_state.tpl.php';
|
||||
parent::__construct('NOSTATE');
|
||||
}
|
||||
}
|
||||
72
lib/SimpleSAML/Error/NotFound.php
Executable file
72
lib/SimpleSAML/Error/NotFound.php
Executable file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Exception which will show a 404 Not Found error page.
|
||||
*
|
||||
* This exception can be thrown from within a module page handler. The user will then be shown a 404 Not Found error
|
||||
* page.
|
||||
*
|
||||
* @author Olav Morken, UNINETT AS.
|
||||
* @package SimpleSAMLphp
|
||||
*/
|
||||
class SimpleSAML_Error_NotFound extends SimpleSAML_Error_Error
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Reason why the given page could not be found.
|
||||
*/
|
||||
private $reason;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new NotFound error
|
||||
*
|
||||
* @param string $reason Optional description of why the given page could not be found.
|
||||
*/
|
||||
public function __construct($reason = null)
|
||||
{
|
||||
|
||||
assert($reason === null || is_string($reason));
|
||||
|
||||
$url = \SimpleSAML\Utils\HTTP::getSelfURL();
|
||||
|
||||
if ($reason === null) {
|
||||
parent::__construct(array('NOTFOUND', '%URL%' => $url));
|
||||
$this->message = "The requested page '$url' could not be found.";
|
||||
} else {
|
||||
parent::__construct(array('NOTFOUNDREASON', '%URL%' => $url, '%REASON%' => $reason));
|
||||
$this->message = "The requested page '$url' could not be found. ".$reason;
|
||||
}
|
||||
|
||||
$this->reason = $reason;
|
||||
$this->httpCode = 404;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the reason why the given page could not be found.
|
||||
*
|
||||
* @return string|null The reason why the page could not be found.
|
||||
*/
|
||||
public function getReason()
|
||||
{
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* NotFound exceptions don't need to display a backtrace, as they are very simple and the trace is usually trivial,
|
||||
* so just log the message without any backtrace at all.
|
||||
*
|
||||
* @param bool $anonymize Whether to anonymize the trace or not.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function format($anonymize = false)
|
||||
{
|
||||
return array(
|
||||
$this->getClass().': '.$this->getMessage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
15
lib/SimpleSAML/Error/ProxyCountExceeded.php
Executable file
15
lib/SimpleSAML/Error/ProxyCountExceeded.php
Executable file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Class SimpleSAML_Error_ProxyCountExceeded
|
||||
*
|
||||
* @deprecated This class has been deprecated and will be removed in SimpleSAMLphp 2.0. Please use
|
||||
* SimpleSAML\Module\saml\Error\ProxyCountExceeded instead.
|
||||
*
|
||||
* @see \SimpleSAML\Module\saml\Error\ProxyCountExceeded
|
||||
*/
|
||||
class SimpleSAML_Error_ProxyCountExceeded extends SimpleSAML_Error_Exception
|
||||
{
|
||||
|
||||
}
|
||||
57
lib/SimpleSAML/Error/UnserializableException.php
Executable file
57
lib/SimpleSAML/Error/UnserializableException.php
Executable file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class for saving normal exceptions for serialization.
|
||||
*
|
||||
* This class is used by the SimpleSAML_Auth_State class when it needs
|
||||
* to serialize an exception which doesn't subclass the
|
||||
* SimpleSAML_Error_Exception class.
|
||||
*
|
||||
* It creates a new exception which contains the backtrace and message
|
||||
* of the original exception.
|
||||
*
|
||||
* @package SimpleSAMLphp
|
||||
*/
|
||||
class SimpleSAML_Error_UnserializableException extends SimpleSAML_Error_Exception
|
||||
{
|
||||
|
||||
/**
|
||||
* The classname of the original exception.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $class;
|
||||
|
||||
|
||||
/**
|
||||
* Create a serializable exception representing an unserializable exception.
|
||||
*
|
||||
* @param Exception $original The original exception.
|
||||
*/
|
||||
public function __construct(Exception $original)
|
||||
{
|
||||
|
||||
$this->class = get_class($original);
|
||||
$msg = $original->getMessage();
|
||||
$code = $original->getCode();
|
||||
|
||||
if (!is_int($code)) {
|
||||
// PDOException uses a string as the code. Filter it out here.
|
||||
$code = -1;
|
||||
}
|
||||
|
||||
parent::__construct($msg, $code);
|
||||
$this->initBacktrace($original);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the class of this exception.
|
||||
*
|
||||
* @return string The classname.
|
||||
*/
|
||||
public function getClass()
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
}
|
||||
14
lib/SimpleSAML/Error/User.php
Executable file
14
lib/SimpleSAML/Error/User.php
Executable file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Baseclass for user error exceptions
|
||||
*
|
||||
*
|
||||
* @author Thomas Graff <thomas.graff@uninett.no>
|
||||
* @package SimpleSAMLphp_base
|
||||
*
|
||||
*/
|
||||
class SimpleSAML_Error_User extends SimpleSAML_Error_Exception
|
||||
{
|
||||
|
||||
}
|
||||
20
lib/SimpleSAML/Error/UserAborted.php
Executable file
20
lib/SimpleSAML/Error/UserAborted.php
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Exception indicating user aborting the authentication process.
|
||||
*
|
||||
* @package SimpleSAMLphp
|
||||
*/
|
||||
class SimpleSAML_Error_UserAborted extends SimpleSAML_Error_Error
|
||||
{
|
||||
|
||||
/**
|
||||
* Create the error
|
||||
*
|
||||
* @param Exception|null $cause The exception that caused this error.
|
||||
*/
|
||||
public function __construct(Exception $cause = null)
|
||||
{
|
||||
parent::__construct('USERABORTED', $cause);
|
||||
}
|
||||
}
|
||||
13
lib/SimpleSAML/Error/UserNotFound.php
Executable file
13
lib/SimpleSAML/Error/UserNotFound.php
Executable file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Exception indicating user not found by authsource.
|
||||
*
|
||||
* @author Thomas Graff <thomas.graff@uninett.no>
|
||||
* @package SimpleSAMLphp_base
|
||||
*
|
||||
*/
|
||||
class SimpleSAML_Error_UserNotFound extends SimpleSAML_Error_User
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user