ILIAS  release_8 Revision v8.24
ilWebAccessChecker Class Reference

Class ilWebAccessChecker. More...

+ Collaboration diagram for ilWebAccessChecker:

Public Member Functions

 __construct (Services $httpState, 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
 
CookieFactory $cookieFactory
 
ilWACException $ressource_not_found
 

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,
CookieFactory  $cookieFactory 
)

ilWebAccessChecker constructor.

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

60 {
61 try {
62 $this->setPathObject(new ilWACPath($httpState->request()->getRequestTarget()));
63 } catch (ilWACException $e) {
64 if ($e->getCode() !== ilWACException::NOT_FOUND) {
65 throw $e;
66 }
67 $this->ressource_not_found = $e;
68 }
69
70 $this->http = $httpState;
71 $this->cookieFactory = $cookieFactory;
72 }
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...
setPathObject(ilWACPath $path_object)
static http()
Fetches the global http state from ILIAS.

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

+ Here is the call graph for this function:

Member Function Documentation

◆ addAppliedCheckingMethod()

ilWebAccessChecker::addAppliedCheckingMethod ( int  $method)
protected

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

336 : void
337 {
338 $this->applied_checking_methods[] = $method;
339 }

Referenced by check().

+ Here is the caller graph for this function:

◆ check()

ilWebAccessChecker::check ( )
Exceptions
ilWACException

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

77 : bool
78 {
79 if ($this->getPathObject() === null) {
80 if ($this->ressource_not_found !== null) {
81 throw new ilWACException(ilWACException::NOT_FOUND, '', $this->ressource_not_found);
82 }
83
85 }
86
87 // Check if Path has been signed with a token
88 $ilWACSignedPath = new ilWACSignedPath($this->getPathObject(), $this->http, $this->cookieFactory);
89 if ($ilWACSignedPath->isSignedPath()) {
90 $this->addAppliedCheckingMethod(self::CM_FILE_TOKEN);
91 if ($ilWACSignedPath->isSignedPathValid()) {
92 $this->setChecked(true);
93 $this->sendHeader('checked using token');
94
95 return true;
96 }
97 }
98
99 // Check if the whole secured folder has been signed
100 if ($ilWACSignedPath->isFolderSigned()) {
101 $this->addAppliedCheckingMethod(self::CM_FOLDER_TOKEN);
102 if ($ilWACSignedPath->isFolderTokenValid()) {
103 if ($this->isRevalidateFolderTokens()) {
104 $ilWACSignedPath->revalidatingFolderToken();
105 }
106 $this->setChecked(true);
107 $this->sendHeader('checked using secure folder');
108
109 return true;
110 }
111 }
112
113 // Fallback, have to initiate ILIAS
114 $this->initILIAS();
115
116 // Check if Path is within accepted paths
117 if ($this->getPathObject()->getModuleType() !== 'rs') {
118 $clean_path = $this->getPathObject()->getCleanURLdecodedPath();
119 $path = realpath($clean_path);
120 $data_dir = realpath(CLIENT_WEB_DIR);
121 if (strpos($path, $data_dir) !== 0) {
122 return false;
123 }
124 if (dirname($path) === $data_dir && is_file($path)) {
125 return false;
126 }
127 }
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 return $canBeDelivered;
142 }
143
144 // none of the checking mechanisms could have been applied. no access
145 $this->setChecked(true);
146 $this->addAppliedCheckingMethod(self::CM_SECFOLDER);
147 return !$this->getPathObject()->isInSecFolder();
148 }
static hasCheckingInstanceRegistered(ilWACPath $ilWACPath)
Searches a checking instance for the given wac path.
Class ilWACSignedPath.
const CLIENT_WEB_DIR
Definition: constants.php:47
$path
Definition: ltiservices.php:32

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

+ Here is the call graph for this function:

◆ checkPublicSection()

ilWebAccessChecker::checkPublicSection ( )
protected
Exceptions
ilWACException

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

206 : void
207 {
208 global $DIC;
209 $is_anonymous = ((int) $DIC->user()->getId() === (int) ANONYMOUS_USER_ID);
210 $is_null_user = ($DIC->user()->getId() === 0);
211 $pub_section_activated = (bool) $DIC['ilSetting']->get('pub_section');
212 $isset = isset($DIC['ilSetting']);
213 $instanceof = $DIC['ilSetting'] instanceof ilSetting;
214
215 if (!$isset || !$instanceof) {
217 }
218
219 if ($pub_section_activated && ($is_null_user || $is_anonymous)) {
220 // Request is initiated from an enabled public area
221 return;
222 }
223
224 if ($is_anonymous || $is_null_user) {
226 }
227 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ANONYMOUS_USER_ID
Definition: constants.php:27
global $DIC
Definition: feed.php:28

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

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

229 : void
230 {
231 global $DIC;
232
233 $is_user = $DIC->user() instanceof ilObjUser;
234 $user_id_is_zero = ((int) $DIC->user()->getId() === 0);
235 if (!$is_user || $user_id_is_zero) {
237 }
238 }
User class.

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

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

323 : array
324 {
326 }

References $applied_checking_methods.

◆ getDisposition()

ilWebAccessChecker::getDisposition ( )

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

260 : string
261 {
262 return $this->disposition;
263 }

References $disposition.

◆ getOverrideMimetype()

ilWebAccessChecker::getOverrideMimetype ( )

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

270 : string
271 {
273 }

References $override_mimetype.

◆ getPathObject()

ilWebAccessChecker::getPathObject ( )

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

250 : ?\ilWACPath
251 {
252 return $this->path_object;
253 }

References $path_object.

Referenced by check(), and initILIAS().

+ Here is the caller graph for this function:

◆ initILIAS()

ilWebAccessChecker::initILIAS ( )

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

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

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

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

◆ isChecked()

ilWebAccessChecker::isChecked ( )

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

240 : bool
241 {
242 return $this->checked;
243 }

References $checked.

◆ isInitialized()

ilWebAccessChecker::isInitialized ( )

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

280 : bool
281 {
282 return $this->initialized;
283 }

References $initialized.

Referenced by initILIAS().

+ Here is the caller graph for this function:

◆ isRevalidateFolderTokens()

ilWebAccessChecker::isRevalidateFolderTokens ( )

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

300 : bool
301 {
303 }

References $revalidate_folder_tokens.

Referenced by check().

+ Here is the caller graph for this function:

◆ isSendStatusCode()

ilWebAccessChecker::isSendStatusCode ( )

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

290 : bool
291 {
293 }

References $send_status_code.

◆ isUseSeperateLogfile()

static ilWebAccessChecker::isUseSeperateLogfile ( )
static

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

310 : bool
311 {
313 }

References $use_seperate_logfile.

◆ sendHeader()

ilWebAccessChecker::sendHeader ( string  $message)
protected

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

150 : void
151 {
152 $response = $this->http->response()->withHeader('X-ILIAS-WebAccessChecker', $message);
153 $this->http->saveResponse($response);
154 }
$message
Definition: xapiexit.php:32

References $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

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

331 : void
332 {
333 $this->applied_checking_methods = $applied_checking_methods;
334 }

References $applied_checking_methods.

◆ setChecked()

ilWebAccessChecker::setChecked ( bool  $checked)

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

245 : void
246 {
247 $this->checked = $checked;
248 }

References $checked.

Referenced by check().

+ Here is the caller graph for this function:

◆ setDisposition()

ilWebAccessChecker::setDisposition ( string  $disposition)

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

265 : void
266 {
267 $this->disposition = $disposition;
268 }

References $disposition.

◆ setInitialized()

ilWebAccessChecker::setInitialized ( bool  $initialized)

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

285 : void
286 {
287 $this->initialized = $initialized;
288 }

References $initialized.

Referenced by initILIAS().

+ Here is the caller graph for this function:

◆ setOverrideMimetype()

ilWebAccessChecker::setOverrideMimetype ( string  $override_mimetype)

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

275 : void
276 {
277 $this->override_mimetype = $override_mimetype;
278 }

References $override_mimetype.

◆ setPathObject()

ilWebAccessChecker::setPathObject ( ilWACPath  $path_object)

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

255 : void
256 {
257 $this->path_object = $path_object;
258 }

References $path_object.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRevalidateFolderTokens()

ilWebAccessChecker::setRevalidateFolderTokens ( bool  $revalidate_folder_tokens)

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

305 : void
306 {
307 $this->revalidate_folder_tokens = $revalidate_folder_tokens;
308 }

References $revalidate_folder_tokens.

◆ setSendStatusCode()

ilWebAccessChecker::setSendStatusCode ( bool  $send_status_code)

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

295 : void
296 {
297 $this->send_status_code = $send_status_code;
298 }

References $send_status_code.

◆ setUseSeperateLogfile()

static ilWebAccessChecker::setUseSeperateLogfile ( bool  $use_seperate_logfile)
static

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

315 : void
316 {
317 self::$use_seperate_logfile = $use_seperate_logfile;
318 }

References $use_seperate_logfile.

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

◆ $cookieFactory

CookieFactory ilWebAccessChecker::$cookieFactory
private

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

Referenced by __construct().

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

Definition at line 54 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 isUseSeperateLogfile(), and 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: