ILIAS  release_8 Revision v8.24
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 (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 = 3
 
static int $cookie_max_lifetime_in_seconds = 300
 

Private Attributes

GlobalHttpState $httpService
 
CookieFactory $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 32 of file class.ilWACSignedPath.php.

Constructor & Destructor Documentation

◆ __construct()

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

ilWACSignedPath constructor.

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

54 {
55 $this->setPathObject($ilWACPath);
56 $this->httpService = $httpState;
57 $this->cookieFactory = $cookieFactory;
58 }
CookieFactory $cookieFactory
setPathObject(ilWACPath $path_object)

References $cookieFactory, and 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 332 of file class.ilWACSignedPath.php.

332 : void
333 {
334 $this->setTokenInstance($this->buildTokenInstance($timestamp, $ttl));
335 }
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 306 of file class.ilWACSignedPath.php.

307 {
308 if ($this->getType() === 0) {
310 }
311
312 switch ($this->getType()) {
313 case PathType::FOLDER:
314 $path = $this->getPathObject()->getSecurePath();
315 break;
316 default:
317 $path = $this->getPathObject()->getPathWithoutQuery();
318 break;
319 }
320
321 $client = $this->getPathObject()->getClient();
322 $timestamp = $timestamp !== 0 ? $timestamp : $this->getPathObject()->getTimestamp();
323 $ttl = $ttl !== 0 ? $ttl : $this->getPathObject()->getTTL();
324
325 return new ilWACToken($path, $client, $timestamp, $ttl);
326 }
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
$path
Definition: ltiservices.php:32

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
Exceptions

ilWACException

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

274 : bool
275 {
276 $request_token_string = $this->getPathObject()->getToken();
277 $request_ttl = $this->getPathObject()->getTTL();
278 $request_timestamp = $this->getPathObject()->getTimestamp();
279 $current_timestamp = time();
280
281 $timestamp_valid = ($current_timestamp < ($request_timestamp + $request_ttl));
282
283 if (!$timestamp_valid) {
284 $this->setChecked(true);
285
286 return false;
287 }
288
289 $simulated_token = $this->buildTokenInstance($request_timestamp, $request_ttl);
290 $simulated_token_string = $simulated_token->getToken();
291 $token_valid = ($simulated_token_string === $request_token_string);
292
293 if (!$token_valid) {
294 $this->setChecked(true);
295
296 return false;
297 }
298
299 return true;
300 }
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 354 of file class.ilWACSignedPath.php.

354 : int
355 {
357 }
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 261 of file class.ilWACSignedPath.php.

261 : ?\ilWACPath
262 {
263 return $this->path_object;
264 }
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 372 of file class.ilWACSignedPath.php.

372 : int
373 {
374 $request_ttl = $this->getPathObject()->getTTL();
375 if ($request_ttl > 0) {
376 return $request_ttl;
377 }
378 switch ($this->getType()) {
379 case PathType::FOLDER:
381 break;
382 case PathType::FILE:
384 break;
385 default:
386 $life_time = 0;
387 break;
388 }
389
390 return $life_time;
391 }
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 63 of file class.ilWACSignedPath.php.

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

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

+ Here is the call graph for this function:

◆ getTokenInstance()

ilWACSignedPath::getTokenInstance ( )

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

241 : ?\ilWACToken
242 {
244 }

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

251 : int
252 {
253 return $this->type;
254 }

References $type.

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

+ Here is the caller graph for this function:

◆ isChecked()

ilWACSignedPath::isChecked ( )

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

393 : bool
394 {
395 return $this->checked;
396 }

References $checked.

◆ isFolderSigned()

ilWACSignedPath::isFolderSigned ( )

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

89 : bool
90 {
91 $this->httpService->cookieJar();
92
93 $this->setType(PathType::FOLDER);
94 $plain_token = $this->buildTokenInstance();
95 $name = $plain_token->getHashedId();
96
97 // Token
98 $default_token = '';
99 $token_cookie_value = $this->httpService->request()->getCookieParams()[$name] ?? $default_token;
100 // Timestamp
101 $default_timestamp = 0;
102 $timestamp_cookie_value = $this->httpService->request()->getCookieParams()[$name . self::TS_SUFFIX] ?? $default_timestamp;
103 $timestamp_cookie_value = (int) $timestamp_cookie_value;
104 // TTL
105 $default_ttl = 0;
106 $ttl_cookie_value = $this->httpService->request()->getCookieParams()[$name . self::TTL_SUFFIX] ?? $default_ttl;
107 $ttl_cookie_value = (int) $ttl_cookie_value;
108
109 $this->getPathObject()->setToken($token_cookie_value);
110 $this->getPathObject()->setTimestamp($timestamp_cookie_value);
111 $this->getPathObject()->setTTL($ttl_cookie_value);
113
114 return $this->getPathObject()->hasToken();
115 }
buildAndSetTokenInstance(int $timestamp=0, int $ttl=0)
if($format !==null) $name
Definition: metadata.php:247

References $name, 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 120 of file class.ilWACSignedPath.php.

120 : bool
121 {
122 if (!$this->isFolderSigned()) {
123 return false;
124 }
125
126 return $this->checkToken();
127 }

References checkToken(), and isFolderSigned().

+ Here is the call graph for this function:

◆ isSignedPath()

ilWACSignedPath::isSignedPath ( )

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

194 : bool
195 {
196 return ($this->getPathObject()->hasToken() && $this->getPathObject()->hasTimestamp()
197 && $this->getPathObject()->hasTTL());
198 }

References getPathObject().

+ Here is the call graph for this function:

◆ isSignedPathValid()

ilWACSignedPath::isSignedPathValid ( )
Exceptions
ilWACException

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

203 : bool
204 {
205 $this->buildAndSetTokenInstance($this->getPathObject()->getTimestamp(), $this->getPathObject()->getTTL());
206
207 return $this->checkToken();
208 }

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

+ Here is the call graph for this function:

◆ revalidatingFolderToken()

ilWACSignedPath::revalidatingFolderToken ( )

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

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

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

+ Here is the call graph for this function:

◆ saveFolderToken()

ilWACSignedPath::saveFolderToken ( )
protected

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

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

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

398 : void
399 {
400 $this->checked = $checked;
401 }

References $checked.

Referenced by checkToken().

+ Here is the caller graph for this function:

◆ setCookieMaxLifetimeInSeconds()

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

ilWACException

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

364 : void
365 {
366 if ($cookie_max_lifetime_in_seconds > self::MAX_LIFETIME) {
368 }
369 self::$cookie_max_lifetime_in_seconds = $cookie_max_lifetime_in_seconds;
370 }

References $cookie_max_lifetime_in_seconds, and ilWACException\MAX_LIFETIME.

◆ setPathObject()

ilWACSignedPath::setPathObject ( ilWACPath  $path_object)

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

266 : void
267 {
268 $this->path_object = $path_object;
269 }

References $path_object.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setTokenInstance()

ilWACSignedPath::setTokenInstance ( ilWACToken  $token_instance)

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

246 : void
247 {
248 $this->token_instance = $token_instance;
249 }

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

◆ setType()

ilWACSignedPath::setType ( int  $type)

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

256 : void
257 {
258 $this->type = $type;
259 }

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

215 : string
216 {
217 global $DIC;
218 if ($path_to_file === '' || $path_to_file === '0') {
219 return '';
220 }
221 $ilWACPath = new ilWACPath($path_to_file, false);
222 if ($ilWACPath->getClient() === '' || $ilWACPath->getClient() === '0') {
223 return $path_to_file;
224 }
225 $obj = new self($ilWACPath, $DIC->http(), new CookieFactoryImpl());
226 $obj->setType(PathType::FILE);
227 $obj->buildAndSetTokenInstance(time(), self::getTokenMaxLifetimeInSeconds());
228
229 return $obj->getSignedPath();
230 }
global $DIC
Definition: feed.php:28

References $DIC, and getTokenMaxLifetimeInSeconds().

Referenced by ilCertificateSettingsFormRepository\createForm(), ilMediaCastTableGUI\fillRow(), ilMediaPoolTableGUI\fillRow(), ilPollBlockGUI\fillRow(), ilBadgeImageTemplateTableGUI\fillRow(), ilUserAvatarResolver\getAvatar(), ilPublicUserProfileGUI\getEmbeddable(), McstImageGalleryGUI\getHTML(), ilBadgeRenderer\getHTML(), ilDclMobRecordRepresentation\getHTML(), ilWACTokenTest\getModifiedSignedPath(), assImagemapQuestionGUI\getPreview(), ilPreviewGUI\getPreviewHTML(), assQuestion\getSuggestedSolutionOutput(), assImagemapQuestionGUI\getTestOutput(), ilUserAvatarFile\getUrl(), ilObjMediaObject\getXML(), ilObjPortfolioBaseGUI\initEditCustomForm(), ilObjPollGUI\initQuestionForm(), ilBadgeProfileGUI\listBadges(), ilUserCertificateGUI\listCertificates(), ilBadgeRenderer\renderModalContent(), ilObjCertificateSettingsGUI\settings(), 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 232 of file class.ilWACSignedPath.php.

232 : void
233 {
234 global $DIC;
235 $obj = new self(new ilWACPath($start_file_path, false), $DIC->http(), new CookieFactoryImpl());
236 $obj->setType(PathType::FOLDER);
237 $obj->buildAndSetTokenInstance(time(), self::getCookieMaxLifetimeInSeconds());
238 $obj->saveFolderToken();
239 }

References $DIC, and getCookieMaxLifetimeInSeconds().

Referenced by ilSCORMPresentationGUI\frameset(), ilSCORM13PlayerGUI\getPlayer(), ilExerciseManagementGUI\openSubmissionViewObject(), ilSCORM13PlayerGUI\pingSession(), ilSCORMPresentationGUI\pingSession(), ilObjFileBasedLMGUI\showLearningModule(), 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 46 of file class.ilWACSignedPath.php.

Referenced by isChecked(), and setChecked().

◆ $cookie_max_lifetime_in_seconds

int ilWACSignedPath::$cookie_max_lifetime_in_seconds = 300
staticprotected

◆ $cookieFactory

CookieFactory ilWACSignedPath::$cookieFactory
private

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

Referenced by __construct().

◆ $httpService

GlobalHttpState ilWACSignedPath::$httpService
private

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

◆ $path_object

ilWACPath ilWACSignedPath::$path_object = null
protected

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

Referenced by getPathObject(), and setPathObject().

◆ $token_instance

ilWACToken ilWACSignedPath::$token_instance = null
protected

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

Referenced by getTokenInstance(), and setTokenInstance().

◆ $token_max_lifetime_in_seconds

int ilWACSignedPath::$token_max_lifetime_in_seconds = 3
staticprotected

◆ $type

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

◆ TS_SUFFIX

const ilWACSignedPath::TS_SUFFIX = 'ts'

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

Referenced by isFolderSigned().

◆ TTL_SUFFIX

const ilWACSignedPath::TTL_SUFFIX = 'ttl'

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

Referenced by isFolderSigned().

◆ WAC_TIMESTAMP_ID

const ilWACSignedPath::WAC_TIMESTAMP_ID = 'il_wac_ts'

Definition at line 35 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 34 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 36 of file class.ilWACSignedPath.php.

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


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