ILIAS  release_8 Revision v8.24
ilCtrlTokenRepository Class Reference

Class ilCtrlTokenRepository. More...

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

Public Member Functions

 getToken ()
 @inheritDoc More...
 
 getToken ()
 Returns a temporary ilCtrlToken for the given session (id). More...
 

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.

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

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

Referenced by getToken().

+ 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.

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

References $token.

Referenced by getToken().

+ Here is the caller graph for this function:

◆ getToken()

ilCtrlTokenRepository::getToken ( )

@inheritDoc

Implements ilCtrlTokenRepositoryInterface.

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

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.
generateToken()
Returns a cryptographically secure token.

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

+ 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.

45 : void
46 {
48 }
static set(string $a_var, $a_val)
Set a value.

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

Referenced by getToken().

+ 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: