ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilWebAccessChecker Class Reference

Class ilWebAccessChecker. More...

+ Collaboration diagram for ilWebAccessChecker:

Public Member Functions

 __construct (private Services $http, 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
 

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 ( private Services  $http,
private CookieFactory  $cookieFactory 
)

ilWebAccessChecker constructor.

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

57  {
58  }

Member Function Documentation

◆ addAppliedCheckingMethod()

ilWebAccessChecker::addAppliedCheckingMethod ( int  $method)
protected

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

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

Referenced by check().

317  : void
318  {
319  $this->applied_checking_methods[] = $method;
320  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check()

ilWebAccessChecker::check ( )
Exceptions
ilWACException

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

References $data_dir, $path, addAppliedCheckingMethod(), CLIENT_WEB_DIR, ilWACPath\getCleanURLdecodedPath(), ilWACPath\getModuleType(), ilWACSecurePath\hasCheckingInstanceRegistered(), ILIAS\FileDelivery\http(), initILIAS(), ilWACPath\isInSecFolder(), isRevalidateFolderTokens(), sendHeader(), setChecked(), and setPathObject().

63  : bool
64  {
65  $path_object = new ilWACPath($this->http->request()->getRequestTarget());
67 
68  // Check if Path has been signed with a token
69  $ilWACSignedPath = new ilWACSignedPath($path_object, $this->http, $this->cookieFactory);
70  if ($ilWACSignedPath->isSignedPath()) {
71  $this->addAppliedCheckingMethod(self::CM_FILE_TOKEN);
72  if ($ilWACSignedPath->isSignedPathValid()) {
73  $this->setChecked(true);
74  $this->sendHeader('checked using token');
75 
76  return true;
77  }
78  }
79 
80  // Check if the whole secured folder has been signed
81  if ($ilWACSignedPath->isFolderSigned()) {
82  $this->addAppliedCheckingMethod(self::CM_FOLDER_TOKEN);
83  if ($ilWACSignedPath->isFolderTokenValid()) {
84  if ($this->isRevalidateFolderTokens()) {
85  $ilWACSignedPath->revalidatingFolderToken();
86  }
87  $this->setChecked(true);
88  $this->sendHeader('checked using secure folder');
89 
90  return true;
91  }
92  }
93 
94  // Fallback, have to initiate ILIAS
95  $this->initILIAS();
96 
97  // Check if Path is within accepted paths
98  if ($path_object->getModuleType() !== 'rs') {
99  $clean_path = $path_object->getCleanURLdecodedPath();
100  $path = realpath(__DIR__ . '/../../../../public/' . $clean_path);
101  $data_dir = realpath(CLIENT_WEB_DIR);
102  if (!str_starts_with($path, $data_dir)) {
103  return false;
104  }
105  if (dirname($path) === $data_dir && is_file($path)) {
106  return false;
107  }
108  }
109 
111  // Maybe the path has been registered, lets check
112  $checkingInstance = ilWACSecurePath::getCheckingInstance($path_object);
113  $this->addAppliedCheckingMethod(self::CM_CHECKINGINSTANCE);
114  $canBeDelivered = $checkingInstance->canBeDelivered($path_object);
115  if ($canBeDelivered) {
116  $this->sendHeader('checked using fallback');
117  if ($ilWACSignedPath->isFolderSigned() && $this->isRevalidateFolderTokens()) {
118  $ilWACSignedPath->revalidatingFolderToken();
119  }
120  }
121  $this->setChecked(true);
122  return $canBeDelivered;
123  }
124 
125  // none of the checking mechanisms could have been applied. no access
126  $this->setChecked(true);
127  $this->addAppliedCheckingMethod(self::CM_SECFOLDER);
128  return !$path_object->isInSecFolder();
129  }
setPathObject(ilWACPath $path_object)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:30
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.
getCleanURLdecodedPath()
Returns a clean (everything behind ? is removed and rawurldecoded path.
+ Here is the call graph for this function:

◆ checkPublicSection()

ilWebAccessChecker::checkPublicSection ( )
protected
Exceptions
ilWACException

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

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

Referenced by initILIAS().

187  : void
188  {
189  global $DIC;
190  $is_anonymous = ((int) $DIC->user()->getId() === (int) ANONYMOUS_USER_ID);
191  $is_null_user = ($DIC->user()->getId() === 0);
192  $pub_section_activated = (bool) $DIC['ilSetting']->get('pub_section');
193  $isset = isset($DIC['ilSetting']);
194  $instanceof = $DIC['ilSetting'] instanceof ilSetting;
195 
196  if (!$isset || !$instanceof) {
198  }
199 
200  if ($pub_section_activated && ($is_null_user || $is_anonymous)) {
201  // Request is initiated from an enabled public area
202  return;
203  }
204 
205  if ($is_anonymous || $is_null_user) {
207  }
208  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
global $DIC
Definition: shib_login.php:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkUser()

ilWebAccessChecker::checkUser ( )
protected

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

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

Referenced by initILIAS().

210  : void
211  {
212  global $DIC;
213 
214  $is_user = $DIC->user() instanceof ilObjUser;
215  $user_id_is_zero = ((int) $DIC->user()->getId() === 0);
216  if (!$is_user || $user_id_is_zero) {
218  }
219  }
global $DIC
Definition: shib_login.php:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAppliedCheckingMethods()

ilWebAccessChecker::getAppliedCheckingMethods ( )
Returns
int[]

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

References $applied_checking_methods.

304  : array
305  {
307  }

◆ getDisposition()

ilWebAccessChecker::getDisposition ( )

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

References $disposition.

241  : string
242  {
243  return $this->disposition;
244  }

◆ getOverrideMimetype()

ilWebAccessChecker::getOverrideMimetype ( )

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

References $override_mimetype.

251  : string
252  {
254  }

◆ getPathObject()

ilWebAccessChecker::getPathObject ( )

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

References $path_object.

Referenced by initILIAS().

231  : ?\ilWACPath
232  {
233  return $this->path_object;
234  }
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 137 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().

137  : void
138  {
139  global $DIC;
140 
141  if ($this->isInitialized()) {
142  return;
143  }
144 
145  $GLOBALS['COOKIE_PATH'] = '/';
146 
147  $cookie = $this->cookieFactory->create('ilClientId', $this->getPathObject()->getClient())
148  ->withPath('/')
149  ->withExpires(0);
150 
151  $response = $this->http->cookieJar()
152  ->with($cookie)
153  ->renderIntoResponseHeader($this->http->response());
154 
155  $this->http->saveResponse($response);
156 
158  try {
160  $this->checkUser();
161  $this->checkPublicSection();
162  } catch (Exception $e) {
163  if ($e instanceof ilWACException
164  && $e->getCode() !== ilWACException::ACCESS_DENIED_NO_LOGIN) {
165  throw $e;
166  }
167  if (($e instanceof Exception && $e->getMessage() === 'Authentication failed.')
168  || $e->getCode() === ilWACException::ACCESS_DENIED_NO_LOGIN) {
169  $this->initAnonymousSession();
170  $this->checkUser();
171  $this->checkPublicSection();
172  }
173  }
174  $this->setInitialized(true);
175 
176  // This workaround is needed because these issues:
177  // https://mantis.ilias.de/view.php?id=32284 and
178  // https://mantis.ilias.de/view.php?id=32063
179  if ($DIC->user()->getId() === 0) {
180  $DIC->user()->setId(ANONYMOUS_USER_ID);
181  }
182  }
const CONTEXT_WAC
const ANONYMOUS_USER_ID
Definition: constants.php:27
$response
Definition: xapitoken.php:90
setInitialized(bool $initialized)
static initILIAS()
ilias initialisation
static http()
Fetches the global http state from ILIAS.
$GLOBALS["DIC"]
Definition: wac.php:30
global $DIC
Definition: shib_login.php:25
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 221 of file class.ilWebAccessChecker.php.

References $checked.

221  : bool
222  {
223  return $this->checked;
224  }

◆ isInitialized()

ilWebAccessChecker::isInitialized ( )

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

References $initialized.

Referenced by initILIAS().

261  : bool
262  {
263  return $this->initialized;
264  }
+ Here is the caller graph for this function:

◆ isRevalidateFolderTokens()

ilWebAccessChecker::isRevalidateFolderTokens ( )

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

References $revalidate_folder_tokens.

Referenced by check().

281  : bool
282  {
284  }
+ Here is the caller graph for this function:

◆ isSendStatusCode()

ilWebAccessChecker::isSendStatusCode ( )

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

References $send_status_code.

271  : bool
272  {
274  }

◆ isUseSeperateLogfile()

static ilWebAccessChecker::isUseSeperateLogfile ( )
static

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

291  : bool
292  {
293  return self::$use_seperate_logfile;
294  }

◆ sendHeader()

ilWebAccessChecker::sendHeader ( string  $message)
protected

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

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

Referenced by check().

131  : void
132  {
133  $response = $this->http->response()->withHeader('X-ILIAS-WebAccessChecker', $message);
134  $this->http->saveResponse($response);
135  }
$response
Definition: xapitoken.php:90
static http()
Fetches the global http state from ILIAS.
+ 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 312 of file class.ilWebAccessChecker.php.

References $applied_checking_methods.

312  : void
313  {
314  $this->applied_checking_methods = $applied_checking_methods;
315  }

◆ setChecked()

ilWebAccessChecker::setChecked ( bool  $checked)

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

References $checked.

Referenced by check().

226  : void
227  {
228  $this->checked = $checked;
229  }
+ Here is the caller graph for this function:

◆ setDisposition()

ilWebAccessChecker::setDisposition ( string  $disposition)

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

References $disposition.

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

◆ setInitialized()

ilWebAccessChecker::setInitialized ( bool  $initialized)

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

References $initialized.

Referenced by initILIAS().

266  : void
267  {
268  $this->initialized = $initialized;
269  }
+ Here is the caller graph for this function:

◆ setOverrideMimetype()

ilWebAccessChecker::setOverrideMimetype ( string  $override_mimetype)

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

References $override_mimetype.

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

◆ setPathObject()

ilWebAccessChecker::setPathObject ( ilWACPath  $path_object)

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

References $path_object.

Referenced by check().

236  : void
237  {
238  $this->path_object = $path_object;
239  }
+ Here is the caller graph for this function:

◆ setRevalidateFolderTokens()

ilWebAccessChecker::setRevalidateFolderTokens ( bool  $revalidate_folder_tokens)

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

References $revalidate_folder_tokens.

286  : void
287  {
288  $this->revalidate_folder_tokens = $revalidate_folder_tokens;
289  }

◆ setSendStatusCode()

ilWebAccessChecker::setSendStatusCode ( bool  $send_status_code)

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

References $send_status_code.

276  : void
277  {
278  $this->send_status_code = $send_status_code;
279  }

◆ setUseSeperateLogfile()

static ilWebAccessChecker::setUseSeperateLogfile ( bool  $use_seperate_logfile)
static

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

References $use_seperate_logfile.

296  : void
297  {
298  self::$use_seperate_logfile = $use_seperate_logfile;
299  }

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().

◆ $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().

◆ $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: