Skip to content
Snippets Groups Projects
Commit cc5017ab authored by Olav Morken's avatar Olav Morken
Browse files

ProcessingChain: Add support for returning to a function.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1659 44740490-163a-0410-bde0-09ae8108e29a
parent 4fdb5187
No related branches found
No related tags found
No related merge requests found
......@@ -160,8 +160,10 @@ class SimpleSAML_Auth_ProcessingChain {
* Process the given state.
*
* This function will only return if processing completes. If processing requires showing
* a page to the user, we will redirect to the URL set in $state['ReturnURL'] after processing is
* completed.
* a page to the user, we will not be able to return from this function. There are two ways
* this can be handled:
* - Redirect to an URL: We will redirect to the URL set in $state['ReturnURL'].
* - Call a function: We will call the function set in $state['ReturnCall'].
*
* If an exception is thrown during processing, it should be handled by the caller of
* this function. If the user has redirected to a different page, the exception will be
......@@ -176,7 +178,8 @@ class SimpleSAML_Auth_ProcessingChain {
*/
public function processState(&$state) {
assert('is_array($state)');
assert('array_key_exists("ReturnURL", $state)');
assert('array_key_exists("ReturnURL", $state) || array_key_exists("ReturnCall", $state)');
assert('!array_key_exists("ReturnURL", $state) || !array_key_exists("ReturnCall", $state)');
$state[self::FILTERS_INDEX] = $this->filters;
......@@ -233,15 +236,34 @@ class SimpleSAML_Auth_ProcessingChain {
}
}
assert('array_key_exists("ReturnURL", $state)');
/* Completed. */
assert('array_key_exists("ReturnURL", $state) || array_key_exists("ReturnCall", $state)');
assert('!array_key_exists("ReturnURL", $state) || !array_key_exists("ReturnCall", $state)');
/* Completed. Save state information, and redirect to the URL specified
* in $state['ReturnURL'].
*/
$id = SimpleSAML_Auth_State::saveState($state, self::COMPLETED_STAGE);
SimpleSAML_Utilities::redirect($state['ReturnURL'], array(self::AUTHPARAM => $id));
if (array_key_exists('ReturnURL', $state)) {
/*
* Save state information, and redirect to the URL specified
* in $state['ReturnURL'].
*/
$id = SimpleSAML_Auth_State::saveState($state, self::COMPLETED_STAGE);
SimpleSAML_Utilities::redirect($state['ReturnURL'], array(self::AUTHPARAM => $id));
} else {
/* Pass the state to the function defined in $state['ReturnCall']. */
/* We are done with the state array in the session. Delete it. */
SimpleSAML_Auth_State::deleteState($state);
$func = $state['ReturnCall'];
assert('is_callable($func)');
call_user_func($func, $state);
assert(FALSE);
}
}
/**
* Process the given state passivly.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment