This class tries to make sure that every exception is serializable.
Author: Thomas Graff (thomas.graff@uninett.no)
Inheritance: extends Exception
    /**
     * Continue the logout operation.
     *
     * This function will never return.
     *
     * @param string                          $assocId The association that is terminated.
     * @param string|NULL                     $relayState The RelayState from the start of the logout.
     * @param SimpleSAML_Error_Exception|null $error The error that occurred during session termination (if any).
     */
    public function onResponse($assocId, $relayState, SimpleSAML_Error_Exception $error = null)
    {
        assert('is_string($assocId)');
        $spId = sha1($assocId);
        $this->idp->terminateAssociation($assocId);
        $header = <<<HEADER
<!DOCTYPE html>
<html>
 <head>
  <title>Logout response from %s</title>
  <script>
HEADER;
        printf($header, htmlspecialchars(var_export($assocId, true)));
        if ($error) {
            $errorMsg = $error->getMessage();
            echo 'window.parent.logoutFailed("' . $spId . '", "' . addslashes($errorMsg) . '");';
        } else {
            echo 'window.parent.logoutCompleted("' . $spId . '");';
        }
        echo <<<FOOTER
  </script>
 </head>
 <body>
 </body>
</html>
FOOTER;
        exit(0);
    }
Exemple #2
0
function SimpleSAML_error_handler($errno, $errstr, $errfile = NULL, $errline = 0, $errcontext = NULL)
{
    if (!class_exists('SimpleSAML_Logger')) {
        /* We are probably logging a deprecation-warning during parsing.
         * Unfortunately, the autoloader is disabled at this point,
         * so we should stop here.
         *
         * See PHP bug: https://bugs.php.net/bug.php?id=47987
         */
        return FALSE;
    }
    if ($errno & SimpleSAML_Utilities::$logMask || !($errno & error_reporting())) {
        /* Masked error. */
        return FALSE;
    }
    static $limit = 5;
    $limit -= 1;
    if ($limit < 0) {
        /* We have reached the limit in the number of backtraces we will log. */
        return FALSE;
    }
    /* Show an error with a full backtrace. */
    $e = new SimpleSAML_Error_Exception('Error ' . $errno . ' - ' . $errstr);
    $e->logError();
    /* Resume normal error processing. */
    return FALSE;
}
    /**
     * Continue the logout operation.
     *
     * This function will never return.
     *
     * @param string $assocId  The association that is terminated.
     * @param string|NULL $relayState  The RelayState from the start of the logout.
     * @param SimpleSAML_Error_Exception|NULL $error  The error that occurred during session termination (if any).
     */
    public function onResponse($assocId, $relayState, SimpleSAML_Error_Exception $error = NULL)
    {
        assert('is_string($assocId)');
        $spId = sha1($assocId);
        $this->idp->terminateAssociation($assocId);
        echo '<!DOCTYPE html>
<html>
<head>
<title>Logout response from ' . htmlspecialchars(var_export($assocId, TRUE)) . '</title>
<script>
';
        if ($error) {
            $errorMsg = $error->getMessage();
            echo 'window.parent.logoutFailed("' . $spId . '", "' . addslashes($errorMsg) . '");';
        } else {
            echo 'window.parent.logoutCompleted("' . $spId . '");';
        }
        echo '
</script>
</head>
<body>
</body>
</html>
';
        exit(0);
    }
function SimpleSAML_error_handler($errno, $errstr, $errfile = null, $errline = 0, $errcontext = null)
{
    if (!class_exists('SimpleSAML\\Logger')) {
        /* We are probably logging a deprecation-warning during parsing. Unfortunately, the autoloader is disabled at
         * this point, so we should stop here.
         *
         * See PHP bug: https://bugs.php.net/bug.php?id=47987
         */
        return false;
    }
    if (SimpleSAML\Logger::isErrorMasked($errno)) {
        // masked error
        return false;
    }
    static $limit = 5;
    $limit -= 1;
    if ($limit < 0) {
        // we have reached the limit in the number of backtraces we will log
        return false;
    }
    // show an error with a full backtrace
    $e = new SimpleSAML_Error_Exception('Error ' . $errno . ' - ' . $errstr);
    $e->logError();
    // resume normal error processing
    return false;
}
 /**
  * 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('is_null($assertion) || is_string($assertion)');
     $msg = 'Assertion failed: ' . var_export($assertion, TRUE);
     parent::__construct($msg);
     $this->assertion = $assertion;
 }
 public function __construct(Exception $original)
 {
     $msg = get_class($original) . ': ' . $original->getMessage();
     $code = $original->getCode();
     parent::__construct($msg, $code);
     $this->setBacktrace(SimpleSAML_Utilities::buildBacktrace($original));
 }
 /**
  * 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).
  */
 public function __construct($errorCode, Exception $cause = 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;
     }
     $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 = '{errors:title_' . $this->errorCode . '}';
         $this->dictDescr = '{errors:descr_' . $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);
 }
Exemple #8
0
 /**
  * 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).
  */
 public function __construct($errorCode, Exception $cause = 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 (!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);
 }
Exemple #9
0
function SimpleSAML_error_handler($errno, $errstr, $errfile = NULL, $errline = 0, $errcontext = NULL)
{
    if ($errno & SimpleSAML_Utilities::$logMask) {
        /* Masked error. */
        return FALSE;
    }
    static $limit = 5;
    $limit -= 1;
    if ($limit < 0) {
        /* We have reached the limit in the number of backtraces we will log. */
        return FALSE;
    }
    /* Show an error with a full backtrace. */
    $e = new SimpleSAML_Error_Exception('Error ' . $errno . ' - ' . $errstr);
    $e->logError();
    /* Resume normal error processing. */
    return FALSE;
}
 /**
  * Continue the logout operation.
  *
  * This function will never return.
  *
  * @param string $assocId The association that is terminated.
  * @param string|null $relayState The RelayState from the start of the logout.
  * @param SimpleSAML_Error_Exception|null $error The error that occurred during session termination (if any).
  *
  * @throws SimpleSAML_Error_Exception If the RelayState was lost during logout.
  */
 public function onResponse($assocId, $relayState, SimpleSAML_Error_Exception $error = null)
 {
     assert('is_string($assocId)');
     assert('is_string($relayState) || is_null($relayState)');
     if ($relayState === null) {
         throw new SimpleSAML_Error_Exception('RelayState lost during logout.');
     }
     $state = SimpleSAML_Auth_State::loadState($relayState, 'core:LogoutTraditional');
     if ($error === null) {
         SimpleSAML_Logger::info('Logged out of ' . var_export($assocId, true) . '.');
         $this->idp->terminateAssociation($assocId);
     } else {
         SimpleSAML_Logger::warning('Error received from ' . var_export($assocId, true) . ' during logout:');
         $error->logWarning();
         $state['core:Failed'] = true;
     }
     self::logoutNextSP($state);
 }
Exemple #11
0
 /**
  * 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);
     }
 }
 /**
  * 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);
 }
 /**
  * Continue the logout operation.
  *
  * This function will never return.
  *
  * @param string $assocId  The association that is terminated.
  * @param string|NULL $relayState  The RelayState from the start of the logout.
  * @param SimpleSAML_Error_Exception|NULL $error  The error that occurred during session termination (if any).
  */
 public function onResponse($assocId, $relayState, SimpleSAML_Error_Exception $error = NULL)
 {
     assert('is_string($assocId)');
     assert('is_string($relayState) || is_null($relayState)');
     if ($relayState === NULL) {
         throw new SimpleSAML_Error_Exception('RelayState lost during logout.');
     }
     // sanitize the input
     $sid = SimpleSAML_Utilities::parseStateID($relayState);
     if (!is_null($sid['url'])) {
         SimpleSAML_Utilities::checkURLAllowed($sid['url']);
     }
     $state = SimpleSAML_Auth_State::loadState($relayState, 'core:LogoutTraditional');
     if ($error === NULL) {
         SimpleSAML_Logger::info('Logged out of ' . var_export($assocId, TRUE) . '.');
         $this->idp->terminateAssociation($assocId);
     } else {
         SimpleSAML_Logger::warning('Error received from ' . var_export($assocId, TRUE) . ' during logout:');
         $error->logWarning();
         $state['core:Failed'] = TRUE;
     }
     self::logoutNextSP($state);
 }
 /**
  * Create a SAML 2 error.
  *
  * @param string $status  The top-level status code.
  * @param string|NULL $subStatus  The second-level status code. Can be NULL, in which case there is no second-level status code.
  * @param string|NULL $statusMessage  The status message. Can be NULL, in which case there is no status message.
  * @param Exception|NULL $cause  The cause of this exception. Can be NULL.
  */
 public function __construct($status, $subStatus = NULL, $statusMessage = NULL, Exception $cause = NULL)
 {
     assert('is_string($status)');
     assert('is_null($subStatus) || is_string($subStatus)');
     assert('is_null($statusMessage) || is_string($statusMessage)');
     $st = self::shortStatus($status);
     if ($subStatus !== NULL) {
         $st .= '/' . self::shortStatus($subStatus);
     }
     if ($statusMessage !== NULL) {
         $st .= ': ' . $statusMessage;
     }
     parent::__construct($st, 0, $cause);
     $this->status = $status;
     $this->subStatus = $subStatus;
     $this->statusMessage = $statusMessage;
 }
Exemple #15
0
                $source['blacklist'] = $blacklist;
            }
            # Merge global and src specific whitelists
            if (isset($source['whitelist'])) {
                $source['whitelist'] = array_unique(array_merge($source['whitelist'], $whitelist));
            } else {
                $source['whitelist'] = $whitelist;
            }
            SimpleSAML_Logger::debug('[metarefresh]: In set [' . $setkey . '] loading source [' . $source['src'] . ']');
            $metaloader->loadSource($source);
        }
        $outputDir = $set->getString('outputDir');
        $outputDir = $config->resolvePath($outputDir);
        $outputFormat = $set->getValueValidate('outputFormat', array('flatfile', 'serialize'), 'flatfile');
        switch ($outputFormat) {
            case 'flatfile':
                $metaloader->writeMetadataFiles($outputDir);
                break;
            case 'serialize':
                $metaloader->writeMetadataSerialize($outputDir);
                break;
        }
    } catch (Exception $e) {
        $e = SimpleSAML_Error_Exception::fromException($e);
        $e->logWarning();
    }
}
$logentries = SimpleSAML_Logger::getCapturedLog();
$t = new SimpleSAML_XHTML_Template($config, 'metarefresh:fetch.tpl.php');
$t->data['logentries'] = $logentries;
$t->show();