ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache Class Reference
+ Collaboration diagram for ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache:

Public Member Functions

 __construct (private Filesystem $filesystem, SecretKeyRotation $secret_key_rotation)
 
 isAuthenticated (string $username, string $password)
 
 setAuthenticated (string $username, string $password, int $user_id)
 

Private Member Functions

 getAuthCacheFile (string $username)
 
 readAuthCache (string $username)
 
 writeAuthCache (string $username, string $password_hash, int $usr_id)
 

Private Attributes

const string SALT = 'webdav'
 
const string F_USERNAME = 'username'
 
const string F_USR_ID = 'usr_id'
 
const string F_PW_HASH = 'password'
 
DataSigner $data_signer
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache::__construct ( private Filesystem  $filesystem,
SecretKeyRotation  $secret_key_rotation 
)

Definition at line 38 of file ILIASAuthenticationFileCache.php.

41 {
42 $this->data_signer = new DataSigner(
43 $secret_key_rotation
44 );
45 }

Member Function Documentation

◆ getAuthCacheFile()

ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache::getAuthCacheFile ( string  $username)
private

Definition at line 47 of file ILIASAuthenticationFileCache.php.

47 : string
48 {
49 return 'davcache_' . hash('sha256', $username);
50 }

Referenced by ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache\readAuthCache(), and ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache\writeAuthCache().

+ Here is the caller graph for this function:

◆ isAuthenticated()

ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache::isAuthenticated ( string  $username,
string  $password 
)

Definition at line 77 of file ILIASAuthenticationFileCache.php.

77 : ?int
78 {
79 $cached = $this->readAuthCache($username);
80 if ($cached === null) {
81 return null;
82 }
83 // has the password, since we stored it hashed
84 $password = hash('sha256', $password);
85
86 if ($cached[self::F_USERNAME] === $username && $cached[self::F_PW_HASH] === $password) {
87 return (int) $cached[self::F_USR_ID]; // retun user_id if corrent
88 }
89
90 return null;
91 }

References ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache\F_USR_ID, and ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache\readAuthCache().

+ Here is the call graph for this function:

◆ readAuthCache()

ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache::readAuthCache ( string  $username)
private

Definition at line 52 of file ILIASAuthenticationFileCache.php.

52 : ?array
53 {
54 $file = $this->getAuthCacheFile($username);
55 if (!$this->filesystem->has($file)) {
56 return null;
57 }
58 $raw = $this->filesystem->read($file);
59
60 return $this->data_signer->verify($raw, self::SALT);
61 }

References ILIAS\Repository\filesystem(), and ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache\getAuthCacheFile().

Referenced by ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache\isAuthenticated().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAuthenticated()

ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache::setAuthenticated ( string  $username,
string  $password,
int  $user_id 
)

Definition at line 93 of file ILIASAuthenticationFileCache.php.

97 : void {
98 // has the password, since we do not want to store them
99 $password = hash('sha256', $password);
100
101 $this->writeAuthCache($username, $password, $user_id);
102 }
writeAuthCache(string $username, string $password_hash, int $usr_id)

◆ writeAuthCache()

ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache::writeAuthCache ( string  $username,
string  $password_hash,
int  $usr_id 
)
private

Definition at line 63 of file ILIASAuthenticationFileCache.php.

63 : void
64 {
65 $file = $this->getAuthCacheFile($username);
66
67 $payload = [
68 self::F_USR_ID => $usr_id,
69 self::F_USERNAME => $username,
70 self::F_PW_HASH => $password_hash,
71 ];
72
73 $payload = $this->data_signer->sign($payload, self::SALT);
74 $this->filesystem->put($file, $payload);
75 }
if(count($parts) !=3) $payload
Definition: ltitoken.php:67

References $payload, ILIAS\Repository\filesystem(), and ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache\getAuthCacheFile().

+ Here is the call graph for this function:

Field Documentation

◆ $data_signer

DataSigner ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache::$data_signer
private

Definition at line 36 of file ILIASAuthenticationFileCache.php.

◆ F_PW_HASH

const string ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache::F_PW_HASH = 'password'
private

Definition at line 35 of file ILIASAuthenticationFileCache.php.

◆ F_USERNAME

const string ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache::F_USERNAME = 'username'
private

Definition at line 33 of file ILIASAuthenticationFileCache.php.

◆ F_USR_ID

const string ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache::F_USR_ID = 'usr_id'
private

◆ SALT

const string ILIAS\WebDAV\Auth\ILIASAuthenticationFileCache::SALT = 'webdav'
private

Definition at line 32 of file ILIASAuthenticationFileCache.php.


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