ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilWACSignedPath Class Reference

Class ilWACSignedPath. More...

+ Collaboration diagram for ilWACSignedPath:

Public Member Functions

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

Static Public Member Functions

static signFile ($path_to_file)
 
static signFolderOfStartFile ($start_file_path, ilWACCookieInterface $ilWACCookieInterface=null)
 
static getTokenMaxLifetimeInSeconds ()
 
static setTokenMaxLifetimeInSeconds ($token_max_lifetime_in_seconds)
 
static getCookieMaxLifetimeInSeconds ()
 
static setCookieMaxLifetimeInSeconds ($cookie_max_lifetime_in_seconds)
 

Data Fields

const TYPE_FILE = 1
 
const TYPE_FOLDER = 2
 
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=null, $ttl=null)
 
 getRelevantLifeTime ()
 

Protected Attributes

 $path_object = null
 
 $token_instance = null
 
 $type = self::TYPE_FILE
 
 $cookie = null
 
 $checked = false
 

Static Protected Attributes

static $token_max_lifetime_in_seconds = 3
 
static $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 13 of file class.ilWACSignedPath.php.

Constructor & Destructor Documentation

◆ __construct()

ilWACSignedPath::__construct ( ilWACPath  $ilWACPath,
ilWACCookieInterface  $ilWACCookieInterface = null 
)

ilWACSignedPath constructor.

Parameters
\ilWACPath$ilWACPath
\ilWACCookieInterface | null$ilWACCookieInterface

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

References setPathObject().

59  {
60  $this->cookie = ($ilWACCookieInterface ? $ilWACCookieInterface : new ilWACCookie());
61  $this->setPathObject($ilWACPath);
62  }
setPathObject($path_object)
Class ilWACCookie.
+ Here is the call graph for this function:

Member Function Documentation

◆ buildAndSetTokenInstance()

ilWACSignedPath::buildAndSetTokenInstance (   $timestamp = null,
  $ttl = null 
)
Parameters
null$timestamp
null$ttl
Exceptions

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

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

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

325  {
326  $this->setTokenInstance($this->buildTokenInstance($timestamp, $ttl));
327  }
setTokenInstance(ilWACToken $token_instance)
buildTokenInstance($timestamp=null, $ttl=null)
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildTokenInstance()

ilWACSignedPath::buildTokenInstance (   $timestamp = null,
  $ttl = null 
)
protected
Parameters
null$timestamp
Returns
Exceptions

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

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

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

295  {
296  if (!$this->getType()) {
298  }
299 
300  switch ($this->getType()) {
301  case self::TYPE_FOLDER:
302  $path = $this->getPathObject()->getModulePath();
303  break;
304  case self::TYPE_FILE:
305  $path = $this->getPathObject()->getPathWithoutQuery();
306  break;
307  default:
308  $path = $this->getPathObject()->getPathWithoutQuery();
309  break;
310  }
311 
312  $client = $this->getPathObject()->getClient();
313  $timestamp = $timestamp ? $timestamp : $this->getPathObject()->getTimestamp();
314  $ttl = $ttl ? $ttl : $this->getPathObject()->getTTL();
315 
316  return new ilWACToken($path, $client, $timestamp, $ttl);
317  }
$path
Definition: aliased.php:25
Class ilWACException.
$client
Class ilWACToken.
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkToken()

ilWACSignedPath::checkToken ( )
protected
Returns
bool
Exceptions

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

References buildTokenInstance(), ilWACLog\getInstance(), getPathObject(), getTokenInstance(), setChecked(), and time.

Referenced by isFolderTokenValid(), and isSignedPathValid().

255  {
256  $requestTokenInstance = $this->getTokenInstance();
257 
258  $request_token = $this->getPathObject()->getToken();
259  $request_ttl = $this->getPathObject()->getTTL();
260  $request_timestamp = $this->getPathObject()->getTimestamp();
261  $current_timestamp = time();
262 
263  ilWACLog::getInstance()->write('Checking Token: ' . $request_token . ', ts: ' . $request_timestamp . "\n\n\n\n\n\n");
264 
265  $timestamp_valid = ($current_timestamp < ($request_timestamp + $request_ttl));
266 
267  if (!$timestamp_valid) {
268  ilWACLog::getInstance()->write('cookie no longer valid: TS, ' . $this->getPathObject()->getPath());
269  $this->setChecked(true);
270 
271  return false;
272  }
273 
274  $simulatedTokenInstance = $this->buildTokenInstance($request_timestamp, $request_ttl);
275  $token_valid = ($simulatedTokenInstance->getToken() == $request_token);
276 
277  if (!$token_valid) {
278  ilWACLog::getInstance()->write('cookie no longer valid: ID');
279  $this->setChecked(true);
280 
281  return false;
282  }
283 
284  ilWACLog::getInstance()->write('Token valid: ' . $requestTokenInstance->getToken());
285 
286  return true;
287  }
buildTokenInstance($timestamp=null, $ttl=null)
static getInstance()
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ 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 353 of file class.ilWACSignedPath.php.

Referenced by ilObjSCORMInitData\getIliasScormVars(), ilSCORM13Player\getPlayer(), ilWACTokenTest\testFolderToken(), and ilWACTokenTest\testFolderTokenWithSecondFile().

353  {
354  return self::$cookie_max_lifetime_in_seconds;
355  }
+ Here is the caller graph for this function:

◆ getPathObject()

ilWACSignedPath::getPathObject ( )
Returns
ilWACPath

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

References $path_object.

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

238  {
239  return $this->path_object;
240  }
+ Here is the caller graph for this function:

◆ getRelevantLifeTime()

ilWACSignedPath::getRelevantLifeTime ( )
protected
Returns
bool|int

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

References getPathObject(), and getType().

373  {
374  $request_ttl = $this->getPathObject()->getTTL();
375  if ($request_ttl > 0) {
376  return $request_ttl;
377  }
378  switch ($this->getType()) {
379  case self::TYPE_FOLDER:
380  $life_time = self::getCookieMaxLifetimeInSeconds();
381  break;
382  case self::TYPE_FILE:
383  $life_time = self::getTokenMaxLifetimeInSeconds();
384  break;
385  default:
386  $life_time = false;
387  break;
388  }
389 
390  return $life_time;
391  }
+ Here is the call graph for this function:

◆ getSignedPath()

ilWACSignedPath::getSignedPath ( )
Returns
string
Exceptions
ilWACException

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

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

69  {
70  if ($this->getType() !== self::TYPE_FILE) {
72  }
73  if (!$this->getPathObject()->getOriginalRequest()) {
74  return '';
75  }
76  if (!$this->getPathObject()->fileExists()) {
77  // return $this->getPathObject()->getOriginalRequest();
78  }
79 
80  if (strpos($this->getPathObject()->getPath(), '?')) {
81  $path = $this->getPathObject()->getPath() . '&' . self::WAC_TOKEN_ID . '=' . $this->getTokenInstance()->getToken();
82  } else {
83  $path = $this->getPathObject()->getPath() . '?' . self::WAC_TOKEN_ID . '=' . $this->getTokenInstance()->getToken();
84  }
85 
86  $path = $path . '&' . self::WAC_TTL_ID . '=' . $this->getTokenInstance()->getTTL();
87  $path = $path . '&' . self::WAC_TIMESTAMP_ID . '=' . $this->getTokenInstance()->getTimestamp();
88 
89  return $path;
90  }
$path
Definition: aliased.php:25
Class ilWACException.
+ Here is the call graph for this function:

◆ getTokenInstance()

ilWACSignedPath::getTokenInstance ( )
Returns
ilWACToken

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

References $token_instance.

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

206  {
207  return $this->token_instance;
208  }
+ Here is the caller graph for this function:

◆ getTokenMaxLifetimeInSeconds()

static ilWACSignedPath::getTokenMaxLifetimeInSeconds ( )
static
Returns
int

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

Referenced by ilWACToken\__construct(), and ilWACTokenTest\testFileToken().

333  {
334  return self::$token_max_lifetime_in_seconds;
335  }
+ Here is the caller graph for this function:

◆ getType()

ilWACSignedPath::getType ( )
Returns
int

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

References $type.

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

222  {
223  return $this->type;
224  }
+ Here is the caller graph for this function:

◆ isChecked()

ilWACSignedPath::isChecked ( )
Returns
boolean

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

References $checked.

397  {
398  return $this->checked;
399  }

◆ isFolderSigned()

ilWACSignedPath::isFolderSigned ( )
Returns
bool

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

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

Referenced by isFolderTokenValid().

96  {
97  $this->setType(self::TYPE_FOLDER);
98  $plain_token = $this->buildTokenInstance();
99  $name = $plain_token->getHashedId();
100  $this->getPathObject()->setToken($this->cookie->get($name));
101  $this->getPathObject()->setTimestamp($this->cookie->get($name . self::TS_SUFFIX));
102  $this->getPathObject()->setTTL($this->cookie->get($name . self::TTL_SUFFIX));
103  $this->buildAndSetTokenInstance();
104 
105  return $this->getPathObject()->hasToken();
106  }
buildTokenInstance($timestamp=null, $ttl=null)
buildAndSetTokenInstance($timestamp=null, $ttl=null)
+ 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 113 of file class.ilWACSignedPath.php.

References checkToken(), and isFolderSigned().

113  {
114  if (!$this->isFolderSigned()) {
115  return false;
116  }
117 
118  return $this->checkToken();
119  }
+ Here is the call graph for this function:

◆ isSignedPath()

ilWACSignedPath::isSignedPath ( )
Returns
bool

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

References getPathObject().

153  {
154  return ($this->getPathObject()->hasToken() && $this->getPathObject()->hasTimestamp() && $this->getPathObject()->hasTTL());
155  }
+ Here is the call graph for this function:

◆ isSignedPathValid()

ilWACSignedPath::isSignedPathValid ( )
Returns
bool
Exceptions
ilWACException

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

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

162  {
163  $this->buildAndSetTokenInstance($this->getPathObject()->getTimestamp(), $this->getPathObject()->getTTL());
164 
165  return $this->checkToken();
166  }
buildAndSetTokenInstance($timestamp=null, $ttl=null)
+ Here is the call graph for this function:

◆ revalidatingFolderToken()

ilWACSignedPath::revalidatingFolderToken ( )
Returns
bool

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

References buildAndSetTokenInstance(), ilWACLog\getInstance(), getType(), saveFolderToken(), and time.

138  {
139  if ($this->getType() !== self::TYPE_FOLDER) {
140  return false;
141  }
142  $this->buildAndSetTokenInstance(time(), self::getCookieMaxLifetimeInSeconds());
143  ilWACLog::getInstance()->write('revalidating folder token');
144  $this->saveFolderToken();
145 
146  return true;
147  }
static getInstance()
buildAndSetTokenInstance($timestamp=null, $ttl=null)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ Here is the call graph for this function:

◆ saveFolderToken()

ilWACSignedPath::saveFolderToken ( )
protected

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

References ilWACLog\getInstance(), getPathObject(), getTokenInstance(), and time.

Referenced by revalidatingFolderToken().

122  {
123  $cookie_lifetime = self::getCookieMaxLifetimeInSeconds();
124  $str = 'save folder token for folder: ' . $this->getPathObject()->getDirName() . ', valid for ' . $cookie_lifetime . 's';
125  ilWACLog::getInstance()->write($str);
126  ilWACLog::getInstance()->write('token: ' . $this->getTokenInstance()->getToken());
127  $id = $this->getTokenInstance()->getHashedId();
128  $expire = time() + $cookie_lifetime;
129  $this->cookie->set($id, $this->getTokenInstance()->getToken(), time() + 24 * 3600, '/', null, false, false);
130  $this->cookie->set($id . self::TS_SUFFIX, time(), $expire, '/', '', false, false);
131  $this->cookie->set($id . self::TTL_SUFFIX, self::getCookieMaxLifetimeInSeconds(), $expire, '/', '', false, false);
132  }
static getInstance()
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setChecked()

ilWACSignedPath::setChecked (   $checked)
Parameters
boolean$checked

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

References $checked.

Referenced by checkToken().

405  {
406  $this->checked = $checked;
407  }
+ Here is the caller graph for this function:

◆ setCookieMaxLifetimeInSeconds()

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

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

References $cookie_max_lifetime_in_seconds, and ilWACException\MAX_LIFETIME.

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

362  {
363  if ($cookie_max_lifetime_in_seconds > self::MAX_LIFETIME) {
365  }
366  self::$cookie_max_lifetime_in_seconds = $cookie_max_lifetime_in_seconds;
367  }
Class ilWACException.
static $cookie_max_lifetime_in_seconds
+ Here is the caller graph for this function:

◆ setPathObject()

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

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

References $path_object.

Referenced by __construct().

246  {
247  $this->path_object = $path_object;
248  }
+ Here is the caller graph for this function:

◆ setTokenInstance()

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

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

References $token_instance.

Referenced by buildAndSetTokenInstance().

214  {
215  $this->token_instance = $token_instance;
216  }
+ 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

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

References $type.

Referenced by isFolderSigned().

230  {
231  $this->type = $type;
232  }
+ Here is the caller graph for this function:

◆ signFile()

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

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

References time.

Referenced by ilObjUser\_getPersonalPicturePath(), ilRTE\_replaceMediaObjectImageSrc(), ilCertificateGUI\certificateEditor(), ilMediaCastTableGUI\fillRow(), ilPollBlockGUI\fillRow(), ilObjStyleSheet\getContentStylePath(), ilOnScreenChatGUI\getEmoticons(), ilDclMobRecordRepresentation\getHTML(), ilWACTokenTest\getModifiedSignedPath(), assImagemapQuestionGUI\getPreview(), ilPreviewGUI\getPreviewHTML(), assMatchingQuestionGUI\getSolutionOutput(), assImagemapQuestionGUI\getSolutionOutput(), assQuestion\getSuggestedSolutionOutput(), assImagemapQuestionGUI\getTestOutput(), ilObjPortfolioBaseGUI\renderFullscreenHeader(), ilObjBlogGUI\renderFullscreenHeader(), ilObjCertificateSettingsGUI\settings(), ilObjMediaCastGUI\showGallery(), ilWACCheckingInstanceTest\testBasicWithFileSigning(), and ilWACTokenTest\testFileToken().

175  {
176  if (!$path_to_file) {
177  return '';
178  }
179  $ilWACPath = new ilWACPath($path_to_file);
180  if (!$ilWACPath->getClient()) {
181  return $path_to_file;
182  }
183  $obj = new self($ilWACPath);
184  $obj->setType(self::TYPE_FILE);
185  $obj->buildAndSetTokenInstance(time(), self::getTokenMaxLifetimeInSeconds());
186 
187  return $obj->getSignedPath();
188  }
Class ilWACPath.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ Here is the caller graph for this function:

◆ signFolderOfStartFile()

static ilWACSignedPath::signFolderOfStartFile (   $start_file_path,
ilWACCookieInterface  $ilWACCookieInterface = null 
)
static
Parameters
$start_file_path
\ilWACCookieInterface | null$ilWACCookieInterface

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

References time.

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

195  {
196  $obj = new self(new ilWACPath($start_file_path), $ilWACCookieInterface);
197  $obj->setType(self::TYPE_FOLDER);
198  $obj->buildAndSetTokenInstance(time(), self::getCookieMaxLifetimeInSeconds());
199  $obj->saveFolderToken();
200  }
Class ilWACPath.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ Here is the caller graph for this function:

Field Documentation

◆ $checked

ilWACSignedPath::$checked = false
protected

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

Referenced by isChecked(), and setChecked().

◆ $cookie

ilWACSignedPath::$cookie = null
protected

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

◆ $cookie_max_lifetime_in_seconds

ilWACSignedPath::$cookie_max_lifetime_in_seconds = 300
staticprotected

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

Referenced by setCookieMaxLifetimeInSeconds().

◆ $path_object

ilWACSignedPath::$path_object = null
protected

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

Referenced by getPathObject(), and setPathObject().

◆ $token_instance

ilWACSignedPath::$token_instance = null
protected

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

Referenced by getTokenInstance(), and setTokenInstance().

◆ $token_max_lifetime_in_seconds

ilWACSignedPath::$token_max_lifetime_in_seconds = 3
staticprotected

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

Referenced by setTokenMaxLifetimeInSeconds().

◆ $type

ilWACSignedPath::$type = self::TYPE_FILE
protected

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

Referenced by getType(), and setType().

◆ MAX_LIFETIME

const ilWACSignedPath::MAX_LIFETIME = 600

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

◆ TS_SUFFIX

const ilWACSignedPath::TS_SUFFIX = 'ts'

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

◆ TTL_SUFFIX

const ilWACSignedPath::TTL_SUFFIX = 'ttl'

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

◆ TYPE_FILE

const ilWACSignedPath::TYPE_FILE = 1

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

◆ TYPE_FOLDER

const ilWACSignedPath::TYPE_FOLDER = 2

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

◆ WAC_TIMESTAMP_ID

const ilWACSignedPath::WAC_TIMESTAMP_ID = 'il_wac_ts'

Definition at line 18 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 17 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 19 of file class.ilWACSignedPath.php.

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


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