ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SimpleSAML_Auth_State Class Reference
+ Collaboration diagram for SimpleSAML_Auth_State:

Static Public Member Functions

static getPersistentAuthData (array $state)
 Get the persistent authentication state from the state array. More...
 
static getStateId (&$state, $rawId=false)
 Retrieve the ID of a state array. More...
 
static saveState (&$state, $stage, $rawId=false)
 Save the state. More...
 
static cloneState (array $state)
 Clone the state. More...
 
static loadState ($id, $stage, $allowMissing=false)
 Retrieve saved state. More...
 
static deleteState (&$state)
 Delete state. More...
 
static throwException ($state, SimpleSAML_Error_Exception $exception)
 Throw exception to the state exception handler. More...
 
static loadExceptionState ($id=null)
 Retrieve an exception state. More...
 
static parseStateID ($stateId)
 Get the ID and (optionally) a URL embedded in a StateID, in the form 'id:url'. More...
 

Data Fields

const ID = 'SimpleSAML_Auth_State.id'
 The index in the state array which contains the identifier. More...
 
const CLONE_ORIGINAL_ID = 'SimpleSAML_Auth_State.cloneOriginalId'
 The index in the cloned state array which contains the identifier of the original state. More...
 
const STAGE = 'SimpleSAML_Auth_State.stage'
 The index in the state array which contains the current stage. More...
 
const RESTART = 'SimpleSAML_Auth_State.restartURL'
 The index in the state array which contains the restart URL. More...
 
const EXCEPTION_HANDLER_URL = 'SimpleSAML_Auth_State.exceptionURL'
 The index in the state array which contains the exception handler URL. More...
 
const EXCEPTION_HANDLER_FUNC = 'SimpleSAML_Auth_State.exceptionFunc'
 The index in the state array which contains the exception handler function. More...
 
const EXCEPTION_DATA = 'SimpleSAML_Auth_State.exceptionData'
 The index in the state array which contains the exception data. More...
 
const EXCEPTION_STAGE = 'SimpleSAML_Auth_State.exceptionStage'
 The stage of a state with an exception. More...
 
const EXCEPTION_PARAM = 'SimpleSAML_Auth_State_exceptionId'
 The URL parameter which contains the exception state id. More...
 

Static Private Member Functions

static getStateTimeout ()
 Retrieve state timeout. More...
 

Static Private Attributes

static $stateTimeout = null
 State timeout. More...
 

Detailed Description

Definition at line 31 of file State.php.

Member Function Documentation

◆ cloneState()

static SimpleSAML_Auth_State::cloneState ( array  $state)
static

Clone the state.

This function clones and returns the new cloned state.

Parameters
array$stateThe original request state.
Returns
array Cloned state data.

Definition at line 226 of file State.php.

References $state, and SimpleSAML\Logger\debug().

227  {
228  $clonedState = $state;
229 
230  if (array_key_exists(self::ID, $state)) {
231  $clonedState[self::CLONE_ORIGINAL_ID] = $state[self::ID];
232  unset($clonedState[self::ID]);
233 
234  SimpleSAML\Logger::debug('Cloned state: '.var_export($state[self::ID], true));
235  } else {
236  SimpleSAML\Logger::debug('Cloned state with undefined id.');
237  }
238 
239  return $clonedState;
240  }
static debug($string)
Definition: Logger.php:213
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
+ Here is the call graph for this function:

◆ deleteState()

static SimpleSAML_Auth_State::deleteState ( $state)
static

Delete state.

This function deletes the given state to prevent the user from reusing it later.

Parameters
array&$stateThe state which should be deleted.

Definition at line 319 of file State.php.

Referenced by SimpleSAML_Auth_Source\completeAuth(), SimpleSAML_Auth_Source\completeLogout(), sspmod_cas_Auth_Source_CAS\logout(), and SimpleSAML_Auth_ProcessingChain\resumeProcessing().

320  {
321  assert('is_array($state)');
322 
323  if (!array_key_exists(self::ID, $state)) {
324  // This state hasn't been saved
325  return;
326  }
327 
328  SimpleSAML\Logger::debug('Deleting state: '.var_export($state[self::ID], true));
329 
331  $session->deleteData('SimpleSAML_Auth_State', $state[self::ID]);
332  }
static debug($string)
Definition: Logger.php:213
$session
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
static getSessionFromRequest()
Retrieves the current session.
Definition: Session.php:243
+ Here is the caller graph for this function:

◆ getPersistentAuthData()

static SimpleSAML_Auth_State::getPersistentAuthData ( array  $state)
static

Get the persistent authentication state from the state array.

Parameters
array$stateThe state array to analyze.
Returns
array The persistent authentication state.

Definition at line 103 of file State.php.

References $key, and array.

Referenced by SimpleSAML_Auth_Default\extractPersistentAuthState(), sspmod_saml_Auth_Source_SP\handleUnsolicitedAuth(), SimpleSAML_Auth_Source\loginCompleted(), and sspmod_saml_Auth_Source_SP\reauthPostLogin().

104  {
105  // save persistent authentication data
106  $persistent = array();
107 
108  if (array_key_exists('PersistentAuthData', $state)) {
109  foreach ($state['PersistentAuthData'] as $key) {
110  if (isset($state[$key])) {
111  $persistent[$key] = $state[$key];
112  }
113  }
114  }
115 
116  // add those that should always be included
117  $mandatory = array(
118  'Attributes',
119  'Expire',
120  'LogoutState',
121  'AuthInstant',
122  'RememberMe',
123  'saml:sp:NameID'
124  );
125  foreach ($mandatory as $key) {
126  if (isset($state[$key])) {
127  $persistent[$key] = $state[$key];
128  }
129  }
130 
131  return $persistent;
132  }
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
Create styles array
The data for the language used.
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ getStateId()

static SimpleSAML_Auth_State::getStateId ( $state,
  $rawId = false 
)
static

Retrieve the ID of a state array.

Note that this function will not save the state.

Parameters
array&$stateThe state array.
bool$rawIdReturn a raw ID, without a restart URL. Defaults to FALSE.
Returns
string Identifier which can be used to retrieve the state later.

Definition at line 145 of file State.php.

References $id, $state, and SimpleSAML\Utils\Random\generateID().

Referenced by sspmod_authlinkedin_Auth_Source_LinkedIn\authenticate(), and sspmod_authfacebook_Facebook\establishCSRFTokenState().

146  {
147  assert('is_array($state)');
148  assert('is_bool($rawId)');
149 
150  if (!array_key_exists(self::ID, $state)) {
152  }
153 
154  $id = $state[self::ID];
155 
156  if ($rawId || !array_key_exists(self::RESTART, $state)) {
157  // Either raw ID or no restart URL. In any case, return the raw ID.
158  return $id;
159  }
160 
161  // We have a restart URL. Return the ID with that URL.
162  return $id.':'.$state[self::RESTART];
163  }
static generateID()
Generate a random identifier, ID_LENGTH bytes long.
Definition: Random.php:26
if(!array_key_exists('StateId', $_REQUEST)) $id
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getStateTimeout()

static SimpleSAML_Auth_State::getStateTimeout ( )
staticprivate

Retrieve state timeout.

Returns
integer State timeout.

Definition at line 171 of file State.php.

References $globalConfig, and SimpleSAML_Configuration\getInstance().

172  {
173  if (self::$stateTimeout === null) {
175  self::$stateTimeout = $globalConfig->getInteger('session.state.timeout', 60 * 60);
176  }
177 
178  return self::$stateTimeout;
179  }
$globalConfig
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
+ Here is the call graph for this function:

◆ loadExceptionState()

static SimpleSAML_Auth_State::loadExceptionState (   $id = null)
static

Retrieve an exception state.

Parameters
string | NULL$idThe exception id. Can be NULL, in which case it will be retrieved from the request.
Returns
array|NULL The state array with the exception, or NULL if no exception was thrown.

Definition at line 381 of file State.php.

References $id, and $state.

382  {
383  assert('is_string($id) || is_null($id)');
384 
385  if ($id === null) {
386  if (!array_key_exists(self::EXCEPTION_PARAM, $_REQUEST)) {
387  // No exception
388  return null;
389  }
390  $id = $_REQUEST[self::EXCEPTION_PARAM];
391  }
392 
393  $state = self::loadState($id, self::EXCEPTION_STAGE);
394  assert('array_key_exists(self::EXCEPTION_DATA, $state)');
395 
396  return $state;
397  }
if(!array_key_exists('StateId', $_REQUEST)) $id
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10

◆ loadState()

static SimpleSAML_Auth_State::loadState (   $id,
  $stage,
  $allowMissing = false 
)
static

Retrieve saved state.

This function retrieves saved state information. If the state information has been lost, it will attempt to restart the request by calling the restart URL which is embedded in the state information. If there is no restart information available, an exception will be thrown.

Parameters
string$idState identifier (with embedded restart information).
string$stageThe stage the state should have been saved in.
bool$allowMissingWhether to allow the state to be missing.
Exceptions
SimpleSAML_Error_NoStateIf we couldn't find the state and there's no URL defined to redirect to.
ExceptionIf the stage of the state is invalid and there's no URL defined to redirect to.
Returns
array|NULL State information, or null if the state is missing and $allowMissing is true.

Definition at line 259 of file State.php.

References $id, $session, $state, SimpleSAML\Logger\debug(), SimpleSAML_Session\getSessionFromRequest(), and SimpleSAML\Utils\HTTP\redirectUntrustedURL().

Referenced by SimpleSAML_Auth_ProcessingChain\fetchProcessedState(), sspmod_authYubiKey_Auth_Source_YubiKey\handleLogin(), sspmod_core_Auth_UserPassOrgBase\handleLogin(), sspmod_core_Auth_UserPassBase\handleLogin(), sspmod_core_Auth_UserPassOrgBase\listOrganizations(), SimpleSAML\IdP\TraditionalLogoutHandler\onResponse(), and sspmod_exampleauth_Auth_Source_External\resume().

260  {
261  assert('is_string($id)');
262  assert('is_string($stage)');
263  assert('is_bool($allowMissing)');
264  SimpleSAML\Logger::debug('Loading state: '.var_export($id, true));
265 
266  $sid = self::parseStateID($id);
267 
269  $state = $session->getData('SimpleSAML_Auth_State', $sid['id']);
270 
271  if ($state === null) {
272  // Could not find saved data
273  if ($allowMissing) {
274  return null;
275  }
276 
277  if ($sid['url'] === null) {
278  throw new SimpleSAML_Error_NoState();
279  }
280 
282  }
283 
284  $state = unserialize($state);
285  assert('is_array($state)');
286  assert('array_key_exists(self::ID, $state)');
287  assert('array_key_exists(self::STAGE, $state)');
288 
289  // Verify stage
290  if ($state[self::STAGE] !== $stage) {
291  /* This could be a user trying to bypass security, but most likely it is just
292  * someone using the back-button in the browser. We try to restart the
293  * request if that is possible. If not, show an error.
294  */
295 
296  $msg = 'Wrong stage in state. Was \''.$state[self::STAGE].
297  '\', should be \''.$stage.'\'.';
298 
299  SimpleSAML\Logger::warning($msg);
300 
301  if ($sid['url'] === null) {
302  throw new Exception($msg);
303  }
304 
305  \SimpleSAML\Utils\HTTP::redirectUntrustedURL($sid['url']);
306  }
307 
308  return $state;
309  }
static debug($string)
Definition: Logger.php:213
$session
if(!array_key_exists('StateId', $_REQUEST)) $id
static redirectUntrustedURL($url, $parameters=array())
This function redirects to the specified URL after performing the appropriate security checks on it...
Definition: HTTP.php:994
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
static getSessionFromRequest()
Retrieves the current session.
Definition: Session.php:243
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseStateID()

static SimpleSAML_Auth_State::parseStateID (   $stateId)
static

Get the ID and (optionally) a URL embedded in a StateID, in the form 'id:url'.

Parameters
string$stateIdThe state ID to use.
Returns
array A hashed array with the ID and the URL (if any), in the 'id' and 'url' keys, respectively. If there's no URL in the input parameter, NULL will be returned as the value for the 'url' key.
Author
Andreas Solberg, UNINETT AS andre.nosp@m.as.s.nosp@m.olber.nosp@m.g@un.nosp@m.inett.nosp@m..no
Jaime Perez, UNINETT AS jaime.nosp@m..per.nosp@m.ez@un.nosp@m.inet.nosp@m.t.no

Definition at line 411 of file State.php.

References $id, $stateId, $url, and array.

Referenced by SimpleSAML_Utilities\parseStateID().

412  {
413  $tmp = explode(':', $stateId, 2);
414  $id = $tmp[0];
415  $url = null;
416  if (count($tmp) === 2) {
417  $url = $tmp[1];
418  }
419  return array('id' => $id, 'url' => $url);
420  }
$stateId
Definition: saml2-acs.php:76
if(!array_key_exists('StateId', $_REQUEST)) $id
Create styles array
The data for the language used.
$url
+ Here is the caller graph for this function:

◆ saveState()

static SimpleSAML_Auth_State::saveState ( $state,
  $stage,
  $rawId = false 
)
static

Save the state.

This function saves the state, and returns an id which can be used to retrieve it later. It will also update the $state array with the identifier.

Parameters
array&$stateThe login request state.
string$stageThe current stage in the login process.
bool$rawIdReturn a raw ID, without a restart URL.
Returns
string Identifier which can be used to retrieve the state later.

Definition at line 194 of file State.php.

References $id, $session, $state, SimpleSAML\Logger\debug(), and SimpleSAML_Session\getSessionFromRequest().

Referenced by sspmod_saml_Auth_Source_SP\askForIdPChange(), sspmod_authtwitter_Auth_Source_Twitter\authenticate(), sspmod_authmyspace_Auth_Source_MySpace\authenticate(), sspmod_authwindowslive_Auth_Source_LiveID\authenticate(), sspmod_authlinkedin_Auth_Source_LinkedIn\authenticate(), sspmod_negotiate_Auth_Source_Negotiate\authenticate(), sspmod_authfacebook_Auth_Source_Facebook\authenticate(), sspmod_exampleauth_Auth_Source_External\authenticate(), sspmod_authYubiKey_Auth_Source_YubiKey\authenticate(), sspmod_multiauth_Auth_Source_MultiAuth\authenticate(), sspmod_core_Auth_UserPassOrgBase\authenticate(), sspmod_core_Auth_UserPassBase\authenticate(), sspmod_cas_Auth_Source_CAS\authenticate(), sspmod_cas_Auth_Source_CAS\finalStep(), SimpleSAML_IdP\handleLogoutRequest(), SimpleSAML\IdP\TraditionalLogoutHandler\logoutNextSP(), sspmod_exampleauth_Auth_Process_RedirectTest\process(), sspmod_core_Auth_Process_WarnShortSSOInterval\process(), sspmod_preprodwarning_Auth_Process_Warning\process(), sspmod_cdc_Auth_Process_CDC\process(), sspmod_authX509_Auth_Process_ExpiryWarning\process(), sspmod_expirycheck_Auth_Process_ExpiryDate\process(), sspmod_consent_Auth_Process_Consent\process(), SimpleSAML_Auth_ProcessingChain\resumeProcessing(), sspmod_saml_Auth_Source_SP\startDisco(), SimpleSAML\IdP\IFrameLogoutHandler\startLogout(), sspmod_saml_Auth_Source_SP\startSLO2(), sspmod_saml_Auth_Source_SP\startSSO1(), sspmod_saml_Auth_Source_SP\startSSO2(), sspmod_saml_Auth_Process_ExpectedAuthnContextClassRef\unauthorized(), and sspmod_authorize_Auth_Process_Authorize\unauthorized().

195  {
196  assert('is_array($state)');
197  assert('is_string($stage)');
198  assert('is_bool($rawId)');
199 
200  $return = self::getStateId($state, $rawId);
201  $id = $state[self::ID];
202 
203  // Save stage
204  $state[self::STAGE] = $stage;
205 
206  // Save state
207  $serializedState = serialize($state);
209  $session->setData('SimpleSAML_Auth_State', $id, $serializedState, self::getStateTimeout());
210 
211  SimpleSAML\Logger::debug('Saved state: '.var_export($return, true));
212 
213  return $return;
214  }
static debug($string)
Definition: Logger.php:213
$session
if(!array_key_exists('StateId', $_REQUEST)) $id
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
static getSessionFromRequest()
Retrieves the current session.
Definition: Session.php:243
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ throwException()

static SimpleSAML_Auth_State::throwException (   $state,
SimpleSAML_Error_Exception  $exception 
)
static

Throw exception to the state exception handler.

Parameters
array$stateThe state array.
SimpleSAML_Error_Exception$exceptionThe exception.
Exceptions
SimpleSAML_Error_ExceptionIf there is no exception handler defined, it will just throw the $exception.

Definition at line 343 of file State.php.

References $id, $state, array, and SimpleSAML\Utils\HTTP\redirectTrustedURL().

Referenced by sspmod_multiauth_Auth_Source_MultiAuth\delegateAuthentication(), sspmod_negotiate_Auth_Source_Negotiate\fallBack(), SimpleSAML_IdP\handleAuthenticationRequest(), SimpleSAML_Auth_Source\initLogin(), SimpleSAML_Auth_ProcessingChain\resumeProcessing(), and sspmod_saml_Auth_Source_SP\startSSO2().

344  {
345  assert('is_array($state)');
346 
347  if (array_key_exists(self::EXCEPTION_HANDLER_URL, $state)) {
348 
349  // Save the exception
350  $state[self::EXCEPTION_DATA] = $exception;
351  $id = self::saveState($state, self::EXCEPTION_STAGE);
352 
353  // Redirect to the exception handler
355  $state[self::EXCEPTION_HANDLER_URL],
356  array(self::EXCEPTION_PARAM => $id)
357  );
358  } elseif (array_key_exists(self::EXCEPTION_HANDLER_FUNC, $state)) {
359  // Call the exception handler
360  $func = $state[self::EXCEPTION_HANDLER_FUNC];
361  assert('is_callable($func)');
362 
363  call_user_func($func, $exception, $state);
364  assert(false);
365  } else {
366  /*
367  * No exception handler is defined for the current state.
368  */
369  throw $exception;
370  }
371  }
if(!array_key_exists('StateId', $_REQUEST)) $id
static redirectTrustedURL($url, $parameters=array())
This function redirects to the specified URL without performing any security checks.
Definition: HTTP.php:962
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $stateTimeout

SimpleSAML_Auth_State::$stateTimeout = null
staticprivate

State timeout.

Definition at line 93 of file State.php.

◆ CLONE_ORIGINAL_ID

const SimpleSAML_Auth_State::CLONE_ORIGINAL_ID = 'SimpleSAML_Auth_State.cloneOriginalId'

The index in the cloned state array which contains the identifier of the original state.

Definition at line 45 of file State.php.

◆ EXCEPTION_DATA

const SimpleSAML_Auth_State::EXCEPTION_DATA = 'SimpleSAML_Auth_State.exceptionData'

The index in the state array which contains the exception data.

Definition at line 75 of file State.php.

◆ EXCEPTION_HANDLER_FUNC

const SimpleSAML_Auth_State::EXCEPTION_HANDLER_FUNC = 'SimpleSAML_Auth_State.exceptionFunc'

The index in the state array which contains the exception handler function.

Definition at line 69 of file State.php.

Referenced by sspmod_saml_IdP_SAML2\receiveAuthnRequest().

◆ EXCEPTION_HANDLER_URL

const SimpleSAML_Auth_State::EXCEPTION_HANDLER_URL = 'SimpleSAML_Auth_State.exceptionURL'

The index in the state array which contains the exception handler URL.

Definition at line 63 of file State.php.

Referenced by SimpleSAML_Auth_Source\initLogin().

◆ EXCEPTION_PARAM

const SimpleSAML_Auth_State::EXCEPTION_PARAM = 'SimpleSAML_Auth_State_exceptionId'

The URL parameter which contains the exception state id.

Definition at line 87 of file State.php.

◆ EXCEPTION_STAGE

const SimpleSAML_Auth_State::EXCEPTION_STAGE = 'SimpleSAML_Auth_State.exceptionStage'

The stage of a state with an exception.

Definition at line 81 of file State.php.

◆ ID

const SimpleSAML_Auth_State::ID = 'SimpleSAML_Auth_State.id'

The index in the state array which contains the identifier.

Definition at line 38 of file State.php.

◆ RESTART

const SimpleSAML_Auth_State::RESTART = 'SimpleSAML_Auth_State.restartURL'

The index in the state array which contains the restart URL.

Definition at line 57 of file State.php.

Referenced by sspmod_saml_IdP_SAML1\receiveAuthnRequest(), and sspmod_saml_IdP_SAML2\receiveAuthnRequest().

◆ STAGE

const SimpleSAML_Auth_State::STAGE = 'SimpleSAML_Auth_State.stage'

The index in the state array which contains the current stage.

Definition at line 51 of file State.php.


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