ILIAS  release_7 Revision v7.30-3-g800a261c036
ilWACSignedPath Class Reference

Class ilWACSignedPath. More...

+ Collaboration diagram for ilWACSignedPath:

Public Member Functions

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

Static Public Member Functions

static signFile ($path_to_file)
 
static signFolderOfStartFile ($start_file_path)
 
static getTokenMaxLifetimeInSeconds ()
 
static setTokenMaxLifetimeInSeconds ($token_max_lifetime_in_seconds)
 
static getCookieMaxLifetimeInSeconds ()
 
static setCookieMaxLifetimeInSeconds ($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 ($timestamp=0, $ttl=0)
 
 getRelevantLifeTime ()
 

Protected Attributes

 $path_object = null
 
 $token_instance = null
 
 $type = PathType::FILE
 
 $checked = false
 

Static Protected Attributes

static $token_max_lifetime_in_seconds = 3
 
static $cookie_max_lifetime_in_seconds = 300
 

Private Attributes

 $httpService
 
 $cookieFactory
 

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 37 of file class.ilWACSignedPath.php.

Constructor & Destructor Documentation

◆ __construct()

ilWACSignedPath::__construct ( ilWACPath  $ilWACPath,
GlobalHttpState  $httpState,
CookieFactory  $cookieFactory 
)

ilWACSignedPath constructor.

Parameters
\ilWACPath$ilWACPath
GlobalHttpState$httpState
CookieFactory$cookieFactory

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

88 {
89 $this->setPathObject($ilWACPath);
90 $this->httpService = $httpState;
91 $this->cookieFactory = $cookieFactory;
92 }
setPathObject(ilWACPath $path_object)

References $cookieFactory, and setPathObject().

+ Here is the call graph for this function:

Member Function Documentation

◆ buildAndSetTokenInstance()

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

ilWACException

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

437 {
438 assert(is_int($timestamp));
439 assert(is_int($ttl));
440
441 $this->setTokenInstance($this->buildTokenInstance($timestamp, $ttl));
442 }
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
setTokenInstance(ilWACToken $token_instance)
buildTokenInstance($timestamp=0, $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 (   $timestamp = 0,
  $ttl = 0 
)
protected
Parameters
int$timestamp
int$ttl
Returns
ilWACToken
Exceptions
ilWACException

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

405 {
406 assert(is_int($timestamp));
407 assert(is_int($ttl));
408 if (!$this->getType()) {
410 }
411
412 switch ($this->getType()) {
413 case PathType::FOLDER:
414 $path = $this->getPathObject()->getSecurePath();
415 break;
416 default:
417 $path = $this->getPathObject()->getPathWithoutQuery();
418 break;
419 }
420
421 $client = $this->getPathObject()->getClient();
422 $timestamp = $timestamp !== 0 ? $timestamp : $this->getPathObject()->getTimestamp();
423 $ttl = $ttl !== 0 ? $ttl : $this->getPathObject()->getTTL();
424
425 return new ilWACToken($path, $client, $timestamp, $ttl);
426 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilWACToken.
if($_SERVER['argc']< 4) $client
Definition: cron.php:12

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
Returns
bool
Exceptions

ilWACException

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

369 {
370 $request_token_string = $this->getPathObject()->getToken();
371 $request_ttl = $this->getPathObject()->getTTL();
372 $request_timestamp = $this->getPathObject()->getTimestamp();
373 $current_timestamp = time();
374
375 $timestamp_valid = ($current_timestamp < ($request_timestamp + $request_ttl));
376
377 if (!$timestamp_valid) {
378 $this->setChecked(true);
379
380 return false;
381 }
382
383 $simulated_token = $this->buildTokenInstance($request_timestamp, $request_ttl);
384 $simulated_token_string = $simulated_token->getToken();
385 $token_valid = ($simulated_token_string == $request_token_string);
386
387 if (!$token_valid) {
388 $this->setChecked(true);
389
390 return false;
391 }
392
393 return true;
394 }

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
Returns
int

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

474 {
476 }
static $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 ( )

◆ getRelevantLifeTime()

ilWACSignedPath::getRelevantLifeTime ( )
protected
Returns
int

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

500 {
501 $request_ttl = $this->getPathObject()->getTTL();
502 if ($request_ttl > 0) {
503 return $request_ttl;
504 }
505 switch ($this->getType()) {
506 case PathType::FOLDER:
508 break;
509 case PathType::FILE:
511 break;
512 default:
513 $life_time = 0;
514 break;
515 }
516
517 return $life_time;
518 }
static getCookieMaxLifetimeInSeconds()
static getTokenMaxLifetimeInSeconds()

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

+ Here is the call graph for this function:

◆ getSignedPath()

ilWACSignedPath::getSignedPath ( )
Returns
string
Exceptions
ilWACException

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

100 {
101 if ($this->getType() !== PathType::FILE) {
103 }
104 if (!$this->getPathObject()->getOriginalRequest()) {
105 return '';
106 }
107 if (!$this->getPathObject()->fileExists()) {
108 // return $this->getPathObject()->getOriginalRequest();
109 }
110
111 if (strpos($this->getPathObject()->getPath(), '?')) {
112 $path = $this->getPathObject()->getPath() . '&' . self::WAC_TOKEN_ID . '='
113 . $this->getTokenInstance()->getToken();
114 } else {
115 $path = $this->getPathObject()->getPath() . '?' . self::WAC_TOKEN_ID . '='
116 . $this->getTokenInstance()->getToken();
117 }
118
119 $path = $path . '&' . self::WAC_TTL_ID . '=' . $this->getTokenInstance()->getTTL();
120 $path = $path . '&' . self::WAC_TIMESTAMP_ID . '='
121 . $this->getTokenInstance()->getTimestamp();
122
123 return $path;
124 }

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

+ Here is the call graph for this function:

◆ getTokenInstance()

ilWACSignedPath::getTokenInstance ( )
Returns
ilWACToken

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

310 {
312 }

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 ( )
Returns
int

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

329 {
330 return (int) $this->type;
331 }

References $type.

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

+ Here is the caller graph for this function:

◆ isChecked()

ilWACSignedPath::isChecked ( )
Returns
bool

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

525 {
526 return (bool) $this->checked;
527 }

References $checked.

◆ isFolderSigned()

ilWACSignedPath::isFolderSigned ( )
Returns
bool

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

131 {
132 $jar = $this->httpService->cookieJar();
133 $cookies = $jar->getAll();
134
135 $this->setType(PathType::FOLDER);
136 $plain_token = $this->buildTokenInstance();
137 $name = $plain_token->getHashedId();
138
139 // Token
140 $default_token = '';
141 $token_cookie_value = $this->httpService->request()->getCookieParams()[$name] ?? $default_token;
142 // Timestamp
143 $default_timestamp = 0;
144 $timestamp_cookie_value = $this->httpService->request()->getCookieParams()[$name . self::TS_SUFFIX] ?? $default_timestamp;
145 $timestamp_cookie_value = intval($timestamp_cookie_value);
146 // TTL
147 $default_ttl = 0;
148 $ttl_cookie_value = $this->httpService->request()->getCookieParams()[$name . self::TTL_SUFFIX] ?? $default_ttl;
149 $ttl_cookie_value = intval($ttl_cookie_value);
150
151 $this->getPathObject()->setToken($token_cookie_value);
152 $this->getPathObject()->setTimestamp($timestamp_cookie_value);
153 $this->getPathObject()->setTTL($ttl_cookie_value);
155
156 return $this->getPathObject()->hasToken();
157 }
buildAndSetTokenInstance($timestamp=0, $ttl=0)
if($format !==null) $name
Definition: metadata.php:230

References $name, buildAndSetTokenInstance(), buildTokenInstance(), getPathObject(), 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 ( )
Returns
bool
Exceptions
ilWACException

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

165 {
166 if (!$this->isFolderSigned()) {
167 return false;
168 }
169
170 return $this->checkToken();
171 }

References checkToken(), and isFolderSigned().

+ Here is the call graph for this function:

◆ isSignedPath()

ilWACSignedPath::isSignedPath ( )
Returns
bool

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

251 {
252 return ($this->getPathObject()->hasToken() && $this->getPathObject()->hasTimestamp()
253 && $this->getPathObject()->hasTTL());
254 }

References getPathObject().

+ Here is the call graph for this function:

◆ isSignedPathValid()

ilWACSignedPath::isSignedPathValid ( )
Returns
bool
Exceptions
ilWACException

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

262 {
263 $this->buildAndSetTokenInstance($this->getPathObject()->getTimestamp(), $this->getPathObject()->getTTL());
264
265 return $this->checkToken();
266 }

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

+ Here is the call graph for this function:

◆ revalidatingFolderToken()

ilWACSignedPath::revalidatingFolderToken ( )
Returns
bool

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

232 {
233 if ($this->getType() !== PathType::FOLDER) {
234 return false;
235 }
236 $this->buildAndSetTokenInstance(time(), $this->getPathObject()->getTTL());
237 $this->getPathObject()->setTTL($this->getTokenInstance()->getTTL());
238 $this->getPathObject()->setTimestamp($this->getTokenInstance()->getTimestamp());
239 $this->getPathObject()->setToken($this->getTokenInstance()->getToken());
240
241 $this->saveFolderToken();
242
243 return true;
244 }

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

+ Here is the call graph for this function:

◆ saveFolderToken()

ilWACSignedPath::saveFolderToken ( )
protected
Returns
void

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

178 {
179 $ttl = $this->getPathObject()->getTTL();
180 $cookie_lifetime = $ttl !== 0 ? $ttl : self::getCookieMaxLifetimeInSeconds();
181 $id = $this->getTokenInstance()->getHashedId();
182 $expire = time() + $cookie_lifetime + 3600;
183 $secure = true;
184 $domain = null;
185 $http_only = true;
186 $path = '/';
187
188 $tokenCookie = $this->cookieFactory->create($id, $this->getTokenInstance()->getToken())
189 ->withExpires($expire)
190 ->withPath($path)
191 ->withSecure($secure)
192 ->withDomain($domain)
193 ->withHttpOnly($http_only);
194
195 $timestampCookie = $this->cookieFactory->create($id . self::TS_SUFFIX, time())
196 ->withExpires($expire)
197 ->withPath($path)
198 ->withDomain($domain)
199 ->withSecure($secure)
200 ->withHttpOnly($http_only);
201
202 $ttlCookie = $this->cookieFactory->create($id . self::TTL_SUFFIX, $cookie_lifetime)
203 ->withExpires($expire)
204 ->withPath($path)
205 ->withDomain($domain)
206 ->withSecure($secure)
207 ->withHttpOnly($http_only);
208
209 $jar = $this->httpService->cookieJar()->with($tokenCookie)
210 ->with($timestampCookie)
211 ->with($ttlCookie);
212
213 // FIX: currently the cookies are never stored, we must use setcookie
214 foreach ($jar->getAll() as $cookie) {
215 setcookie(
216 $cookie->getName(),
217 $cookie->getValue(),
218 $cookie->getExpires(),
219 $cookie->getPath(),
220 $cookie->getDomain(),
221 $cookie->getSecure(),
222 $cookie->getHttpOnly()
223 );
224 }
225 }

References 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 (   $checked)
Parameters
bool$checked
Returns
void

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

535 {
536 assert(is_bool($checked));
537 $this->checked = $checked;
538 }

References $checked.

Referenced by checkToken().

+ Here is the caller graph for this function:

◆ setCookieMaxLifetimeInSeconds()

static ilWACSignedPath::setCookieMaxLifetimeInSeconds (   $cookie_max_lifetime_in_seconds)
static
Parameters
int$cookie_max_lifetime_in_seconds
Returns
void
Exceptions

ilWACException

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

487 {
488 assert(is_int($cookie_max_lifetime_in_seconds));
489 if ($cookie_max_lifetime_in_seconds > self::MAX_LIFETIME) {
491 }
492 self::$cookie_max_lifetime_in_seconds = $cookie_max_lifetime_in_seconds;
493 }

References $cookie_max_lifetime_in_seconds, and ilWACException\MAX_LIFETIME.

◆ setPathObject()

ilWACSignedPath::setPathObject ( ilWACPath  $path_object)
Parameters
ilWACPath$path_object
Returns
void

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

359 {
360 $this->path_object = $path_object;
361 }

References $path_object.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setTokenInstance()

ilWACSignedPath::setTokenInstance ( ilWACToken  $token_instance)
Parameters
ilWACToken$token_instance
Returns
void

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

320 {
321 $this->token_instance = $token_instance;
322 }

References $token_instance.

Referenced by buildAndSetTokenInstance().

+ Here is the caller graph for this function:

◆ setTokenMaxLifetimeInSeconds()

static ilWACSignedPath::setTokenMaxLifetimeInSeconds (   $token_max_lifetime_in_seconds)
static

◆ setType()

ilWACSignedPath::setType (   $type)
Parameters
int$type
Returns
void

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

339 {
340 assert(is_int($type));
341 $this->type = $type;
342 }

References $type.

Referenced by isFolderSigned().

+ Here is the caller graph for this function:

◆ signFile()

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

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

277 {
278 if (!$path_to_file) {
279 return '';
280 }
281 $ilWACPath = new ilWACPath($path_to_file, false);
282 if (!$ilWACPath->getClient()) {
283 return $path_to_file;
284 }
285 $obj = new self($ilWACPath, self::http(), new CookieFactoryImpl());
286 $obj->setType(PathType::FILE);
287 $obj->buildAndSetTokenInstance(time(), self::getTokenMaxLifetimeInSeconds());
288
289 return $obj->getSignedPath();
290 }
Class ilWACPath.
static http()
Fetches the global http state from ILIAS.

References getTokenMaxLifetimeInSeconds(), and ILIAS\FileDelivery\http().

Referenced by ilObjUser\_getPersonalPicturePath(), ilRTE\_replaceMediaObjectImageSrc(), ilCertificateSettingsFormRepository\createForm(), ilPollBlockGUI\fillRow(), ilMediaCastTableGUI\fillRow(), ilMediaPoolTableGUI\fillRow(), ilObjStyleSheet\getContentStylePath(), ilPublicUserProfileGUI\getEmbeddable(), ilDclMobRecordRepresentation\getHTML(), ilBadgeRenderer\getHTML(), ilWACTokenTest\getModifiedSignedPath(), assImagemapQuestionGUI\getPreview(), ilPreviewGUI\getPreviewHTML(), assMatchingQuestionGUI\getSolutionOutput(), assQuestion\getSuggestedSolutionOutput(), assImagemapQuestionGUI\getTestOutput(), ilObjMediaObject\getXML(), ilUserCertificateGUI\listCertificates(), ilObjPortfolioBaseGUI\renderFullscreenHeader(), ilObjBlogGUI\renderFullscreenHeader(), ilObjCertificateSettingsGUI\settings(), ilObjMediaCastGUI\showGallery(), ilWACCheckingInstanceTest\testBasicWithFileSigning(), and ilWACTokenTest\testFileToken().

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

◆ signFolderOfStartFile()

static ilWACSignedPath::signFolderOfStartFile (   $start_file_path)
static
Parameters
string$start_file_path
Returns
void

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

298 {
299 $obj = new self(new ilWACPath($start_file_path, false), self::http(), new CookieFactoryImpl());
300 $obj->setType(PathType::FOLDER);
301 $obj->buildAndSetTokenInstance(time(), self::getCookieMaxLifetimeInSeconds());
302 $obj->saveFolderToken();
303 }

References getCookieMaxLifetimeInSeconds(), and ILIAS\FileDelivery\http().

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

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

Field Documentation

◆ $checked

ilWACSignedPath::$checked = false
protected

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

Referenced by isChecked(), and setChecked().

◆ $cookie_max_lifetime_in_seconds

ilWACSignedPath::$cookie_max_lifetime_in_seconds = 300
staticprotected

◆ $cookieFactory

CookieFactory ilWACSignedPath::$cookieFactory
private

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

Referenced by __construct().

◆ $httpService

ILIAS DI HTTPServices ilWACSignedPath::$httpService
private

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

◆ $path_object

ilWACSignedPath::$path_object = null
protected

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

Referenced by getPathObject(), and setPathObject().

◆ $token_instance

ilWACSignedPath::$token_instance = null
protected

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

Referenced by getTokenInstance(), and setTokenInstance().

◆ $token_max_lifetime_in_seconds

ilWACSignedPath::$token_max_lifetime_in_seconds = 3
staticprotected

◆ $type

ilWACSignedPath::$type = PathType::FILE
protected

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

Referenced by getType(), and setType().

◆ MAX_LIFETIME

const ilWACSignedPath::MAX_LIFETIME = 600

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

◆ TS_SUFFIX

const ilWACSignedPath::TS_SUFFIX = 'ts'

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

Referenced by isFolderSigned().

◆ TTL_SUFFIX

const ilWACSignedPath::TTL_SUFFIX = 'ttl'

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

Referenced by isFolderSigned().

◆ WAC_TIMESTAMP_ID

const ilWACSignedPath::WAC_TIMESTAMP_ID = 'il_wac_ts'

Definition at line 41 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 40 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 42 of file class.ilWACSignedPath.php.

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


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