ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilWebAccessChecker Class Reference

Class ilWebAccessChecker. More...

+ Collaboration diagram for ilWebAccessChecker:

Public Member Functions

 __construct (Services $httpState, private CookieFactory $cookieFactory)
 ilWebAccessChecker constructor. More...
 
 check ()
 
 initILIAS ()
 
 isChecked ()
 
 setChecked (bool $checked)
 
 getPathObject ()
 
 setPathObject (ilWACPath $path_object)
 
 getDisposition ()
 
 setDisposition (string $disposition)
 
 getOverrideMimetype ()
 
 setOverrideMimetype (string $override_mimetype)
 
 isInitialized ()
 
 setInitialized (bool $initialized)
 
 isSendStatusCode ()
 
 setSendStatusCode (bool $send_status_code)
 
 isRevalidateFolderTokens ()
 
 setRevalidateFolderTokens (bool $revalidate_folder_tokens)
 
 getAppliedCheckingMethods ()
 
 setAppliedCheckingMethods (array $applied_checking_methods)
 

Static Public Member Functions

static isUseSeperateLogfile ()
 
static setUseSeperateLogfile (bool $use_seperate_logfile)
 

Data Fields

const DISPOSITION = 'disposition'
 
const STATUS_CODE = 'status_code'
 
const REVALIDATE = 'revalidate'
 
const CM_FILE_TOKEN = 1
 
const CM_FOLDER_TOKEN = 2
 
const CM_CHECKINGINSTANCE = 3
 
const CM_SECFOLDER = 4
 

Protected Member Functions

 sendHeader (string $message)
 
 checkPublicSection ()
 
 checkUser ()
 
 addAppliedCheckingMethod (int $method)
 

Protected Attributes

ilWACPath $path_object = null
 
bool $checked = false
 
string $disposition = ilFileDelivery::DISP_INLINE
 
string $override_mimetype = ''
 
bool $send_status_code = false
 
bool $initialized = false
 
bool $revalidate_folder_tokens = true
 
array $applied_checking_methods = []
 

Static Protected Attributes

static bool $use_seperate_logfile = false
 

Private Attributes

Services $http
 
ilWACException $ressource_not_found = null
 

Detailed Description

Class ilWebAccessChecker.

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.ilWebAccessChecker.php.

Constructor & Destructor Documentation

◆ __construct()

ilWebAccessChecker::__construct ( Services  $httpState,
private CookieFactory  $cookieFactory 
)

ilWebAccessChecker constructor.

Definition at line 58 of file class.ilWebAccessChecker.php.

References Vendor\Package\$e, ILIAS\FileDelivery\http(), ilWACException\NOT_FOUND, ILIAS\HTTP\Services\request(), and setPathObject().

59  {
60  try {
61  $this->setPathObject(new ilWACPath($httpState->request()->getRequestTarget()));
62  } catch (ilWACException $e) {
63  if ($e->getCode() !== ilWACException::NOT_FOUND) {
64  throw $e;
65  }
66  $this->ressource_not_found = $e;
67  }
68 
69  $this->http = $httpState;
70  }
setPathObject(ilWACPath $path_object)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

Member Function Documentation

◆ addAppliedCheckingMethod()

ilWebAccessChecker::addAppliedCheckingMethod ( int  $method)
protected

Definition at line 334 of file class.ilWebAccessChecker.php.

References $DIC, ANONYMOUS_USER_ID, ilContext\CONTEXT_WAC, ilContext\init(), and ilInitialisation\reInitUser().

Referenced by check().

334  : void
335  {
336  $this->applied_checking_methods[] = $method;
337  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check()

ilWebAccessChecker::check ( )
Exceptions
ilWACException

Definition at line 75 of file class.ilWebAccessChecker.php.

References $data_dir, $path, addAppliedCheckingMethod(), CLIENT_WEB_DIR, ilWACException\CODE_NO_PATH, getPathObject(), ilWACSecurePath\hasCheckingInstanceRegistered(), ILIAS\FileDelivery\http(), initILIAS(), isRevalidateFolderTokens(), ilWACException\NOT_FOUND, sendHeader(), and setChecked().

75  : bool
76  {
77  if (!$this->getPathObject() instanceof \ilWACPath) {
78  if ($this->ressource_not_found instanceof \ilWACException) {
79  throw new ilWACException(ilWACException::NOT_FOUND, '', $this->ressource_not_found);
80  }
81 
82  throw new ilWACException(ilWACException::CODE_NO_PATH);
83  }
84 
85  // Check if Path has been signed with a token
86  $ilWACSignedPath = new ilWACSignedPath($this->getPathObject(), $this->http, $this->cookieFactory);
87  if ($ilWACSignedPath->isSignedPath()) {
88  $this->addAppliedCheckingMethod(self::CM_FILE_TOKEN);
89  if ($ilWACSignedPath->isSignedPathValid()) {
90  $this->setChecked(true);
91  $this->sendHeader('checked using token');
92 
93  return true;
94  }
95  }
96 
97  // Check if the whole secured folder has been signed
98  if ($ilWACSignedPath->isFolderSigned()) {
99  $this->addAppliedCheckingMethod(self::CM_FOLDER_TOKEN);
100  if ($ilWACSignedPath->isFolderTokenValid()) {
101  if ($this->isRevalidateFolderTokens()) {
102  $ilWACSignedPath->revalidatingFolderToken();
103  }
104  $this->setChecked(true);
105  $this->sendHeader('checked using secure folder');
106 
107  return true;
108  }
109  }
110 
111  // Fallback, have to initiate ILIAS
112  $this->initILIAS();
113 
114  // Check if Path is within accepted paths
115  if ($this->getPathObject()->getModuleType() !== 'rs') {
116  $clean_path = $this->getPathObject()->getCleanURLdecodedPath();
117  $path = realpath($clean_path);
118  $data_dir = realpath(CLIENT_WEB_DIR);
119  if (!str_starts_with($path, $data_dir)) {
120  return false;
121  }
122  if (dirname($path) === $data_dir && is_file($path)) {
123  return false;
124  }
125  }
126 
128  // Maybe the path has been registered, lets check
129  $checkingInstance = ilWACSecurePath::getCheckingInstance($this->getPathObject());
130  $this->addAppliedCheckingMethod(self::CM_CHECKINGINSTANCE);
131  $canBeDelivered = $checkingInstance->canBeDelivered($this->getPathObject());
132  if ($canBeDelivered) {
133  $this->sendHeader('checked using fallback');
134  if ($ilWACSignedPath->isFolderSigned() && $this->isRevalidateFolderTokens()) {
135  $ilWACSignedPath->revalidatingFolderToken();
136  }
137  }
138  $this->setChecked(true);
139  return $canBeDelivered;
140  }
141 
142  // none of the checking mechanisms could have been applied. no access
143  $this->setChecked(true);
144  $this->addAppliedCheckingMethod(self::CM_SECFOLDER);
145  return !$this->getPathObject()->isInSecFolder();
146  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:32
static http()
Fetches the global http state from ILIAS.
const CLIENT_WEB_DIR
Definition: constants.php:47
static hasCheckingInstanceRegistered(ilWACPath $ilWACPath)
Searches a checking instance for the given wac path.
+ Here is the call graph for this function:

◆ checkPublicSection()

ilWebAccessChecker::checkPublicSection ( )
protected
Exceptions
ilWACException

Definition at line 204 of file class.ilWebAccessChecker.php.

References $DIC, ilWACException\ACCESS_DENIED_NO_PUB, ANONYMOUS_USER_ID, and ILIAS\Repository\int().

Referenced by initILIAS().

204  : void
205  {
206  global $DIC;
207  $is_anonymous = ((int) $DIC->user()->getId() === (int) ANONYMOUS_USER_ID);
208  $is_null_user = ($DIC->user()->getId() === 0);
209  $pub_section_activated = (bool) $DIC['ilSetting']->get('pub_section');
210  $isset = isset($DIC['ilSetting']);
211  $instanceof = $DIC['ilSetting'] instanceof ilSetting;
212 
213  if (!$isset || !$instanceof) {
215  }
216 
217  if ($pub_section_activated && ($is_null_user || $is_anonymous)) {
218  // Request is initiated from an enabled public area
219  return;
220  }
221 
222  if ($is_anonymous || $is_null_user) {
224  }
225  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkUser()

ilWebAccessChecker::checkUser ( )
protected

Definition at line 227 of file class.ilWebAccessChecker.php.

References $DIC, ilWACException\ACCESS_DENIED_NO_LOGIN, and ILIAS\Repository\int().

Referenced by initILIAS().

227  : void
228  {
229  global $DIC;
230 
231  $is_user = $DIC->user() instanceof ilObjUser;
232  $user_id_is_zero = ((int) $DIC->user()->getId() === 0);
233  if (!$is_user || $user_id_is_zero) {
235  }
236  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAppliedCheckingMethods()

ilWebAccessChecker::getAppliedCheckingMethods ( )
Returns
int[]

Definition at line 321 of file class.ilWebAccessChecker.php.

References $applied_checking_methods.

321  : array
322  {
324  }

◆ getDisposition()

ilWebAccessChecker::getDisposition ( )

Definition at line 258 of file class.ilWebAccessChecker.php.

References $disposition.

258  : string
259  {
260  return $this->disposition;
261  }

◆ getOverrideMimetype()

ilWebAccessChecker::getOverrideMimetype ( )

Definition at line 268 of file class.ilWebAccessChecker.php.

References $override_mimetype.

268  : string
269  {
271  }

◆ getPathObject()

ilWebAccessChecker::getPathObject ( )

Definition at line 248 of file class.ilWebAccessChecker.php.

References $path_object.

Referenced by check(), and initILIAS().

248  : ?\ilWACPath
249  {
250  return $this->path_object;
251  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the caller graph for this function:

◆ initILIAS()

ilWebAccessChecker::initILIAS ( )

Definition at line 154 of file class.ilWebAccessChecker.php.

References $DIC, Vendor\Package\$e, $GLOBALS, $response, ilWACException\ACCESS_DENIED_NO_LOGIN, ANONYMOUS_USER_ID, checkPublicSection(), checkUser(), ilContext\CONTEXT_WAC, getPathObject(), ILIAS\FileDelivery\http(), ilContext\init(), ilInitialisation\initILIAS(), isInitialized(), and setInitialized().

Referenced by check().

154  : void
155  {
156  global $DIC;
157 
158  if ($this->isInitialized()) {
159  return;
160  }
161 
162  $GLOBALS['COOKIE_PATH'] = '/';
163 
164  $cookie = $this->cookieFactory->create('ilClientId', $this->getPathObject()->getClient())
165  ->withPath('/')
166  ->withExpires(0);
167 
168  $response = $this->http->cookieJar()
169  ->with($cookie)
170  ->renderIntoResponseHeader($this->http->response());
171 
172  $this->http->saveResponse($response);
173 
175  try {
177  $this->checkUser();
178  $this->checkPublicSection();
179  } catch (Exception $e) {
180  if ($e instanceof ilWACException
181  && $e->getCode() !== ilWACException::ACCESS_DENIED_NO_LOGIN) {
182  throw $e;
183  }
184  if (($e instanceof Exception && $e->getMessage() === 'Authentication failed.')
185  || $e->getCode() === ilWACException::ACCESS_DENIED_NO_LOGIN) {
186  $this->initAnonymousSession();
187  $this->checkUser();
188  $this->checkPublicSection();
189  }
190  }
191  $this->setInitialized(true);
192 
193  // This workaround is needed because these issues:
194  // https://mantis.ilias.de/view.php?id=32284 and
195  // https://mantis.ilias.de/view.php?id=32063
196  if ($DIC->user()->getId() === 0) {
197  $DIC->user()->setId(ANONYMOUS_USER_ID);
198  }
199  }
const CONTEXT_WAC
const ANONYMOUS_USER_ID
Definition: constants.php:27
$response
Definition: xapitoken.php:93
setInitialized(bool $initialized)
global $DIC
Definition: feed.php:28
static initILIAS()
ilias initialisation
static http()
Fetches the global http state from ILIAS.
$GLOBALS["DIC"]
Definition: wac.php:31
static init(string $a_type)
Init context by type.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isChecked()

ilWebAccessChecker::isChecked ( )

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

References $checked.

238  : bool
239  {
240  return $this->checked;
241  }

◆ isInitialized()

ilWebAccessChecker::isInitialized ( )

Definition at line 278 of file class.ilWebAccessChecker.php.

References $initialized.

Referenced by initILIAS().

278  : bool
279  {
280  return $this->initialized;
281  }
+ Here is the caller graph for this function:

◆ isRevalidateFolderTokens()

ilWebAccessChecker::isRevalidateFolderTokens ( )

Definition at line 298 of file class.ilWebAccessChecker.php.

References $revalidate_folder_tokens.

Referenced by check().

298  : bool
299  {
301  }
+ Here is the caller graph for this function:

◆ isSendStatusCode()

ilWebAccessChecker::isSendStatusCode ( )

Definition at line 288 of file class.ilWebAccessChecker.php.

References $send_status_code.

288  : bool
289  {
291  }

◆ isUseSeperateLogfile()

static ilWebAccessChecker::isUseSeperateLogfile ( )
static

Definition at line 308 of file class.ilWebAccessChecker.php.

308  : bool
309  {
310  return self::$use_seperate_logfile;
311  }

◆ sendHeader()

ilWebAccessChecker::sendHeader ( string  $message)
protected

Definition at line 148 of file class.ilWebAccessChecker.php.

References $response, and ILIAS\FileDelivery\http().

Referenced by check().

148  : void
149  {
150  $response = $this->http->response()->withHeader('X-ILIAS-WebAccessChecker', $message);
151  $this->http->saveResponse($response);
152  }
$response
Definition: xapitoken.php:93
static http()
Fetches the global http state from ILIAS.
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAppliedCheckingMethods()

ilWebAccessChecker::setAppliedCheckingMethods ( array  $applied_checking_methods)
Parameters
int[]$applied_checking_methods

Definition at line 329 of file class.ilWebAccessChecker.php.

References $applied_checking_methods.

329  : void
330  {
331  $this->applied_checking_methods = $applied_checking_methods;
332  }

◆ setChecked()

ilWebAccessChecker::setChecked ( bool  $checked)

Definition at line 243 of file class.ilWebAccessChecker.php.

References $checked.

Referenced by check().

243  : void
244  {
245  $this->checked = $checked;
246  }
+ Here is the caller graph for this function:

◆ setDisposition()

ilWebAccessChecker::setDisposition ( string  $disposition)

Definition at line 263 of file class.ilWebAccessChecker.php.

References $disposition.

263  : void
264  {
265  $this->disposition = $disposition;
266  }

◆ setInitialized()

ilWebAccessChecker::setInitialized ( bool  $initialized)

Definition at line 283 of file class.ilWebAccessChecker.php.

References $initialized.

Referenced by initILIAS().

283  : void
284  {
285  $this->initialized = $initialized;
286  }
+ Here is the caller graph for this function:

◆ setOverrideMimetype()

ilWebAccessChecker::setOverrideMimetype ( string  $override_mimetype)

Definition at line 273 of file class.ilWebAccessChecker.php.

References $override_mimetype.

273  : void
274  {
275  $this->override_mimetype = $override_mimetype;
276  }

◆ setPathObject()

ilWebAccessChecker::setPathObject ( ilWACPath  $path_object)

Definition at line 253 of file class.ilWebAccessChecker.php.

References $path_object.

Referenced by __construct().

253  : void
254  {
255  $this->path_object = $path_object;
256  }
+ Here is the caller graph for this function:

◆ setRevalidateFolderTokens()

ilWebAccessChecker::setRevalidateFolderTokens ( bool  $revalidate_folder_tokens)

Definition at line 303 of file class.ilWebAccessChecker.php.

References $revalidate_folder_tokens.

303  : void
304  {
305  $this->revalidate_folder_tokens = $revalidate_folder_tokens;
306  }

◆ setSendStatusCode()

ilWebAccessChecker::setSendStatusCode ( bool  $send_status_code)

Definition at line 293 of file class.ilWebAccessChecker.php.

References $send_status_code.

293  : void
294  {
295  $this->send_status_code = $send_status_code;
296  }

◆ setUseSeperateLogfile()

static ilWebAccessChecker::setUseSeperateLogfile ( bool  $use_seperate_logfile)
static

Definition at line 313 of file class.ilWebAccessChecker.php.

References $use_seperate_logfile.

313  : void
314  {
315  self::$use_seperate_logfile = $use_seperate_logfile;
316  }

Field Documentation

◆ $applied_checking_methods

array ilWebAccessChecker::$applied_checking_methods = []
protected

◆ $checked

bool ilWebAccessChecker::$checked = false
protected

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

Referenced by isChecked(), and setChecked().

◆ $disposition

string ilWebAccessChecker::$disposition = ilFileDelivery::DISP_INLINE
protected

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

Referenced by getDisposition(), and setDisposition().

◆ $http

Services ilWebAccessChecker::$http
private

Definition at line 52 of file class.ilWebAccessChecker.php.

◆ $initialized

bool ilWebAccessChecker::$initialized = false
protected

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

Referenced by isInitialized(), and setInitialized().

◆ $override_mimetype

string ilWebAccessChecker::$override_mimetype = ''
protected

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

Referenced by getOverrideMimetype(), and setOverrideMimetype().

◆ $path_object

ilWACPath ilWebAccessChecker::$path_object = null
protected

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

Referenced by getPathObject(), and setPathObject().

◆ $ressource_not_found

ilWACException ilWebAccessChecker::$ressource_not_found = null
private

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

◆ $revalidate_folder_tokens

bool ilWebAccessChecker::$revalidate_folder_tokens = true
protected

◆ $send_status_code

bool ilWebAccessChecker::$send_status_code = false
protected

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

Referenced by isSendStatusCode(), and setSendStatusCode().

◆ $use_seperate_logfile

bool ilWebAccessChecker::$use_seperate_logfile = false
staticprotected

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

Referenced by setUseSeperateLogfile().

◆ CM_CHECKINGINSTANCE

const ilWebAccessChecker::CM_CHECKINGINSTANCE = 3

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

◆ CM_FILE_TOKEN

const ilWebAccessChecker::CM_FILE_TOKEN = 1

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

◆ CM_FOLDER_TOKEN

const ilWebAccessChecker::CM_FOLDER_TOKEN = 2

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

◆ CM_SECFOLDER

const ilWebAccessChecker::CM_SECFOLDER = 4

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

◆ DISPOSITION

const ilWebAccessChecker::DISPOSITION = 'disposition'

◆ REVALIDATE

const ilWebAccessChecker::REVALIDATE = 'revalidate'

◆ STATUS_CODE

const ilWebAccessChecker::STATUS_CODE = 'status_code'

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