ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilWACSignedPath Class Reference

Class ilWACSignedPath. More...

+ Collaboration diagram for ilWACSignedPath:

Public Member Functions

 __construct (ilWACPath $ilWACPath, private GlobalHttpState $httpService, private CookieFactory $cookieFactory)
 ilWACSignedPath constructor. More...
 
 getSignedPath ()
 
 isFolderSigned ()
 
 isFolderTokenValid ()
 
 revalidatingFolderToken ()
 
 isSignedPath ()
 
 isSignedPathValid ()
 
 getTokenInstance ()
 
 setTokenInstance (ilWACToken $token_instance)
 
 getType ()
 
 setType (int $type)
 
 getPathObject ()
 
 setPathObject (ilWACPath $path_object)
 
 buildAndSetTokenInstance (int $timestamp=0, int $ttl=0)
 
 isChecked ()
 
 setChecked (bool $checked)
 

Static Public Member Functions

static signFile (string $path_to_file)
 
static signFolderOfStartFile (string $start_file_path)
 
static getTokenMaxLifetimeInSeconds ()
 
static setTokenMaxLifetimeInSeconds (int $token_max_lifetime_in_seconds)
 
static getCookieMaxLifetimeInSeconds ()
 
static setCookieMaxLifetimeInSeconds (int $cookie_max_lifetime_in_seconds)
 

Data Fields

const WAC_TOKEN_ID = 'il_wac_token'
 
const WAC_TIMESTAMP_ID = 'il_wac_ts'
 
const WAC_TTL_ID = 'il_wac_ttl'
 
const TS_SUFFIX = 'ts'
 
const TTL_SUFFIX = 'ttl'
 
const MAX_LIFETIME = 600
 

Protected Member Functions

 saveFolderToken ()
 
 checkToken ()
 
 buildTokenInstance (int $timestamp=0, int $ttl=0)
 
 getRelevantLifeTime ()
 

Protected Attributes

ilWACPath $path_object = null
 
ilWACToken $token_instance = null
 
int $type = PathType::FILE
 
bool $checked = false
 

Static Protected Attributes

static int $token_max_lifetime_in_seconds = 5
 
static int $cookie_max_lifetime_in_seconds = 300
 

Detailed Description

Class ilWACSignedPath.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
1.0.0

Definition at line 30 of file class.ilWACSignedPath.php.

Constructor & Destructor Documentation

◆ __construct()

ilWACSignedPath::__construct ( ilWACPath  $ilWACPath,
private GlobalHttpState  $httpService,
private CookieFactory  $cookieFactory 
)

ilWACSignedPath constructor.

Definition at line 49 of file class.ilWACSignedPath.php.

50 {
51 $this->setPathObject($ilWACPath);
52 }
setPathObject(ilWACPath $path_object)

References setPathObject().

+ Here is the call graph for this function:

Member Function Documentation

◆ buildAndSetTokenInstance()

ilWACSignedPath::buildAndSetTokenInstance ( int  $timestamp = 0,
int  $ttl = 0 
)
Exceptions

ilWACException

Definition at line 324 of file class.ilWACSignedPath.php.

324 : void
325 {
326 $this->setTokenInstance($this->buildTokenInstance($timestamp, $ttl));
327 }
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:70
setTokenInstance(ilWACToken $token_instance)
buildTokenInstance(int $timestamp=0, int $ttl=0)

References $timestamp, buildTokenInstance(), and setTokenInstance().

Referenced by isFolderSigned(), isSignedPathValid(), and revalidatingFolderToken().

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

◆ buildTokenInstance()

ilWACSignedPath::buildTokenInstance ( int  $timestamp = 0,
int  $ttl = 0 
)
protected
Exceptions
ilWACException

Definition at line 302 of file class.ilWACSignedPath.php.

303 {
304 if ($this->getType() === 0) {
306 }
307
308 $path = match ($this->getType()) {
309 PathType::FOLDER => $this->getPathObject()->getSecurePath(),
310 default => $this->getPathObject()->getPathWithoutQuery(),
311 };
312
313 $client = $this->getPathObject()->getClient();
314 $timestamp = $timestamp !== 0 ? $timestamp : $this->getPathObject()->getTimestamp();
315 $ttl = $ttl !== 0 ? $ttl : $this->getPathObject()->getTTL();
316
317 return new ilWACToken($path, $client, $timestamp, $ttl);
318 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$client

References $client, $timestamp, ilWACException\CODE_NO_TYPE, getPathObject(), and getType().

Referenced by buildAndSetTokenInstance(), checkToken(), and isFolderSigned().

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

◆ checkToken()

ilWACSignedPath::checkToken ( )
protected
Exceptions

ilWACException

Definition at line 270 of file class.ilWACSignedPath.php.

270 : bool
271 {
272 $request_token_string = $this->getPathObject()->getToken();
273 $request_ttl = $this->getPathObject()->getTTL();
274 $request_timestamp = $this->getPathObject()->getTimestamp();
275 $current_timestamp = time();
276
277 $timestamp_valid = ($current_timestamp < ($request_timestamp + $request_ttl));
278
279 if (!$timestamp_valid) {
280 $this->setChecked(true);
281
282 return false;
283 }
284
285 $simulated_token = $this->buildTokenInstance($request_timestamp, $request_ttl);
286 $simulated_token_string = $simulated_token->getToken();
287 $token_valid = ($simulated_token_string === $request_token_string);
288
289 if (!$token_valid) {
290 $this->setChecked(true);
291
292 return false;
293 }
294
295 return true;
296 }
setChecked(bool $checked)

References buildTokenInstance(), getPathObject(), and setChecked().

Referenced by isFolderTokenValid(), and isSignedPathValid().

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

◆ getCookieMaxLifetimeInSeconds()

static ilWACSignedPath::getCookieMaxLifetimeInSeconds ( )
static

Definition at line 346 of file class.ilWACSignedPath.php.

346 : int
347 {
349 }
static int $cookie_max_lifetime_in_seconds

References $cookie_max_lifetime_in_seconds.

Referenced by ilObjSCORMInitData\getIliasScormVars(), ilSCORM13PlayerGUI\getPlayer(), getRelevantLifeTime(), saveFolderToken(), and signFolderOfStartFile().

+ Here is the caller graph for this function:

◆ getPathObject()

ilWACSignedPath::getPathObject ( )

Definition at line 257 of file class.ilWACSignedPath.php.

257 : ?\ilWACPath
258 {
259 return $this->path_object;
260 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $path_object.

Referenced by buildTokenInstance(), checkToken(), getRelevantLifeTime(), getSignedPath(), isFolderSigned(), isSignedPath(), isSignedPathValid(), revalidatingFolderToken(), and saveFolderToken().

+ Here is the caller graph for this function:

◆ getRelevantLifeTime()

ilWACSignedPath::getRelevantLifeTime ( )
protected

Definition at line 364 of file class.ilWACSignedPath.php.

364 : int
365 {
366 $request_ttl = $this->getPathObject()->getTTL();
367 if ($request_ttl > 0) {
368 return $request_ttl;
369 }
370
371 return match ($this->getType()) {
372 PathType::FOLDER => self::getCookieMaxLifetimeInSeconds(),
373 PathType::FILE => self::getTokenMaxLifetimeInSeconds(),
374 default => 0,
375 };
376 }
static getCookieMaxLifetimeInSeconds()
static getTokenMaxLifetimeInSeconds()

References getCookieMaxLifetimeInSeconds(), getPathObject(), getTokenMaxLifetimeInSeconds(), and getType().

+ Here is the call graph for this function:

◆ getSignedPath()

ilWACSignedPath::getSignedPath ( )
Exceptions
ilWACException

Definition at line 57 of file class.ilWACSignedPath.php.

57 : string
58 {
59 if ($this->getType() !== PathType::FILE) {
61 }
62 if ($this->getPathObject()->getOriginalRequest() === '' || $this->getPathObject()->getOriginalRequest() === '0') {
63 return '';
64 }
65 if (!$this->getPathObject()->fileExists()) {
66 // return $this->getPathObject()->getOriginalRequest();
67 }
68
69 if (strpos($this->getPathObject()->getPath(), '?')) {
70 $path = $this->getPathObject()->getPath() . '&' . self::WAC_TOKEN_ID . '='
71 . $this->getTokenInstance()->getToken();
72 } else {
73 $path = $this->getPathObject()->getPath() . '?' . self::WAC_TOKEN_ID . '='
74 . $this->getTokenInstance()->getToken();
75 }
76
77 $path .= '&' . self::WAC_TTL_ID . '=' . $this->getTokenInstance()->getTTL();
78
79 return $path . '&' . self::WAC_TIMESTAMP_ID . '='
80 . $this->getTokenInstance()->getTimestamp();
81 }

References getPathObject(), getTokenInstance(), getType(), and ilWACException\WRONG_PATH_TYPE.

+ Here is the call graph for this function:

◆ getTokenInstance()

ilWACSignedPath::getTokenInstance ( )

Definition at line 237 of file class.ilWACSignedPath.php.

237 : ?\ilWACToken
238 {
240 }

References $token_instance.

Referenced by getSignedPath(), revalidatingFolderToken(), and saveFolderToken().

+ Here is the caller graph for this function:

◆ getTokenMaxLifetimeInSeconds()

static ilWACSignedPath::getTokenMaxLifetimeInSeconds ( )
static

◆ getType()

ilWACSignedPath::getType ( )

Definition at line 247 of file class.ilWACSignedPath.php.

247 : int
248 {
249 return $this->type;
250 }

References $type.

Referenced by buildTokenInstance(), getRelevantLifeTime(), getSignedPath(), and revalidatingFolderToken().

+ Here is the caller graph for this function:

◆ isChecked()

ilWACSignedPath::isChecked ( )

Definition at line 378 of file class.ilWACSignedPath.php.

378 : bool
379 {
380 return $this->checked;
381 }

References $checked.

◆ isFolderSigned()

ilWACSignedPath::isFolderSigned ( )

Definition at line 83 of file class.ilWACSignedPath.php.

83 : bool
84 {
85 $this->httpService->cookieJar();
86
87 $this->setType(PathType::FOLDER);
88 $plain_token = $this->buildTokenInstance();
89 $name = $plain_token->getHashedId();
90
91 // Token
92 $default_token = '';
93 $token_cookie_value = $this->httpService->request()->getCookieParams()[$name] ?? $default_token;
94 // Timestamp
95 $default_timestamp = 0;
96 $timestamp_cookie_value = $this->httpService->request()->getCookieParams()[$name . self::TS_SUFFIX] ?? $default_timestamp;
97 $timestamp_cookie_value = (int) $timestamp_cookie_value;
98 // TTL
99 $default_ttl = 0;
100 $ttl_cookie_value = $this->httpService->request()->getCookieParams()[$name . self::TTL_SUFFIX] ?? $default_ttl;
101 $ttl_cookie_value = (int) $ttl_cookie_value;
102
103 $this->getPathObject()->setToken($token_cookie_value);
104 $this->getPathObject()->setTimestamp($timestamp_cookie_value);
105 $this->getPathObject()->setTTL($ttl_cookie_value);
107
108 return $this->getPathObject()->hasToken();
109 }
buildAndSetTokenInstance(int $timestamp=0, int $ttl=0)

References buildAndSetTokenInstance(), buildTokenInstance(), getPathObject(), ILIAS\Repository\int(), setType(), TS_SUFFIX, and TTL_SUFFIX.

Referenced by isFolderTokenValid().

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

◆ isFolderTokenValid()

ilWACSignedPath::isFolderTokenValid ( )
Exceptions
ilWACException

Definition at line 114 of file class.ilWACSignedPath.php.

114 : bool
115 {
116 if (!$this->isFolderSigned()) {
117 return false;
118 }
119
120 return $this->checkToken();
121 }

References checkToken(), and isFolderSigned().

+ Here is the call graph for this function:

◆ isSignedPath()

ilWACSignedPath::isSignedPath ( )

Definition at line 190 of file class.ilWACSignedPath.php.

190 : bool
191 {
192 return ($this->getPathObject()->hasToken() && $this->getPathObject()->hasTimestamp()
193 && $this->getPathObject()->hasTTL());
194 }

References getPathObject().

+ Here is the call graph for this function:

◆ isSignedPathValid()

ilWACSignedPath::isSignedPathValid ( )
Exceptions
ilWACException

Definition at line 199 of file class.ilWACSignedPath.php.

199 : bool
200 {
201 $this->buildAndSetTokenInstance($this->getPathObject()->getTimestamp(), $this->getPathObject()->getTTL());
202
203 return $this->checkToken();
204 }

References buildAndSetTokenInstance(), checkToken(), and getPathObject().

+ Here is the call graph for this function:

◆ revalidatingFolderToken()

ilWACSignedPath::revalidatingFolderToken ( )

Definition at line 175 of file class.ilWACSignedPath.php.

175 : bool
176 {
177 if ($this->getType() !== PathType::FOLDER) {
178 return false;
179 }
180 $this->buildAndSetTokenInstance(time(), $this->getPathObject()->getTTL());
181 $this->getPathObject()->setTTL($this->getTokenInstance()->getTTL());
182 $this->getPathObject()->setTimestamp($this->getTokenInstance()->getTimestamp());
183 $this->getPathObject()->setToken($this->getTokenInstance()->getToken());
184
185 $this->saveFolderToken();
186
187 return true;
188 }

References buildAndSetTokenInstance(), getPathObject(), getTokenInstance(), getType(), and saveFolderToken().

+ Here is the call graph for this function:

◆ saveFolderToken()

ilWACSignedPath::saveFolderToken ( )
protected

Definition at line 123 of file class.ilWACSignedPath.php.

123 : void
124 {
125 $ttl = $this->getPathObject()->getTTL();
126 $cookie_lifetime = $ttl !== 0 ? $ttl : self::getCookieMaxLifetimeInSeconds();
127 $id = $this->getTokenInstance()->getHashedId();
128 $expire = time() + $cookie_lifetime + 3600;
129 $secure = true;
130 $domain = null;
131 $http_only = true;
132 $path = '/';
133
134 $tokenCookie = $this->cookieFactory->create($id, $this->getTokenInstance()->getToken())
135 ->withExpires($expire)
136 ->withPath($path)
137 ->withSecure($secure)
138 ->withDomain($domain)
139 ->withHttpOnly($http_only);
140
141 $timestampCookie = $this->cookieFactory->create($id . self::TS_SUFFIX, time())
142 ->withExpires($expire)
143 ->withPath($path)
144 ->withDomain($domain)
145 ->withSecure($secure)
146 ->withHttpOnly($http_only);
147
148 $ttlCookie = $this->cookieFactory->create($id . self::TTL_SUFFIX, $cookie_lifetime)
149 ->withExpires($expire)
150 ->withPath($path)
151 ->withDomain($domain)
152 ->withSecure($secure)
153 ->withHttpOnly($http_only);
154
155 $jar = $this->httpService->cookieJar()->with($tokenCookie)
156 ->with($timestampCookie)
157 ->with($ttlCookie);
158
159 // FIX: currently the cookies are never stored, we must use setcookie
160 foreach ($jar->getAll() as $cookie) {
161 setcookie(
162 $cookie->getName(),
163 (string) $cookie->getValue(),
164 [
165 'expires' => $cookie->getExpires(),
166 'path' => $cookie->getPath() ?? '/',
167 'domain' => $cookie->getDomain() ?? '',
168 'secure' => $cookie->getSecure(),
169 'httponly' => $cookie->getHttpOnly()
170 ]
171 );
172 }
173 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id, getCookieMaxLifetimeInSeconds(), getPathObject(), and getTokenInstance().

Referenced by revalidatingFolderToken().

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

◆ setChecked()

ilWACSignedPath::setChecked ( bool  $checked)

Definition at line 383 of file class.ilWACSignedPath.php.

383 : void
384 {
385 $this->checked = $checked;
386 }

References $checked, and ILIAS\UI\examples\Symbol\Glyph\Checked\checked().

Referenced by checkToken().

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

◆ setCookieMaxLifetimeInSeconds()

static ilWACSignedPath::setCookieMaxLifetimeInSeconds ( int  $cookie_max_lifetime_in_seconds)
static
Exceptions

ilWACException

Definition at line 356 of file class.ilWACSignedPath.php.

356 : void
357 {
358 if ($cookie_max_lifetime_in_seconds > self::MAX_LIFETIME) {
360 }
361 self::$cookie_max_lifetime_in_seconds = $cookie_max_lifetime_in_seconds;
362 }

References $cookie_max_lifetime_in_seconds, and ilWACException\MAX_LIFETIME.

◆ setPathObject()

ilWACSignedPath::setPathObject ( ilWACPath  $path_object)

Definition at line 262 of file class.ilWACSignedPath.php.

262 : void
263 {
264 $this->path_object = $path_object;
265 }

References $path_object.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setTokenInstance()

ilWACSignedPath::setTokenInstance ( ilWACToken  $token_instance)

Definition at line 242 of file class.ilWACSignedPath.php.

242 : void
243 {
244 $this->token_instance = $token_instance;
245 }

References $token_instance.

Referenced by buildAndSetTokenInstance().

+ Here is the caller graph for this function:

◆ setTokenMaxLifetimeInSeconds()

static ilWACSignedPath::setTokenMaxLifetimeInSeconds ( int  $token_max_lifetime_in_seconds)
static
Exceptions

ilWACException

Definition at line 338 of file class.ilWACSignedPath.php.

338 : void
339 {
340 if ($token_max_lifetime_in_seconds > self::MAX_LIFETIME) {
342 }
343 self::$token_max_lifetime_in_seconds = $token_max_lifetime_in_seconds;
344 }

References $token_max_lifetime_in_seconds, and ilWACException\MAX_LIFETIME.

Referenced by ILIAS\OnScreenChat\Repository\Subscriber\getDataByUserIds(), ilWACTokenTest\getModifiedSignedPath(), assQuestion\getSuggestedSolutionOutput(), and ilWACTokenTest\testFileToken().

+ Here is the caller graph for this function:

◆ setType()

ilWACSignedPath::setType ( int  $type)

Definition at line 252 of file class.ilWACSignedPath.php.

252 : void
253 {
254 $this->type = $type;
255 }

References $type.

Referenced by isFolderSigned().

+ Here is the caller graph for this function:

◆ signFile()

static ilWACSignedPath::signFile ( string  $path_to_file)
static
Exceptions
ilWACException

Definition at line 211 of file class.ilWACSignedPath.php.

211 : string
212 {
213 global $DIC;
214 if ($path_to_file === '' || $path_to_file === '0') {
215 return '';
216 }
217 $ilWACPath = new ilWACPath($path_to_file);
218 if ($ilWACPath->getClient() === '' || $ilWACPath->getClient() === '0') {
219 return $path_to_file;
220 }
221 $obj = new self($ilWACPath, $DIC->http(), $DIC->http()->cookies());
222 $obj->setType(PathType::FILE);
223 $obj->buildAndSetTokenInstance(time(), self::getTokenMaxLifetimeInSeconds());
224
225 return $obj->getSignedPath();
226 }
global $DIC
Definition: shib_login.php:26

References $DIC, and getTokenMaxLifetimeInSeconds().

Referenced by assImagemapQuestionGUI\areaEditor(), ILIAS\MediaObjects\MediaObjectManager\getLocalSrc(), ilWACTokenTest\getModifiedSignedPath(), assQuestion\getSuggestedSolutionOutput(), ilObjMediaObject\getXML(), and ilWACTokenTest\testFileToken().

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

◆ signFolderOfStartFile()

static ilWACSignedPath::signFolderOfStartFile ( string  $start_file_path)
static

Definition at line 228 of file class.ilWACSignedPath.php.

228 : void
229 {
230 global $DIC;
231 $obj = new self(new ilWACPath($start_file_path), $DIC->http(), $DIC->http()->cookies());
232 $obj->setType(PathType::FOLDER);
233 $obj->buildAndSetTokenInstance(time(), self::getCookieMaxLifetimeInSeconds());
234 $obj->saveFolderToken();
235 }

References $DIC, and getCookieMaxLifetimeInSeconds().

Referenced by ilSCORMPresentationGUI\frameset(), ilSCORM13PlayerGUI\getPlayer(), ilExerciseManagementGUI\openSubmissionViewObject(), ilSCORM13PlayerGUI\pingSession(), ilSCORMPresentationGUI\pingSession(), and ilWACTokenTest\testCookieGeneration().

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

Field Documentation

◆ $checked

bool ilWACSignedPath::$checked = false
protected

Definition at line 44 of file class.ilWACSignedPath.php.

Referenced by isChecked(), and setChecked().

◆ $cookie_max_lifetime_in_seconds

int ilWACSignedPath::$cookie_max_lifetime_in_seconds = 300
staticprotected

◆ $path_object

ilWACPath ilWACSignedPath::$path_object = null
protected

Definition at line 39 of file class.ilWACSignedPath.php.

Referenced by getPathObject(), and setPathObject().

◆ $token_instance

ilWACToken ilWACSignedPath::$token_instance = null
protected

Definition at line 40 of file class.ilWACSignedPath.php.

Referenced by getTokenInstance(), and setTokenInstance().

◆ $token_max_lifetime_in_seconds

int ilWACSignedPath::$token_max_lifetime_in_seconds = 5
staticprotected

◆ $type

int ilWACSignedPath::$type = PathType::FILE
protected

Definition at line 41 of file class.ilWACSignedPath.php.

Referenced by getType(), and setType().

◆ MAX_LIFETIME

const ilWACSignedPath::MAX_LIFETIME = 600

Definition at line 37 of file class.ilWACSignedPath.php.

◆ TS_SUFFIX

const ilWACSignedPath::TS_SUFFIX = 'ts'

Definition at line 35 of file class.ilWACSignedPath.php.

Referenced by isFolderSigned().

◆ TTL_SUFFIX

const ilWACSignedPath::TTL_SUFFIX = 'ttl'

Definition at line 36 of file class.ilWACSignedPath.php.

Referenced by isFolderSigned().

◆ WAC_TIMESTAMP_ID

const ilWACSignedPath::WAC_TIMESTAMP_ID = 'il_wac_ts'

Definition at line 33 of file class.ilWACSignedPath.php.

Referenced by ilWACPath\handleParameters(), and ilWACPath\setTimestamp().

◆ WAC_TOKEN_ID

const ilWACSignedPath::WAC_TOKEN_ID = 'il_wac_token'

Definition at line 32 of file class.ilWACSignedPath.php.

Referenced by ilWACPath\handleParameters(), and ilWACPath\setToken().

◆ WAC_TTL_ID

const ilWACSignedPath::WAC_TTL_ID = 'il_wac_ttl'

Definition at line 34 of file class.ilWACSignedPath.php.

Referenced by ilWACPath\handleParameters(), and ilWACPath\setTTL().


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