ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 45 of file class.ilCtrlTokenRepository.php.

46 {
48 return unserialize(ilSession::get(ilCtrlInterface::PARAM_CSRF_TOKEN), [ilCtrlTokenInterface::class]);
49 }
50
51 return null;
52 }
static get(string $a_var)
static has($a_var)
const PARAM_CSRF_TOKEN
$_GET request parameter names, used throughout ilCtrl.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

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 69 of file class.ilCtrlTokenRepository.php.

70 {
71 // random_bytes() is cryptographically secure but
72 // depends on the system it's running on. If the
73 // generation fails, we use a less secure option
74 // that is available for sure.
75
76 try {
77 $token = bin2hex(random_bytes(32));
78 } catch (Throwable $t) {
79 $token = md5(uniqid((string) time(), true));
80 }
81
82 return new ilCtrlToken($token);
83 }
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 31 of file class.ilCtrlTokenRepository.php.

32 {
33 $token = $this->fetchToken() ?? $this->generateToken();
34
35 $this->storeToken($token);
36
37 return $token;
38 }
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 59 of file class.ilCtrlTokenRepository.php.

59 : void
60 {
62 }
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: