ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 80 of file Error.php.

81 {
82 assert('is_string($errorCode) || is_array($errorCode)');
83
84 if (is_array($errorCode)) {
85 $this->parameters = $errorCode;
86 unset($this->parameters[0]);
87 $this->errorCode = $errorCode[0];
88 } else {
89 $this->parameters = array();
90 $this->errorCode = $errorCode;
91 }
92
93 if (isset($httpCode)) {
94 $this->httpCode = $httpCode;
95 }
96
97 $moduleCode = explode(':', $this->errorCode, 2);
98 if (count($moduleCode) === 2) {
99 $this->module = $moduleCode[0];
100 $this->dictTitle = '{'.$this->module.':errors:title_'.$moduleCode[1].'}';
101 $this->dictDescr = '{'.$this->module.':errors:descr_'.$moduleCode[1].'}';
102 } else {
103 $this->dictTitle = SimpleSAML\Error\ErrorCodes::getErrorCodeTitle($this->errorCode);
104 $this->dictDescr = SimpleSAML\Error\ErrorCodes::getErrorCodeDescription($this->errorCode);
105 }
106
107 if (!empty($this->parameters)) {
108 $msg = $this->errorCode.'(';
109 foreach ($this->parameters as $k => $v) {
110 if ($k === 0) {
111 continue;
112 }
113
114 $msg .= var_export($k, true).' => '.var_export($v, true).', ';
115 }
116 $msg = substr($msg, 0, -2).')';
117 } else {
118 $msg = $this->errorCode;
119 }
120 parent::__construct($msg, -1, $cause);
121 }
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 162 of file Error.php.

163 {
164 return $this->dictDescr;
165 }

References $dictDescr.

◆ getDictTitle()

SimpleSAML_Error_Error::getDictTitle ( )

Retrieve the error title tag in dictionary.

Returns
string The error title tag.

Definition at line 151 of file Error.php.

152 {
153 return $this->dictTitle;
154 }

References $dictTitle.

◆ getErrorCode()

SimpleSAML_Error_Error::getErrorCode ( )

Retrieve the error code given when throwing this error.

Returns
string The error code.

Definition at line 129 of file Error.php.

130 {
131 return $this->errorCode;
132 }

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 140 of file Error.php.

141 {
142 return $this->parameters;
143 }

References $parameters.

◆ saveError()

SimpleSAML_Error_Error::saveError ( )
protected

Save an error report.

Returns
array The array with the error report data.

Definition at line 207 of file Error.php.

208 {
209 $data = $this->format(true);
210 $emsg = array_shift($data);
211 $etrace = implode("\n", $data);
212
213 $reportId = bin2hex(openssl_random_pseudo_bytes(4));
214 SimpleSAML\Logger::error('Error report with id '.$reportId.' generated.');
215
218
219 if (isset($_SERVER['HTTP_REFERER'])) {
220 $referer = $_SERVER['HTTP_REFERER'];
221 // remove anything after the first '?' or ';', just in case it contains any sensitive data
222 $referer = explode('?', $referer, 2);
223 $referer = $referer[0];
224 $referer = explode(';', $referer, 2);
225 $referer = $referer[0];
226 } else {
227 $referer = 'unknown';
228 }
229 $errorData = array(
230 'exceptionMsg' => $emsg,
231 'exceptionTrace' => $etrace,
232 'reportId' => $reportId,
233 'trackId' => $session->getTrackID(),
234 'url' => \SimpleSAML\Utils\HTTP::getSelfURLNoQuery(),
235 'version' => $config->getVersion(),
236 'referer' => $referer,
237 );
238 $session->setData('core:errorreport', $reportId, $errorData);
239
240 return $errorData;
241 }
static error($string)
Definition: Logger.php:168
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
format($anonymize=false)
Format this exception for logging.
Definition: Exception.php:151
static getSessionFromRequest()
Retrieves the current session.
Definition: Session.php:243
Attribute-related utility methods.
$session
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
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 173 of file Error.php.

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

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 249 of file Error.php.

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

References $attributes, $authority, $baseurl, $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 43 of file Error.php.

Referenced by getDictDescr(), and show().

◆ $dictTitle

SimpleSAML_Error_Error::$dictTitle
private

Definition at line 35 of file Error.php.

Referenced by getDictTitle(), and show().

◆ $errorCode

SimpleSAML_Error_Error::$errorCode
private

Definition at line 19 of file Error.php.

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

◆ $httpCode

SimpleSAML_Error_Error::$httpCode = 500
protected

Definition at line 27 of file Error.php.

Referenced by __construct(), and setHTTPCode().

◆ $includeTemplate

SimpleSAML_Error_Error::$includeTemplate = null
protected

Definition at line 67 of file Error.php.

Referenced by show().

◆ $module

SimpleSAML_Error_Error::$module = null
private

Definition at line 51 of file Error.php.

Referenced by show().

◆ $parameters

SimpleSAML_Error_Error::$parameters
private

Definition at line 59 of file Error.php.

Referenced by getParameters(), and show().


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