ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCtrlTokenRepository Class Reference

Class ilCtrlTokenRepository. More...

+ Inheritance diagram for ilCtrlTokenRepository:
+ Collaboration diagram for ilCtrlTokenRepository:

Public Member Functions

 getToken ()
 

Protected Member Functions

 fetchToken ()
 Returns the currently stored token from the session. More...
 
 storeToken (ilCtrlTokenInterface $token)
 Stores the given token in the curren session. More...
 
 generateToken ()
 Returns a cryptographically secure token. More...
 

Detailed Description

Member Function Documentation

◆ fetchToken()

ilCtrlTokenRepository::fetchToken ( )
protected

Returns the currently stored token from the session.

Returns
ilCtrlTokenInterface|null

Definition at line 31 of file class.ilCtrlTokenRepository.php.

References ilSession\get(), ilSession\has(), and ilCtrlInterface\PARAM_CSRF_TOKEN.

Referenced by getToken().

32  {
34  return unserialize(ilSession::get(ilCtrlInterface::PARAM_CSRF_TOKEN), [ilCtrlTokenInterface::class]);
35  }
36 
37  return null;
38  }
static get(string $a_var)
const PARAM_CSRF_TOKEN
$_GET request parameter names, used throughout ilCtrl.
static has($a_var)
Interface ilCtrlTokenInterface describes an ilCtrl token.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generateToken()

ilCtrlTokenRepository::generateToken ( )
protected

Returns a cryptographically secure token.

Returns
ilCtrlToken

Definition at line 55 of file class.ilCtrlTokenRepository.php.

References $token.

Referenced by getToken().

56  {
57  // random_bytes() is cryptographically secure but
58  // depends on the system it's running on. If the
59  // generation fails, we use a less secure option
60  // that is available for sure.
61 
62  try {
63  $token = bin2hex(random_bytes(32));
64  } catch (Throwable $t) {
65  $token = md5(uniqid((string) time(), true));
66  }
67 
68  return new ilCtrlToken($token);
69  }
Class ilCtrlToken is responsible for generating and storing unique CSRF tokens.
$token
Definition: xapitoken.php:70
Interface ilCtrlTokenInterface describes an ilCtrl token.
+ Here is the caller graph for this function:

◆ getToken()

ilCtrlTokenRepository::getToken ( )

Implements ilCtrlTokenRepositoryInterface.

Definition at line 17 of file class.ilCtrlTokenRepository.php.

References $token, fetchToken(), generateToken(), and storeToken().

18  {
19  $token = $this->fetchToken() ?? $this->generateToken();
20 
21  $this->storeToken($token);
22 
23  return $token;
24  }
fetchToken()
Returns the currently stored token from the session.
storeToken(ilCtrlTokenInterface $token)
Stores the given token in the curren session.
$token
Definition: xapitoken.php:70
Interface ilCtrlTokenInterface describes an ilCtrl token.
generateToken()
Returns a cryptographically secure token.
+ Here is the call graph for this function:

◆ storeToken()

ilCtrlTokenRepository::storeToken ( ilCtrlTokenInterface  $token)
protected

Stores the given token in the curren session.

Parameters
ilCtrlTokenInterface$token

Definition at line 45 of file class.ilCtrlTokenRepository.php.

References ilCtrlInterface\PARAM_CSRF_TOKEN, and ilSession\set().

Referenced by getToken().

45  : void
46  {
48  }
const PARAM_CSRF_TOKEN
$_GET request parameter names, used throughout ilCtrl.
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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