ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilWebAccessChecker Class Reference

Class ilWebAccessChecker. More...

+ Collaboration diagram for ilWebAccessChecker:

Public Member Functions

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

Static Public Member Functions

static isUseSeperateLogfile ()
 
static setUseSeperateLogfile ($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 ($message)
 
 checkPublicSection ()
 
 checkUser ()
 
 addAppliedCheckingMethod ($method)
 
 isRequestNotFromLoginPage ()
 

Protected Attributes

 $path_object = null
 
 $checked = false
 
 $disposition = ilFileDelivery::DISP_INLINE
 
 $override_mimetype = ''
 
 $send_status_code = false
 
 $initialized = false
 
 $revalidate_folder_tokens = true
 
 $applied_checking_methods = array()
 

Static Protected Attributes

static $use_seperate_logfile = false
 

Private Attributes

 $http
 
 $cookieFactory
 

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 36 of file class.ilWebAccessChecker.php.

Constructor & Destructor Documentation

◆ __construct()

ilWebAccessChecker::__construct ( GlobalHttpState  $httpState,
CookieFactory  $cookieFactory 
)

ilWebAccessChecker constructor.

Parameters
GlobalHttpState$httpState
CookieFactory$cookieFactory

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

References $cookieFactory, ILIAS\FileDelivery\http(), ILIAS\HTTP\GlobalHttpState\request(), and setPathObject().

98  {
99  $this->setPathObject(new ilWACPath($httpState->request()->getRequestTarget()));
100  $this->http = $httpState;
101  $this->cookieFactory = $cookieFactory;
102  }
setPathObject(ilWACPath $path_object)
request()
Returns the current psr-7 server request.
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 (   $method)
protected
Parameters
int$method
Returns
void

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

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

Referenced by check().

483  {
484  assert(is_int($method));
485  $this->applied_checking_methods[] = $method;
486  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check()

ilWebAccessChecker::check ( )
Returns
bool
Exceptions
ilWACException

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

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

Referenced by ilWebAccessCheckerDelivery\handleRequest(), ilWACCheckingInstanceTest\testBasic(), and ilWACCheckingInstanceTest\testNonCheckingInstanceNoSec().

110  {
111  if (!$this->getPathObject()) {
113  }
114 
115  // Check if Path has been signed with a token
116  $ilWACSignedPath = new ilWACSignedPath($this->getPathObject(), $this->http, $this->cookieFactory);
117  if ($ilWACSignedPath->isSignedPath()) {
118  $this->addAppliedCheckingMethod(self::CM_FILE_TOKEN);
119  if ($ilWACSignedPath->isSignedPathValid()) {
120  $this->setChecked(true);
121  $this->sendHeader('checked using token');
122 
123  return true;
124  }
125  }
126 
127  // Check if the whole secured folder has been signed
128  if ($ilWACSignedPath->isFolderSigned()) {
129  $this->addAppliedCheckingMethod(self::CM_FOLDER_TOKEN);
130  if ($ilWACSignedPath->isFolderTokenValid()) {
131  if ($this->isRevalidateFolderTokens()) {
132  $ilWACSignedPath->revalidatingFolderToken();
133  }
134  $this->setChecked(true);
135  $this->sendHeader('checked using secure folder');
136 
137  return true;
138  }
139  }
140 
141  // Fallback, have to initiate ILIAS
142  $this->initILIAS();
143 
144  // Check if Path is within accepted paths
145  if ($this->getPathObject()->getModuleType() !== 'rs') {
146  $path = realpath($this->getPathObject()->getCleanURLdecodedPath());
147  $data_dir = realpath(CLIENT_WEB_DIR);
148  if (strpos($path, $data_dir) !== 0) {
149  return false;
150  }
151  if (dirname($path) === $data_dir && is_file($path)) {
152  return false;
153  }
154  }
155 
157  // Maybe the path has been registered, lets check
158  $checkingInstance = ilWACSecurePath::getCheckingInstance($this->getPathObject());
159  $this->addAppliedCheckingMethod(self::CM_CHECKINGINSTANCE);
160  $canBeDelivered = $checkingInstance->canBeDelivered($this->getPathObject());
161  if ($canBeDelivered) {
162  $this->sendHeader('checked using fallback');
163  if ($ilWACSignedPath->isFolderSigned() && $this->isRevalidateFolderTokens()) {
164  $ilWACSignedPath->revalidatingFolderToken();
165  }
166 
167  $this->setChecked(true);
168 
169  return true;
170  } else {
171  $this->setChecked(true);
172 
173  return false;
174  }
175  }
176 
177  // none of the checking mechanisms could have been applied. no access
178  $this->setChecked(true);
179  if ($this->getPathObject()->isInSecFolder()) {
180  $this->addAppliedCheckingMethod(self::CM_SECFOLDER);
181 
182  return false;
183  } else {
184  $this->addAppliedCheckingMethod(self::CM_SECFOLDER);
185 
186  return true;
187  }
188  }
Class ilWACException.
static http()
Fetches the global http state from ILIAS.
Class ilWACSignedPath.
static hasCheckingInstanceRegistered(ilWACPath $ilWACPath)
Searches a checking instance for the given wac path.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkPublicSection()

ilWebAccessChecker::checkPublicSection ( )
protected
Returns
void
Exceptions
ilWACException

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

References $DIC, ilWACException\ACCESS_DENIED_NO_PUB, and isRequestNotFromLoginPage().

Referenced by initILIAS().

250  {
251  global $DIC;
252  $on_login_page = !$this->isRequestNotFromLoginPage();
253  $is_anonymous = ((int) $DIC->user()->getId() === (int) ANONYMOUS_USER_ID);
254  $is_null_user = ($DIC->user()->getId() === 0);
255  $pub_section_activated = (bool) $DIC['ilSetting']->get('pub_section');
256  $isset = isset($DIC['ilSetting']);
257  $instanceof = $DIC['ilSetting'] instanceof ilSetting;
258 
259  if (!$isset || !$instanceof) {
261  }
262 
263  if ($on_login_page && ($is_null_user || $is_anonymous)) {
264  // Request is initiated from login page
265  return;
266  }
267 
268  if ($pub_section_activated && ($is_null_user || $is_anonymous)) {
269  // Request is initiated from an enabled public area
270  return;
271  }
272 
273  if ($is_anonymous || $is_null_user) {
275  }
276  }
Class ilWACException.
$DIC
Definition: xapitoken.php:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkUser()

ilWebAccessChecker::checkUser ( )
protected

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

References $DIC, ilWACException\ACCESS_DENIED_NO_LOGIN, and isRequestNotFromLoginPage().

Referenced by initILIAS().

280  {
281  global $DIC;
282 
283  $is_user = $DIC->user() instanceof ilObjUser;
284  $user_id_is_zero = ((int) $DIC->user()->getId() === 0);
285  $not_on_login_page = $this->isRequestNotFromLoginPage();
286  if (!$is_user || ($user_id_is_zero && $not_on_login_page)) {
288  }
289  }
Class ilWACException.
$DIC
Definition: xapitoken.php:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAppliedCheckingMethods()

ilWebAccessChecker::getAppliedCheckingMethods ( )
Returns
int[]

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

References $applied_checking_methods.

461  {
462  return (array) $this->applied_checking_methods;
463  }

◆ getDisposition()

ilWebAccessChecker::getDisposition ( )
Returns
string

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

References $disposition.

Referenced by ilWebAccessCheckerDelivery\deliver(), ilWebAccessCheckerDelivery\deliverDummyImage(), and ilWebAccessCheckerDelivery\deliverDummyVideo().

337  {
338  return (string) $this->disposition;
339  }
+ Here is the caller graph for this function:

◆ getOverrideMimetype()

ilWebAccessChecker::getOverrideMimetype ( )
Returns
string

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

References $override_mimetype.

358  {
359  return (string) $this->override_mimetype;
360  }

◆ getPathObject()

ilWebAccessChecker::getPathObject ( )
Returns
ilWACPath

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

References $path_object.

Referenced by check(), ilWebAccessCheckerDelivery\deliver(), ilWebAccessCheckerDelivery\handleAccessErrors(), and initILIAS().

317  {
318  return $this->path_object;
319  }
+ Here is the caller graph for this function:

◆ initILIAS()

ilWebAccessChecker::initILIAS ( )
Returns
void

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

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

Referenced by check(), and ilWebAccessCheckerDelivery\handleAccessErrors().

207  {
208  if ($this->isInitialized()) {
209  return;
210  }
211 
212  $GLOBALS['COOKIE_PATH'] = '/';
213 
214  $cookie = $this->cookieFactory->create('ilClientId', $this->getPathObject()->getClient())
215  ->withPath('/')
216  ->withExpires(0);
217 
218  $response = $this->http->cookieJar()
219  ->with($cookie)
220  ->renderIntoResponseHeader($this->http->response());
221 
222  $this->http->saveResponse($response);
223 
225  try {
227  $this->checkUser();
228  $this->checkPublicSection();
229  } catch (Exception $e) {
230  if ($e instanceof ilWACException
231  && $e->getCode() !== ilWACException::ACCESS_DENIED_NO_LOGIN) {
232  throw $e;
233  }
234  if (($e instanceof Exception && $e->getMessage() == 'Authentication failed.')
235  || $e->getCode() === ilWACException::ACCESS_DENIED_NO_LOGIN) {
236  $this->initAnonymousSession();
237  $this->checkUser();
238  $this->checkPublicSection();
239  }
240  }
241  $this->setInitialized(true);
242  }
Class ilWACException.
const CONTEXT_WAC
static initILIAS()
ilias initialisation
static http()
Fetches the global http state from ILIAS.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static init($a_type)
Init context by type.
$response
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isChecked()

ilWebAccessChecker::isChecked ( )
Returns
bool

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

References $checked.

Referenced by ilWebAccessCheckerDelivery\deliver(), and ilWebAccessCheckerDelivery\deny().

296  {
297  return (bool) $this->checked;
298  }
+ Here is the caller graph for this function:

◆ isInitialized()

ilWebAccessChecker::isInitialized ( )
Returns
bool

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

References $initialized.

Referenced by initILIAS().

379  {
380  return (bool) $this->initialized;
381  }
+ Here is the caller graph for this function:

◆ isRequestNotFromLoginPage()

ilWebAccessChecker::isRequestNotFromLoginPage ( )
protected
Returns
bool

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

References $_SERVER, and ilUtil\_getHttpPath().

Referenced by checkPublicSection(), and checkUser().

514  {
515  $referrer = (string) ($_SERVER['HTTP_REFERER'] ?? '');
516  $not_on_login_page = (strpos($referrer, 'login.php') === false
517  && strpos($referrer, '&baseClass=ilStartUpGUI') === false);
518 
519  if ($not_on_login_page && $referrer !== '') {
520  // In some scenarios (observed for content styles on login page, the HTTP_REFERER does not contain a PHP script
521  $referrer_url_parts = parse_url($referrer);
522  $ilias_url_parts = parse_url(ilUtil::_getHttpPath());
523  if (
524  $ilias_url_parts['host'] === $referrer_url_parts['host'] &&
525  (
526  !isset($referrer_url_parts['path']) ||
527  strpos($referrer_url_parts['path'], '.php') === false
528  )
529  ) {
530  $not_on_login_page = false;
531  }
532  }
533 
534  return $not_on_login_page;
535  }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
static _getHttpPath()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isRevalidateFolderTokens()

ilWebAccessChecker::isRevalidateFolderTokens ( )
Returns
bool

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

References $revalidate_folder_tokens.

Referenced by check().

419  {
420  return (bool) $this->revalidate_folder_tokens;
421  }
+ Here is the caller graph for this function:

◆ isSendStatusCode()

ilWebAccessChecker::isSendStatusCode ( )
Returns
bool

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

References $send_status_code.

398  {
399  return (bool) $this->send_status_code;
400  }

◆ isUseSeperateLogfile()

static ilWebAccessChecker::isUseSeperateLogfile ( )
static
Returns
bool

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

440  {
441  return (bool) self::$use_seperate_logfile;
442  }

◆ sendHeader()

ilWebAccessChecker::sendHeader (   $message)
protected
Parameters
string$message
Returns
void

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

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

Referenced by check().

197  {
198  $response = $this->http->response()->withHeader('X-ILIAS-WebAccessChecker', $message);
199  $this->http->saveResponse($response);
200  }
static http()
Fetches the global http state from ILIAS.
$message
Definition: xapiexit.php:14
$response
+ 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
Returns
void

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

References $applied_checking_methods.

472  {
473  $this->applied_checking_methods = $applied_checking_methods;
474  }

◆ setChecked()

ilWebAccessChecker::setChecked (   $checked)
Parameters
boolean$checked
Returns
void

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

References $checked.

Referenced by check().

307  {
308  assert(is_bool($checked));
309  $this->checked = $checked;
310  }
+ Here is the caller graph for this function:

◆ setDisposition()

ilWebAccessChecker::setDisposition (   $disposition)
Parameters
string$disposition
Returns
void

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

References $disposition.

Referenced by ilWebAccessCheckerDelivery\handleRequest().

348  {
349  assert(is_string($disposition));
350  $this->disposition = $disposition;
351  }
+ Here is the caller graph for this function:

◆ setInitialized()

ilWebAccessChecker::setInitialized (   $initialized)
Parameters
bool$initialized

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

References $initialized.

Referenced by initILIAS().

388  {
389  assert(is_bool($initialized));
390  $this->initialized = $initialized;
391  }
+ Here is the caller graph for this function:

◆ setOverrideMimetype()

ilWebAccessChecker::setOverrideMimetype (   $override_mimetype)
Parameters
string$override_mimetype
Returns
void

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

References $override_mimetype.

369  {
370  assert(is_string($override_mimetype));
371  $this->override_mimetype = $override_mimetype;
372  }

◆ setPathObject()

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

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

References $path_object.

Referenced by __construct().

328  {
329  $this->path_object = $path_object;
330  }
+ Here is the caller graph for this function:

◆ setRevalidateFolderTokens()

ilWebAccessChecker::setRevalidateFolderTokens (   $revalidate_folder_tokens)
Parameters
bool$revalidate_folder_tokens
Returns
void

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

References $revalidate_folder_tokens.

Referenced by ilWebAccessCheckerDelivery\handleRequest().

430  {
431  assert(is_bool($revalidate_folder_tokens));
432  $this->revalidate_folder_tokens = $revalidate_folder_tokens;
433  }
+ Here is the caller graph for this function:

◆ setSendStatusCode()

ilWebAccessChecker::setSendStatusCode (   $send_status_code)
Parameters
bool$send_status_code
Returns
void

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

References $send_status_code.

Referenced by ilWebAccessCheckerDelivery\handleRequest().

409  {
410  assert(is_bool($send_status_code));
411  $this->send_status_code = $send_status_code;
412  }
+ Here is the caller graph for this function:

◆ setUseSeperateLogfile()

static ilWebAccessChecker::setUseSeperateLogfile (   $use_seperate_logfile)
static
Parameters
bool$use_seperate_logfile
Returns
void

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

References $use_seperate_logfile.

451  {
452  assert(is_bool($use_seperate_logfile));
453  self::$use_seperate_logfile = $use_seperate_logfile;
454  }

Field Documentation

◆ $applied_checking_methods

ilWebAccessChecker::$applied_checking_methods = array()
protected

◆ $checked

ilWebAccessChecker::$checked = false
protected

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

Referenced by isChecked(), and setChecked().

◆ $cookieFactory

CookieFactory ilWebAccessChecker::$cookieFactory
private

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

Referenced by __construct().

◆ $disposition

ilWebAccessChecker::$disposition = ilFileDelivery::DISP_INLINE
protected

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

Referenced by getDisposition(), and setDisposition().

◆ $http

ILIAS DI HTTPServices ilWebAccessChecker::$http
private

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

◆ $initialized

ilWebAccessChecker::$initialized = false
protected

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

Referenced by isInitialized(), and setInitialized().

◆ $override_mimetype

ilWebAccessChecker::$override_mimetype = ''
protected

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

Referenced by getOverrideMimetype(), and setOverrideMimetype().

◆ $path_object

ilWebAccessChecker::$path_object = null
protected

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

Referenced by getPathObject(), and setPathObject().

◆ $revalidate_folder_tokens

ilWebAccessChecker::$revalidate_folder_tokens = true
protected

◆ $send_status_code

ilWebAccessChecker::$send_status_code = false
protected

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

Referenced by isSendStatusCode(), and setSendStatusCode().

◆ $use_seperate_logfile

ilWebAccessChecker::$use_seperate_logfile = false
staticprotected

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

Referenced by setUseSeperateLogfile().

◆ CM_CHECKINGINSTANCE

const ilWebAccessChecker::CM_CHECKINGINSTANCE = 3

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

◆ CM_FILE_TOKEN

const ilWebAccessChecker::CM_FILE_TOKEN = 1

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

◆ CM_FOLDER_TOKEN

const ilWebAccessChecker::CM_FOLDER_TOKEN = 2

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

◆ CM_SECFOLDER

const ilWebAccessChecker::CM_SECFOLDER = 4

Definition at line 44 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: