SimpleSAML_Auth_State::throwException PHP Method

throwException() public static method

Throw exception to the state exception handler.
public static throwException ( array $state, SimpleSAML_Error_Exception $exception )
$state array The state array.
$exception SimpleSAML_Error_Exception The exception.
    public static function throwException($state, SimpleSAML_Error_Exception $exception)
    {
        assert('is_array($state)');
        if (array_key_exists(self::EXCEPTION_HANDLER_URL, $state)) {
            // Save the exception
            $state[self::EXCEPTION_DATA] = $exception;
            $id = self::saveState($state, self::EXCEPTION_STAGE);
            // Redirect to the exception handler
            \SimpleSAML\Utils\HTTP::redirectTrustedURL($state[self::EXCEPTION_HANDLER_URL], array(self::EXCEPTION_PARAM => $id));
        } elseif (array_key_exists(self::EXCEPTION_HANDLER_FUNC, $state)) {
            // Call the exception handler
            $func = $state[self::EXCEPTION_HANDLER_FUNC];
            assert('is_callable($func)');
            call_user_func($func, $exception, $state);
            assert(false);
        } else {
            /*
             * No exception handler is defined for the current state.
             */
            throw $exception;
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Start authentication.
  *
  * This function never returns.
  *
  * @param string $authId  The identifier of the authentication source.
  * @param string|array $return The URL or function we should direct the
  * user to after authentication. If using a URL obtained from user input,
  * please make sure to check it by calling
  * SimpleSAML_Utilities::checkURLAllowed().
  * @param string|NULL $errorURL The URL we should direct the user to after
  * failed authentication. Can be NULL, in which case a standard error page
  * will be shown. If using a URL obtained from user input, please make sure
  * to check it by calling SimpleSAML_Utilities::checkURLAllowed().
  * @param array $params Extra information about the login. Different
  * authentication requestors may provide different information. Optional,
  * will default to an empty array.
  */
 public static function initLogin($authId, $return, $errorURL = NULL, array $params = array())
 {
     assert('is_string($authId)');
     assert('is_string($return) || is_array($return)');
     assert('is_string($errorURL) || is_null($errorURL)');
     $state = array_merge($params, array('SimpleSAML_Auth_Default.id' => $authId, 'SimpleSAML_Auth_Default.Return' => $return, 'SimpleSAML_Auth_Default.ErrorURL' => $errorURL, 'LoginCompletedHandler' => array(get_class(), 'loginCompleted'), 'LogoutCallback' => array(get_class(), 'logoutCallback'), 'LogoutCallbackState' => array('SimpleSAML_Auth_Default.logoutSource' => $authId)));
     if (is_string($return)) {
         $state['SimpleSAML_Auth_Default.ReturnURL'] = $return;
     }
     if ($errorURL !== NULL) {
         $state[SimpleSAML_Auth_State::EXCEPTION_HANDLER_URL] = $errorURL;
     }
     $as = SimpleSAML_Auth_Source::getById($authId);
     if ($as === NULL) {
         throw new Exception('Invalid authentication source: ' . $authId);
     }
     try {
         $as->authenticate($state);
     } catch (SimpleSAML_Error_Exception $e) {
         SimpleSAML_Auth_State::throwException($state, $e);
     } catch (Exception $e) {
         $e = new SimpleSAML_Error_UnserializableException($e);
         SimpleSAML_Auth_State::throwException($state, $e);
     }
     self::loginCompleted($state);
 }
All Usage Examples Of SimpleSAML_Auth_State::throwException