ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SimpleSAML_Error_Error Class Reference
+ Inheritance diagram for SimpleSAML_Error_Error:
+ Collaboration diagram for SimpleSAML_Error_Error:

Public Member Functions

 __construct ($errorCode, Exception $cause=null, $httpCode=null)
 Constructor for this error. More...
 
 getErrorCode ()
 Retrieve the error code given when throwing this error. More...
 
 getParameters ()
 Retrieve the error parameters given when throwing this error. More...
 
 getDictTitle ()
 Retrieve the error title tag in dictionary. More...
 
 getDictDescr ()
 Retrieve the error description tag in dictionary. More...
 
 show ()
 Display this error. More...
 
- Public Member Functions inherited from SimpleSAML_Error_Exception
 __construct ($message, $code=0, Exception $cause=null)
 Constructor for this error. More...
 
 getBacktrace ()
 Retrieve the backtrace. More...
 
 getCause ()
 Retrieve the cause of this exception. More...
 
 getClass ()
 Retrieve the class of this exception. More...
 
 format ($anonymize=false)
 Format this exception for logging. More...
 
 formatBacktrace ($anonymize=false)
 Format the backtrace for logging. More...
 
 log ($default_level)
 Print the exception to the log, by default with log level error. More...
 
 logError ()
 Print the exception to the log with log level error. More...
 
 logWarning ()
 Print the exception to the log with log level warning. More...
 
 logInfo ()
 Print the exception to the log with log level info. More...
 
 logDebug ()
 Print the exception to the log with log level debug. More...
 
 __sleep ()
 Function for serialization. More...
 

Protected Member Functions

 setHTTPCode ()
 Set the HTTP return code for this error. More...
 
 saveError ()
 Save an error report. More...
 
- Protected Member Functions inherited from SimpleSAML_Error_Exception
 initBacktrace (Exception $exception)
 Load the backtrace from the given exception. More...
 
 logBacktrace ($level=\SimpleSAML\Logger::DEBUG)
 Print the backtrace to the log if the 'debug' option is enabled in the configuration. More...
 

Protected Attributes

 $httpCode = 500
 
 $includeTemplate = null
 

Private Attributes

 $errorCode
 
 $dictTitle
 
 $dictDescr
 
 $module = null
 
 $parameters
 

Additional Inherited Members

- Static Public Member Functions inherited from SimpleSAML_Error_Exception
static fromException (Exception $e)
 Convert any exception into a SimpleSAML_Error_Exception. More...
 

Detailed Description

Definition at line 10 of file Error.php.

Constructor & Destructor Documentation

◆ __construct()

SimpleSAML_Error_Error::__construct (   $errorCode,
Exception  $cause = null,
  $httpCode = 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.

Parameters
mixed$errorCodeOne of the error codes defined in the errors dictionary.
Exception$causeThe exception which caused this fatal error (if any). Optional.
int | null$httpCodeThe HTTP response code to use. Optional.

Definition at line 71 of file Error.php.

72 {
73 assert(is_string($errorCode) || is_array($errorCode));
74
75 if (is_array($errorCode)) {
76 $this->parameters = $errorCode;
77 unset($this->parameters[0]);
78 $this->errorCode = $errorCode[0];
79 } else {
80 $this->parameters = array();
81 $this->errorCode = $errorCode;
82 }
83
84 if (isset($httpCode)) {
85 $this->httpCode = $httpCode;
86 }
87
88 $moduleCode = explode(':', $this->errorCode, 2);
89 if (count($moduleCode) === 2) {
90 $this->module = $moduleCode[0];
91 $this->dictTitle = '{'.$this->module.':errors:title_'.$moduleCode[1].'}';
92 $this->dictDescr = '{'.$this->module.':errors:descr_'.$moduleCode[1].'}';
93 } else {
94 $this->dictTitle = SimpleSAML\Error\ErrorCodes::getErrorCodeTitle($this->errorCode);
95 $this->dictDescr = SimpleSAML\Error\ErrorCodes::getErrorCodeDescription($this->errorCode);
96 }
97
98 if (!empty($this->parameters)) {
99 $msg = $this->errorCode.'(';
100 foreach ($this->parameters as $k => $v) {
101 if ($k === 0) {
102 continue;
103 }
104
105 $msg .= var_export($k, true).' => '.var_export($v, true).', ';
106 }
107 $msg = substr($msg, 0, -2).')';
108 } else {
109 $msg = $this->errorCode;
110 }
111 parent::__construct($msg, -1, $cause);
112 }
static getErrorCodeTitle($errorCode)
Fetch a translation string for a title for a given error code.
Definition: ErrorCodes.php:151
static getErrorCodeDescription($errorCode)
Fetch a translation string for a description for a given error code.
Definition: ErrorCodes.php:165

References SimpleSAML_Error_Exception\$cause, $errorCode, $httpCode, SimpleSAML\Error\ErrorCodes\getErrorCodeDescription(), and SimpleSAML\Error\ErrorCodes\getErrorCodeTitle().

+ Here is the call graph for this function:

Member Function Documentation

◆ getDictDescr()

SimpleSAML_Error_Error::getDictDescr ( )

Retrieve the error description tag in dictionary.

Returns
string The error description tag.

Definition at line 153 of file Error.php.

154 {
155 return $this->dictDescr;
156 }

References $dictDescr.

◆ getDictTitle()

SimpleSAML_Error_Error::getDictTitle ( )

Retrieve the error title tag in dictionary.

Returns
string The error title tag.

Definition at line 142 of file Error.php.

143 {
144 return $this->dictTitle;
145 }

References $dictTitle.

◆ getErrorCode()

SimpleSAML_Error_Error::getErrorCode ( )

Retrieve the error code given when throwing this error.

Returns
string The error code.

Definition at line 120 of file Error.php.

121 {
122 return $this->errorCode;
123 }

References $errorCode.

Referenced by sspmod_authYubiKey_Auth_Source_YubiKey\handleLogin().

+ Here is the caller graph for this function:

◆ getParameters()

SimpleSAML_Error_Error::getParameters ( )

Retrieve the error parameters given when throwing this error.

Returns
array The parameters.

Definition at line 131 of file Error.php.

132 {
133 return $this->parameters;
134 }

References $parameters.

◆ saveError()

SimpleSAML_Error_Error::saveError ( )
protected

Save an error report.

Returns
array The array with the error report data.

Definition at line 198 of file Error.php.

199 {
200 $data = $this->format(true);
201 $emsg = array_shift($data);
202 $etrace = implode("\n", $data);
203
204 $reportId = bin2hex(openssl_random_pseudo_bytes(4));
205 SimpleSAML\Logger::error('Error report with id '.$reportId.' generated.');
206
209
210 if (isset($_SERVER['HTTP_REFERER'])) {
211 $referer = $_SERVER['HTTP_REFERER'];
212 // remove anything after the first '?' or ';', just in case it contains any sensitive data
213 $referer = explode('?', $referer, 2);
214 $referer = $referer[0];
215 $referer = explode(';', $referer, 2);
216 $referer = $referer[0];
217 } else {
218 $referer = 'unknown';
219 }
220 $errorData = array(
221 'exceptionMsg' => $emsg,
222 'exceptionTrace' => $etrace,
223 'reportId' => $reportId,
224 'trackId' => $session->getTrackID(),
225 'url' => \SimpleSAML\Utils\HTTP::getSelfURLNoQuery(),
226 'version' => $config->getVersion(),
227 'referer' => $referer,
228 );
229 $session->setData('core:errorreport', $reportId, $errorData);
230
231 return $errorData;
232 }
static error($string)
Definition: Logger.php:166
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
format($anonymize=false)
Format this exception for logging.
Definition: Exception.php:150
static getSessionFromRequest()
Retrieves the current session.
Definition: Session.php:241
$config
Definition: bootstrap.php:15
Attribute-related utility methods.
$session
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$data
Definition: bench.php:6
if($_SERVER['REQUEST_METHOD'] !=='POST') $reportId
Definition: errorreport.php:16

References $_SERVER, $config, $data, $reportId, $session, SimpleSAML\Logger\error(), SimpleSAML_Error_Exception\format(), SimpleSAML_Configuration\getInstance(), and SimpleSAML_Session\getSessionFromRequest().

Referenced by show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHTTPCode()

SimpleSAML_Error_Error::setHTTPCode ( )
protected

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.

Definition at line 164 of file Error.php.

165 {
166 // Some mostly used HTTP codes
167 $httpCodesMap = array(
168 400 => 'HTTP/1.0 400 Bad Request',
169 403 => 'HTTP/1.0 403 Forbidden',
170 404 => 'HTTP/1.0 404 Not Found',
171 405 => 'HTTP/1.0 405 Method Not Allowed',
172 500 => 'HTTP/1.0 500 Internal Server Error',
173 501 => 'HTTP/1.0 501 Method Not Implemented',
174 503 => 'HTTP/1.0 503 Service Temporarily Unavailable',
175 );
176
178
179 if (function_exists('http_response_code')) {
180 http_response_code($httpCode);
181 return;
182 }
183
184 if (!array_key_exists($this->httpCode, $httpCodesMap)) {
185 $httpCode = 500;
186 SimpleSAML\Logger::warning('HTTP response code not defined: '.var_export($this->httpCode, true));
187 }
188
189 header($httpCodesMap[$httpCode]);
190 }
static warning($string)
Definition: Logger.php:177

References $httpCode, and SimpleSAML\Logger\warning().

Referenced by show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ show()

SimpleSAML_Error_Error::show ( )

Display this error.

This method displays a standard SimpleSAMLphp error page and exits.

Definition at line 240 of file Error.php.

241 {
242 $this->setHTTPCode();
243
244 // log the error message
245 $this->logError();
246
247 $errorData = $this->saveError();
249
250 $data = array();
251 $data['showerrors'] = $config->getBoolean('showerrors', true);
252 $data['error'] = $errorData;
253 $data['errorCode'] = $this->errorCode;
254 $data['parameters'] = $this->parameters;
255 $data['module'] = $this->module;
256 $data['dictTitle'] = $this->dictTitle;
257 $data['dictDescr'] = $this->dictDescr;
258 $data['includeTemplate'] = $this->includeTemplate;
259 $data['clipboard.js'] = true;
260
261 // check if there is a valid technical contact email address
262 if ($config->getBoolean('errorreporting', true) &&
263 $config->getString('technicalcontact_email', 'na@example.org') !== 'na@example.org'
264 ) {
265 // enable error reporting
267 $data['errorReportAddress'] = $baseurl.'errorreport.php';
268 }
269
270 $data['email'] = '';
272 $authorities = $session->getAuthorities();
273 foreach ($authorities as $authority) {
274 $attributes = $session->getAuthData($authority, 'Attributes');
275 if ($attributes !== null && array_key_exists('mail', $attributes) && count($attributes['mail']) > 0) {
276 $data['email'] = $attributes['mail'][0];
277 break; // enough, don't need to get all available mails, if more than one
278 }
279 }
280
281 $show_function = $config->getArray('errors.show_function', null);
282 if (isset($show_function)) {
283 assert(is_callable($show_function));
284 call_user_func($show_function, $config, $data);
285 assert(false);
286 } else {
287 $t = new SimpleSAML_XHTML_Template($config, 'error.php', 'errors');
288 $t->data = array_merge($t->data, $data);
289 $t->data['dictTitleTranslated'] = $t->getTranslator()->t($t->data['dictTitle']);
290 $t->data['dictDescrTranslated'] = $t->getTranslator()->t($t->data['dictDescr'], $t->data['parameters']);
291 $t->show();
292 }
293
294 exit;
295 }
exit
Definition: backend.php:16
static getBaseURL()
Retrieve the base URL of the SimpleSAMLphp installation.
Definition: HTTP.php:597
setHTTPCode()
Set the HTTP return code for this error.
Definition: Error.php:164
saveError()
Save an error report.
Definition: Error.php:198
logError()
Print the exception to the log with log level error.
Definition: Exception.php:252
$authority
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85

References $attributes, $authority, $config, $data, $dictDescr, $dictTitle, $errorCode, $includeTemplate, $module, $parameters, $session, $t, exit, SimpleSAML\Utils\HTTP\getBaseURL(), SimpleSAML_Configuration\getInstance(), SimpleSAML_Session\getSessionFromRequest(), SimpleSAML_Error_Exception\logError(), saveError(), and setHTTPCode().

+ Here is the call graph for this function:

Field Documentation

◆ $dictDescr

SimpleSAML_Error_Error::$dictDescr
private

Definition at line 38 of file Error.php.

Referenced by getDictDescr(), and show().

◆ $dictTitle

SimpleSAML_Error_Error::$dictTitle
private

Definition at line 31 of file Error.php.

Referenced by getDictTitle(), and show().

◆ $errorCode

SimpleSAML_Error_Error::$errorCode
private

Definition at line 17 of file Error.php.

Referenced by __construct(), getErrorCode(), and show().

◆ $httpCode

SimpleSAML_Error_Error::$httpCode = 500
protected

Definition at line 24 of file Error.php.

Referenced by __construct(), and setHTTPCode().

◆ $includeTemplate

SimpleSAML_Error_Error::$includeTemplate = null
protected

Definition at line 59 of file Error.php.

Referenced by show().

◆ $module

SimpleSAML_Error_Error::$module = null
private

Definition at line 45 of file Error.php.

Referenced by show().

◆ $parameters

SimpleSAML_Error_Error::$parameters
private

Definition at line 52 of file Error.php.

Referenced by getParameters(), and show().


The documentation for this class was generated from the following file: