ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 23 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 73 of file class.ilWACSignedPath.php.

74 {
75 $this->setPathObject($ilWACPath);
76 $this->httpService = $httpState;
77 $this->cookieFactory = $cookieFactory;
78 }
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 395 of file class.ilWACSignedPath.php.

396 {
397 assert(is_int($timestamp));
398 assert(is_int($ttl));
399
400 $this->setTokenInstance($this->buildTokenInstance($timestamp, $ttl));
401 }
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 360 of file class.ilWACSignedPath.php.

361 {
362 assert(is_int($timestamp));
363 assert(is_int($ttl));
364 if (!$this->getType()) {
366 }
367
368 switch ($this->getType()) {
369 case PathType::FOLDER:
370 $path = $this->getPathObject()->getModulePath();
371 break;
372 case PathType::FILE:
373 $path = $this->getPathObject()->getPathWithoutQuery();
374 break;
375 default:
376 $path = $this->getPathObject()->getPathWithoutQuery();
377 break;
378 }
379
380 $client = $this->getPathObject()->getClient();
381 $timestamp = $timestamp ? $timestamp : $this->getPathObject()->getTimestamp();
382 $ttl = $ttl ? $ttl : $this->getPathObject()->getTTL();
383
384 return new ilWACToken($path, $client, $timestamp, $ttl);
385 }
$client
Definition: resume.php:9
Class ilWACException.
Class ilWACToken.

References $client, $path, $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 325 of file class.ilWACSignedPath.php.

326 {
327 $request_token = $this->getPathObject()->getToken();
328 $request_ttl = $this->getPathObject()->getTTL();
329 $request_timestamp = $this->getPathObject()->getTimestamp();
330 $current_timestamp = time();
331
332 $timestamp_valid = ($current_timestamp < ($request_timestamp + $request_ttl));
333
334 if (!$timestamp_valid) {
335 $this->setChecked(true);
336
337 return false;
338 }
339
340 $simulatedTokenInstance = $this->buildTokenInstance($request_timestamp, $request_ttl);
341 $token_valid = ($simulatedTokenInstance->getToken() == $request_token);
342
343 if (!$token_valid) {
344 $this->setChecked(true);
345
346 return false;
347 }
348
349 return true;
350 }

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

◆ getPathObject()

ilWACSignedPath::getPathObject ( )
Returns
ilWACPath

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

306 {
307 return $this->path_object;
308 }

References $path_object.

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

+ Here is the caller graph for this function:

◆ getRelevantLifeTime()

ilWACSignedPath::getRelevantLifeTime ( )
protected
Returns
int

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

459 {
460 $request_ttl = $this->getPathObject()->getTTL();
461 if ($request_ttl > 0) {
462 return $request_ttl;
463 }
464 switch ($this->getType()) {
465 case PathType::FOLDER:
467 break;
468 case PathType::FILE:
470 break;
471 default:
472 $life_time = 0;
473 break;
474 }
475
476 return $life_time;
477 }
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 85 of file class.ilWACSignedPath.php.

86 {
87 if ($this->getType() !== PathType::FILE) {
89 }
90 if (!$this->getPathObject()->getOriginalRequest()) {
91 return '';
92 }
93 if (!$this->getPathObject()->fileExists()) {
94 // return $this->getPathObject()->getOriginalRequest();
95 }
96
97 if (strpos($this->getPathObject()->getPath(), '?')) {
98 $path = $this->getPathObject()->getPath() . '&' . self::WAC_TOKEN_ID . '='
99 . $this->getTokenInstance()->getToken();
100 } else {
101 $path = $this->getPathObject()->getPath() . '?' . self::WAC_TOKEN_ID . '='
102 . $this->getTokenInstance()->getToken();
103 }
104
105 $path = $path . '&' . self::WAC_TTL_ID . '=' . $this->getTokenInstance()->getTTL();
106 $path = $path . '&' . self::WAC_TIMESTAMP_ID . '='
107 . $this->getTokenInstance()->getTimestamp();
108
109 return $path;
110 }

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

+ Here is the call graph for this function:

◆ getTokenInstance()

ilWACSignedPath::getTokenInstance ( )
Returns
ilWACToken

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

267 {
269 }

References $token_instance.

Referenced by getSignedPath(), and saveFolderToken().

+ Here is the caller graph for this function:

◆ getTokenMaxLifetimeInSeconds()

static ilWACSignedPath::getTokenMaxLifetimeInSeconds ( )
static
Returns
int

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

408 {
410 }

References $token_max_lifetime_in_seconds.

Referenced by ilWACToken\__construct(), ilOnScreenChatUserDataProvider\getDataByUserIds(), getRelevantLifeTime(), signFile(), and ilWACTokenTest\testFileToken().

+ Here is the caller graph for this function:

◆ getType()

ilWACSignedPath::getType ( )
Returns
int

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

286 {
287 return (int) $this->type;
288 }

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

484 {
485 return (bool) $this->checked;
486 }

References $checked.

◆ isFolderSigned()

ilWACSignedPath::isFolderSigned ( )
Returns
bool

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

117 {
118 $cookieJar = $this->httpService->cookieJar();
119
120 $this->setType(PathType::FOLDER);
121 $plain_token = $this->buildTokenInstance();
122 $name = $plain_token->getHashedId();
123
124 $tokenCookie = $cookieJar->get($name);
125 $timestampCookie = $cookieJar->get($name . self::TS_SUFFIX);
126 $ttlCookie = $cookieJar->get($name . self::TTL_SUFFIX);
127
128 $defaultToken = '';
129 $tokenCookieValue = is_null($tokenCookie) ? $defaultToken : is_a($tokenCookie->getValue(), Cookie::class) ? $tokenCookie->getValue() : $defaultToken;
130
131 $defaultTimestamp = 0;
132 $timestampCookieValue = is_null($timestampCookie) ? $defaultTimestamp : is_a($timestampCookie->getValue(), Cookie::class) ? $timestampCookie->getValue() : $defaultTimestamp;
133 $timestampCookieValue = intval($timestampCookieValue);
134
135 $defaultTtl = 0;
136 $ttlCookieValue = is_null($ttlCookie) ? $defaultTtl : is_a($ttlCookie->getValue(), Cookie::class) ? $ttlCookie->getValue() : $defaultTtl;
137 $ttlCookieValue = intval($ttlCookieValue);
138
139 $this->getPathObject()->setToken($tokenCookieValue);
140 $this->getPathObject()->setTimestamp($timestampCookieValue);
141 $this->getPathObject()->setTTL($ttlCookieValue);
143
144 return $this->getPathObject()->hasToken();
145 }
buildAndSetTokenInstance($timestamp=0, $ttl=0)
if($format !==null) $name
Definition: metadata.php:146

References $name, buildAndSetTokenInstance(), buildTokenInstance(), getPathObject(), and setType().

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

153 {
154 if (!$this->isFolderSigned()) {
155 return false;
156 }
157
158 return $this->checkToken();
159 }

References checkToken(), and isFolderSigned().

+ Here is the call graph for this function:

◆ isSignedPath()

ilWACSignedPath::isSignedPath ( )
Returns
bool

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

208 {
209 return ($this->getPathObject()->hasToken() && $this->getPathObject()->hasTimestamp()
210 && $this->getPathObject()->hasTTL());
211 }

References getPathObject().

+ Here is the call graph for this function:

◆ isSignedPathValid()

ilWACSignedPath::isSignedPathValid ( )
Returns
bool
Exceptions
ilWACException

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

219 {
220 $this->buildAndSetTokenInstance($this->getPathObject()->getTimestamp(), $this->getPathObject()->getTTL());
221
222 return $this->checkToken();
223 }

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

+ Here is the call graph for this function:

◆ revalidatingFolderToken()

ilWACSignedPath::revalidatingFolderToken ( )
Returns
bool

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

193 {
194 if ($this->getType() !== PathType::FOLDER) {
195 return false;
196 }
197 $this->buildAndSetTokenInstance(time(), self::getCookieMaxLifetimeInSeconds());
198 $this->saveFolderToken();
199
200 return true;
201 }

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

+ Here is the call graph for this function:

◆ saveFolderToken()

ilWACSignedPath::saveFolderToken ( )
protected
Returns
void

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

166 {
167 $cookie_lifetime = self::getCookieMaxLifetimeInSeconds();
168 //$str = 'save folder token for folder: ' . $this->getPathObject()->getDirName() . ', valid for ' . $cookie_lifetime . 's';
169 $id = $this->getTokenInstance()->getHashedId();
170 $expire = time() + $cookie_lifetime;
171
172 $tokenCookie = $this->cookieFactory->create($id, $this->getTokenInstance()->getToken())->withExpires(time()
173 + 24
174 * 3600)->withPath('/')->withSecure(false)->withDomain(null)->withSecure(false)->withHttpOnly(false);
175
176 $timestampCookie = $this->cookieFactory->create($id
177 . self::TS_SUFFIX, time())->withExpires($expire)->withPath('/')->withDomain(null)->withSecure(false)->withHttpOnly(false);
178
179 $ttlCookie = $this->cookieFactory->create($id
180 . self::TTL_SUFFIX, self::getCookieMaxLifetimeInSeconds())->withExpires($expire)->withPath('/')->withDomain(null)->withSecure(false)->withHttpOnly(false);
181
182 $cookieJar = $this->httpService->cookieJar();
183 $response = $cookieJar->with($tokenCookie)->with($timestampCookie)->with($ttlCookie)->renderIntoResponseHeader($this->httpService->response());
184
185 $this->httpService->saveResponse($response);
186 }
if(!array_key_exists('StateId', $_REQUEST)) $id
$expire
Definition: saml2-acs.php:140
$response

References $expire, $id, $response, getCookieMaxLifetimeInSeconds(), 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 493 of file class.ilWACSignedPath.php.

494 {
495 assert(is_bool($checked));
496 $this->checked = $checked;
497 }

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

446 {
447 assert(is_int($cookie_max_lifetime_in_seconds));
448 if ($cookie_max_lifetime_in_seconds > self::MAX_LIFETIME) {
450 }
451 self::$cookie_max_lifetime_in_seconds = $cookie_max_lifetime_in_seconds;
452 }

References $cookie_max_lifetime_in_seconds, and ilWACException\MAX_LIFETIME.

Referenced by ilWACTokenTest\testFolderToken(), and ilWACTokenTest\testFolderTokenWithSecondFile().

+ Here is the caller graph for this function:

◆ setPathObject()

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

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

316 {
317 $this->path_object = $path_object;
318 }

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

277 {
278 $this->token_instance = $token_instance;
279 }

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

296 {
297 assert(is_int($type));
298 $this->type = $type;
299 }

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

234 {
235 if (!$path_to_file) {
236 return '';
237 }
238 $ilWACPath = new ilWACPath($path_to_file);
239 if (!$ilWACPath->getClient()) {
240 return $path_to_file;
241 }
242 $obj = new self($ilWACPath, self::http(), new CookieFactoryImpl());
243 $obj->setType(PathType::FILE);
244 $obj->buildAndSetTokenInstance(time(), self::getTokenMaxLifetimeInSeconds());
245
246 return $obj->getSignedPath();
247 }
Class ilWACPath.
static http()
Fetches the global http state from ILIAS.

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

Referenced by ilRTE\_replaceMediaObjectImageSrc(), ilCertificateGUI\certificateEditor(), ilPollBlockGUI\fillRow(), ilMediaCastTableGUI\fillRow(), ilObjStyleSheet\getContentStylePath(), ilDclMobRecordRepresentation\getHTML(), ilWACTokenTest\getModifiedSignedPath(), assImagemapQuestionGUI\getPreview(), ilPreviewGUI\getPreviewHTML(), assImagemapQuestionGUI\getSolutionOutput(), assMatchingQuestionGUI\getSolutionOutput(), assQuestion\getSuggestedSolutionOutput(), assImagemapQuestionGUI\getTestOutput(), ilObjMediaObject\getXML(), 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 254 of file class.ilWACSignedPath.php.

255 {
256 $obj = new self(new ilWACPath($start_file_path), self::http(), new CookieFactoryImpl());
257 $obj->setType(PathType::FOLDER);
258 $obj->buildAndSetTokenInstance(time(), self::getCookieMaxLifetimeInSeconds());
259 $obj->saveFolderToken();
260 }

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

Referenced by ilSCORMPresentationGUI\frameset(), ilSCORM13Player\getPlayer(), ilSCORM13Player\pingSession(), ilSCORMPresentationGUI\pingSession(), ilObjMediaCastGUI\showGallery(), ilObjFileBasedLMGUI\showLearningModule(), ilWACCheckingInstanceTest\testBasicWithFolderSigning(), ilWACTokenTest\testCookieGeneration(), ilWACTokenTest\testFolderToken(), and ilWACTokenTest\testFolderTokenWithSecondFile().

+ 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 55 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 63 of file class.ilWACSignedPath.php.

Referenced by __construct().

◆ $httpService

ILIAS DI HTTPServices ilWACSignedPath::$httpService
private

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

◆ $path_object

ilWACSignedPath::$path_object = null
protected

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

Referenced by getPathObject(), and setPathObject().

◆ $token_instance

ilWACSignedPath::$token_instance = null
protected

Definition at line 39 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 43 of file class.ilWACSignedPath.php.

Referenced by getType(), and setType().

◆ MAX_LIFETIME

const ilWACSignedPath::MAX_LIFETIME = 600

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

◆ TS_SUFFIX

const ilWACSignedPath::TS_SUFFIX = 'ts'

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

◆ TTL_SUFFIX

const ilWACSignedPath::TTL_SUFFIX = 'ttl'

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

◆ WAC_TIMESTAMP_ID

const ilWACSignedPath::WAC_TIMESTAMP_ID = 'il_wac_ts'

Definition at line 27 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 26 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 28 of file class.ilWACSignedPath.php.

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


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