ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 21 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 82 of file class.ilWebAccessChecker.php.

83 {
84 $this->setPathObject(new ilWACPath($httpState->request()->getRequestTarget()));
85 $this->http = $httpState;
86 $this->cookieFactory = $cookieFactory;
87 }
Class ilWACPath.
setPathObject(ilWACPath $path_object)
request()
Returns the current psr-7 server request.
static http()
Fetches the global http state from ILIAS.

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

+ Here is the call graph for this function:

Member Function Documentation

◆ addAppliedCheckingMethod()

ilWebAccessChecker::addAppliedCheckingMethod (   $method)
protected
Parameters
int$method
Returns
void

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

456 {
457 assert(is_int($method));
458 $this->applied_checking_methods[] = $method;
459 }

Referenced by check().

+ Here is the caller graph for this function:

◆ check()

ilWebAccessChecker::check ( )
Returns
bool
Exceptions
ilWACException

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

95 {
96 if (!$this->getPathObject()) {
98 }
99
100 // Check if Path has been signed with a token
101 $ilWACSignedPath = new ilWACSignedPath($this->getPathObject(), $this->http, $this->cookieFactory);
102 if ($ilWACSignedPath->isSignedPath()) {
103 $this->addAppliedCheckingMethod(self::CM_FILE_TOKEN);
104 if ($ilWACSignedPath->isSignedPathValid()) {
105 $this->setChecked(true);
106 $this->sendHeader('checked using token');
107
108 return true;
109 }
110 }
111
112 // Check if the whole secured folder has been signed
113 if ($ilWACSignedPath->isFolderSigned()) {
114 $this->addAppliedCheckingMethod(self::CM_FOLDER_TOKEN);
115 if ($ilWACSignedPath->isFolderTokenValid()) {
116 if ($this->isRevalidateFolderTokens()) {
117 $ilWACSignedPath->revalidatingFolderToken();
118 }
119 $this->setChecked(true);
120 $this->sendHeader('checked using secure folder');
121
122 return true;
123 }
124 }
125
126 // Fallback, have to initiate ILIAS
127 $this->initILIAS();
128
130 // Maybe the path has been registered, lets check
131 $checkingInstance = ilWACSecurePath::getCheckingInstance($this->getPathObject());
132 $this->addAppliedCheckingMethod(self::CM_CHECKINGINSTANCE);
133 $canBeDelivered = $checkingInstance->canBeDelivered($this->getPathObject());
134 if ($canBeDelivered) {
135 $this->sendHeader('checked using fallback');
136 if ($ilWACSignedPath->isFolderSigned() && $this->isRevalidateFolderTokens()) {
137 $ilWACSignedPath->revalidatingFolderToken();
138 }
139
140 $this->setChecked(true);
141
142 return true;
143 } else {
144 $this->setChecked(true);
145
146 return false;
147 }
148 }
149
150 // none of the checking mechanisms could have been applied. no access
151 $this->setChecked(true);
152 if ($this->getPathObject()->isInSecFolder()) {
153 $this->addAppliedCheckingMethod(self::CM_SECFOLDER);
154
155 return false;
156 } else {
157 $this->addAppliedCheckingMethod(self::CM_SECFOLDER);
158
159 return true;
160 }
161 }
Class ilWACException.
static hasCheckingInstanceRegistered(ilWACPath $ilWACPath)
Searches a checking instance for the given wac path.
Class ilWACSignedPath.

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

Referenced by ilWebAccessCheckerDelivery\handleRequest().

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

223 {
224 global $DIC;
225 $on_login_page = !$this->isRequestNotFromLoginPage();
226 $is_anonymous = ((int) $DIC->user()->getId() === (int) ANONYMOUS_USER_ID);
227 $is_null_user = ($DIC->user()->getId() === 0);
228 $pub_section_activated = (bool) $DIC['ilSetting']->get('pub_section');
229 $isset = isset($DIC['ilSetting']);
230 $instanceof = $DIC['ilSetting'] instanceof ilSetting;
231
232 if (!$isset || !$instanceof) {
234 }
235
236 if ($on_login_page && ($is_null_user || $is_anonymous)) {
237 // Request is initiated from login page
238 return;
239 }
240
241 if ($pub_section_activated && ($is_null_user || $is_anonymous)) {
242 // Request is initiated from an enabled public area
243 return;
244 }
245
246 if ($is_anonymous || $is_null_user) {
248 }
249 }
ILIAS Setting Class.
global $DIC
Definition: saml.php:7

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

Referenced by initILIAS().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkUser()

ilWebAccessChecker::checkUser ( )
protected

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

253 {
254 global $DIC;
255
256 $is_user = $DIC->user() instanceof ilObjUser;
257 $user_id_is_zero = ((int) $DIC->user()->getId() === 0);
258 $not_on_login_page = $this->isRequestNotFromLoginPage();
259 if (!$is_user || ($user_id_is_zero && $not_on_login_page)) {
261 }
262 }

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

Referenced by initILIAS().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAppliedCheckingMethods()

ilWebAccessChecker::getAppliedCheckingMethods ( )
Returns
int[]

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

434 {
435 return (array) $this->applied_checking_methods;
436 }

References $applied_checking_methods.

◆ getDisposition()

ilWebAccessChecker::getDisposition ( )
Returns
string

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

310 {
311 return (string) $this->disposition;
312 }

References $disposition.

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

+ Here is the caller graph for this function:

◆ getOverrideMimetype()

ilWebAccessChecker::getOverrideMimetype ( )
Returns
string

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

331 {
332 return (string) $this->override_mimetype;
333 }

References $override_mimetype.

◆ getPathObject()

ilWebAccessChecker::getPathObject ( )
Returns
ilWACPath

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

References $path_object.

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

+ Here is the caller graph for this function:

◆ initILIAS()

ilWebAccessChecker::initILIAS ( )
Returns
void

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

180 {
181 if ($this->isInitialized()) {
182 return;
183 }
184
185 $GLOBALS['COOKIE_PATH'] = '/';
186
187 $cookie = $this->cookieFactory->create('ilClientId', $this->getPathObject()->getClient())
188 ->withPath('/')
189 ->withExpires(0);
190
191 $response = $this->http->cookieJar()
192 ->with($cookie)
193 ->renderIntoResponseHeader($this->http->response());
194
195 $this->http->saveResponse($response);
196
198 try {
200 $this->checkUser();
201 $this->checkPublicSection();
202 } catch (Exception $e) {
203 if ($e instanceof ilWACException
204 && $e->getCode() !== ilWACException::ACCESS_DENIED_NO_LOGIN) {
205 throw $e;
206 }
207 if (($e instanceof Exception && $e->getMessage() == 'Authentication failed.')
208 || $e->getCode() === ilWACException::ACCESS_DENIED_NO_LOGIN) {
209 $this->initAnonymousSession();
210 $this->checkUser();
211 $this->checkPublicSection();
212 }
213 }
214 $this->setInitialized(true);
215 }
static init($a_type)
Init context by type.
const CONTEXT_WAC
static initILIAS()
ilias initialisation
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
$response

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isChecked()

ilWebAccessChecker::isChecked ( )
Returns
bool

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

269 {
270 return (bool) $this->checked;
271 }

References $checked.

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

+ Here is the caller graph for this function:

◆ isInitialized()

ilWebAccessChecker::isInitialized ( )
Returns
bool

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

352 {
353 return (bool) $this->initialized;
354 }

References $initialized.

Referenced by initILIAS().

+ Here is the caller graph for this function:

◆ isRequestNotFromLoginPage()

ilWebAccessChecker::isRequestNotFromLoginPage ( )
protected
Returns
bool

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

486 {
487 $referrer = (string) ($_SERVER['HTTP_REFERER'] ?? '');
488 $not_on_login_page = (strpos($referrer, 'login.php') === false
489 && strpos($referrer, '&baseClass=ilStartUpGUI') === false);
490
491 if ($not_on_login_page && $referrer !== '') {
492 // In some scenarios (observed for content styles on login page, the HTTP_REFERER does not contain a PHP script
493 $referrer_url_parts = parse_url($referrer);
494 $ilias_url_parts = parse_url(ilUtil::_getHttpPath());
495 if (
496 $ilias_url_parts['host'] === $referrer_url_parts['host'] &&
497 (
498 !isset($referrer_url_parts['path']) ||
499 strpos($referrer_url_parts['path'], '.php') === false
500 )
501 ) {
502 $not_on_login_page = false;
503 }
504 }
505
506 return $not_on_login_page;
507 }
static _getHttpPath()
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

References $_SERVER, and ilUtil\_getHttpPath().

Referenced by checkPublicSection(), and checkUser().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isRevalidateFolderTokens()

ilWebAccessChecker::isRevalidateFolderTokens ( )
Returns
bool

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

392 {
394 }

References $revalidate_folder_tokens.

Referenced by check().

+ Here is the caller graph for this function:

◆ isSendStatusCode()

ilWebAccessChecker::isSendStatusCode ( )
Returns
bool

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

371 {
372 return (bool) $this->send_status_code;
373 }

References $send_status_code.

◆ isUseSeperateLogfile()

static ilWebAccessChecker::isUseSeperateLogfile ( )
static
Returns
bool

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

413 {
414 return (bool) self::$use_seperate_logfile;
415 }

References $use_seperate_logfile.

◆ sendHeader()

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

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

170 {
171 $response = $this->http->response()->withHeader('X-ILIAS-WebAccessChecker', $message);
172 $this->http->saveResponse($response);
173 }
catch(Exception $e) $message

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

Referenced by check().

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

445 {
446 $this->applied_checking_methods = $applied_checking_methods;
447 }

References $applied_checking_methods.

◆ setChecked()

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

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

280 {
281 assert(is_bool($checked));
282 $this->checked = $checked;
283 }

References $checked.

Referenced by check().

+ Here is the caller graph for this function:

◆ setDisposition()

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

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

321 {
322 assert(is_string($disposition));
323 $this->disposition = $disposition;
324 }

References $disposition.

Referenced by ilWebAccessCheckerDelivery\handleRequest().

+ Here is the caller graph for this function:

◆ setInitialized()

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

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

361 {
362 assert(is_bool($initialized));
363 $this->initialized = $initialized;
364 }

References $initialized.

Referenced by initILIAS().

+ Here is the caller graph for this function:

◆ setOverrideMimetype()

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

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

342 {
343 assert(is_string($override_mimetype));
344 $this->override_mimetype = $override_mimetype;
345 }

References $override_mimetype.

◆ setPathObject()

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

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

301 {
302 $this->path_object = $path_object;
303 }

References $path_object.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRevalidateFolderTokens()

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

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

403 {
404 assert(is_bool($revalidate_folder_tokens));
405 $this->revalidate_folder_tokens = $revalidate_folder_tokens;
406 }

References $revalidate_folder_tokens.

Referenced by ilWebAccessCheckerDelivery\handleRequest().

+ Here is the caller graph for this function:

◆ setSendStatusCode()

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

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

382 {
383 assert(is_bool($send_status_code));
384 $this->send_status_code = $send_status_code;
385 }

References $send_status_code.

Referenced by ilWebAccessCheckerDelivery\handleRequest().

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

424 {
425 assert(is_bool($use_seperate_logfile));
426 self::$use_seperate_logfile = $use_seperate_logfile;
427 }

References $use_seperate_logfile.

Field Documentation

◆ $applied_checking_methods

ilWebAccessChecker::$applied_checking_methods = array()
protected

◆ $checked

ilWebAccessChecker::$checked = false
protected

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

Referenced by isChecked(), and setChecked().

◆ $cookieFactory

CookieFactory ilWebAccessChecker::$cookieFactory
private

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

Referenced by __construct().

◆ $disposition

ilWebAccessChecker::$disposition = ilFileDelivery::DISP_INLINE
protected

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

Referenced by getDisposition(), and setDisposition().

◆ $http

ILIAS DI HTTPServices ilWebAccessChecker::$http
private

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

◆ $initialized

ilWebAccessChecker::$initialized = false
protected

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

Referenced by isInitialized(), and setInitialized().

◆ $override_mimetype

ilWebAccessChecker::$override_mimetype = ''
protected

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

Referenced by getOverrideMimetype(), and setOverrideMimetype().

◆ $path_object

ilWebAccessChecker::$path_object = null
protected

Definition at line 33 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 49 of file class.ilWebAccessChecker.php.

Referenced by isSendStatusCode(), and setSendStatusCode().

◆ $use_seperate_logfile

ilWebAccessChecker::$use_seperate_logfile = false
staticprotected

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

Referenced by isUseSeperateLogfile(), and setUseSeperateLogfile().

◆ CM_CHECKINGINSTANCE

const ilWebAccessChecker::CM_CHECKINGINSTANCE = 3

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

◆ CM_FILE_TOKEN

const ilWebAccessChecker::CM_FILE_TOKEN = 1

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

◆ CM_FOLDER_TOKEN

const ilWebAccessChecker::CM_FOLDER_TOKEN = 2

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

◆ CM_SECFOLDER

const ilWebAccessChecker::CM_SECFOLDER = 4

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