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

Auth_State: Add getStateId function.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2732 44740490-163a-0410-bde0-09ae8108e29a
parent 4210eb01
No related branches found
No related tags found
No related merge requests found
......@@ -79,6 +79,35 @@ class SimpleSAML_Auth_State {
const EXCEPTION_PARAM = 'SimpleSAML_Auth_State_exceptionId';
/**
* Retrieve the ID of a state array.
*
* Note that this function will not save the state.
*
* @param array &$state The state array.
* @param bool $rawId Return a raw ID, without a restart URL. Defaults to FALSE.
* @return string Identifier which can be used to retrieve the state later.
*/
public static function getStateId(&$state, $rawId = FALSE) {
assert('is_array($state)');
assert('is_bool($rawId)');
if (!array_key_exists(self::ID, $state)) {
$state[self::ID] = SimpleSAML_Utilities::generateID();
}
$id = $state[self::ID];
if ($rawId || !array_key_exists(self::RESTART, $state)) {
/* Either raw ID or no restart URL. In any case, return the raw ID. */
return $id;
}
/* We have a restart URL. Return the ID with that URL. */
return $id . ':' . $state[self::RESTART];
}
/**
* Save the state.
*
......@@ -95,25 +124,14 @@ class SimpleSAML_Auth_State {
assert('is_string($stage)');
assert('is_bool($rawId)');
/* Save stage. */
$state[self::STAGE] = $stage;
if (!array_key_exists(self::ID, $state)) {
$state[self::ID] = SimpleSAML_Utilities::generateID();
}
$return = self::getStateId($state, $rawId);
$id = $state[self::ID];
/* Embed the restart URL in the state identifier, if it is available. */
if (array_key_exists(self::RESTART, $state) && !$rawId) {
assert('is_string($state[self::RESTART])');
$return = $id . ':' . $state[self::RESTART];
} else {
$return = $id;
}
/* Save stage. */
$state[self::STAGE] = $stage;
/* Save state. */
$serializedState = serialize($state);
$session = SimpleSAML_Session::getInstance();
$session->setData('SimpleSAML_Auth_State', $id, $serializedState, 60*60);
......
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