3declare(strict_types=1);
66 $this->
user = $DIC->user();
67 $this->db =
$DIC->database();
68 $this->rbacsystem =
$DIC[
'rbacsystem'];
69 $this->results = array();
72 $this->objDefinition =
$DIC[
'objDefinition'];
78 $this->condition =
true;
81 $this->obj_id_cache = [];
82 $this->obj_type_cache = [];
83 $this->obj_tree_cache = [];
105 string $a_permission,
108 bool $a_access_granted,
109 ?
int $a_user_id =
null,
112 if ($a_user_id === null) {
113 $a_user_id = $this->
user->getId();
115 if ($a_info ===
null) {
119 $this->results[$a_ref_id][$a_permission][$a_cmd][$a_user_id] = [
120 "granted" => $a_access_granted,
124 $this->current_result_element = [$a_access_granted, $a_ref_id, $a_permission, $a_cmd, $a_user_id];
125 $this->last_result = $this->results[$a_ref_id][$a_permission][$a_cmd][$a_user_id];
126 $this->last_info = $a_info;
137 $this->prevent_caching_last_result = $a_val;
145 return $this->prevent_caching_last_result;
152 string $a_permission,
155 ?
int $a_user_id =
null
157 if ($a_user_id === null) {
158 $a_user_id = $this->
user->getId();
160 if (isset($this->results[$a_ref_id][$a_permission][$a_cmd][$a_user_id])) {
161 return $this->results[$a_ref_id][$a_permission][$a_cmd][$a_user_id];
171 $query =
"DELETE FROM acc_cache WHERE user_id = " . $this->db->quote($this->
user->getId(),
'integer');
174 $this->db->insert(
'acc_cache', array(
175 'user_id' => array(
'integer', $this->
user->getId()),
176 'time' => array(
'integer', time()),
177 'result' => array(
'clob', serialize($this->results))
187 $query =
"SELECT * FROM acc_cache WHERE user_id = " .
188 $this->db->quote($this->
user->getId(),
'integer');
189 $set = $this->db->query(
$query);
191 if ((time() - $rec[
"time"]) < $a_secs) {
192 $this->results = unserialize($rec[
"result"]);
212 $this->results = $a_results;
218 public function addInfoItem(
string $a_type,
string $a_text,
string $a_data =
""): void
220 $this->current_info->addInfoItem($a_type, $a_text, $a_data);
227 string $a_permission,
231 ?
int $a_obj_id =
null,
232 ?
int $a_tree_id =
null
234 return $this->checkAccessOfUser(
250 string $a_permission,
259 $ilBench =
$DIC[
'ilBench'];
261 $this->setPreventCachingLastResult(
false);
263 $ilBench->start(
"AccessControl",
"0400_clear_info");
264 $this->current_info->clear();
265 $ilBench->stop(
"AccessControl",
"0400_clear_info");
268 $cached = $this->doCacheCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id);
269 if ($cached[
"hit"]) {
271 if (!$cached[
"granted"]) {
274 if ($cached[
"prevent_db_cache"]) {
275 $this->setPreventCachingLastResult(
true);
277 return $cached[
"granted"];
280 $ilBench->start(
"AccessControl",
"0500_lookup_id_and_type");
282 if ($a_obj_id == 0) {
283 if (isset($this->obj_id_cache[$a_ref_id]) && $this->obj_id_cache[$a_ref_id] > 0) {
284 $a_obj_id = $this->obj_id_cache[$a_ref_id];
287 $this->obj_id_cache[$a_ref_id] = $a_obj_id;
291 if (isset($this->obj_type_cache[$a_ref_id]) && $this->obj_type_cache[$a_ref_id] !=
"") {
292 $a_type = $this->obj_type_cache[$a_ref_id];
295 $this->obj_type_cache[$a_ref_id] = $a_type;
299 $ilBench->stop(
"AccessControl",
"0500_lookup_id_and_type");
303 if ($a_tree_id != 1 &&
304 !$this->doTreeCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id)) {
306 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
311 if (!$this->doRBACCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_type)) {
313 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
318 $act_check = $this->doActivationCheck(
329 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
334 $par_check = $this->doPathCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id);
337 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
342 if (!$this->doConditionCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_obj_id, $a_type)) {
344 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
345 $this->setPreventCachingLastResult(
true);
350 if (!$this->doStatusCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_obj_id, $a_type)) {
352 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
353 $this->setPreventCachingLastResult(
true);
358 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
true, $a_user_id);
367 return is_object($this->last_info) ? $this->last_info->getInfoItems() : array();
375 return $this->last_result;
383 if ($a_ref_id ==
"") {
387 return $this->results[$a_ref_id];
393 public function doCacheCheck(
string $a_permission,
string $a_cmd,
int $a_ref_id,
int $a_user_id): array
395 $stored_access = $this->getStoredAccessResult($a_permission, $a_cmd, $a_ref_id, $a_user_id);
398 if ($stored_access !== []) {
399 if (isset($stored_access[
'info']) && $stored_access[
'info'] instanceof
ilAccessInfo) {
400 $this->current_info = $stored_access[
"info"];
405 "granted" => $stored_access[
"granted"],
406 "prevent_db_cache" => $stored_access[
"prevent_db_cache"]
414 "prevent_db_cache" => false
421 public function doTreeCheck(
string $a_permission,
string $a_cmd,
int $a_ref_id,
int $a_user_id): bool
424 $tree_cache_key = $a_user_id .
':' . $a_ref_id;
425 if (array_key_exists($tree_cache_key, $this->obj_tree_cache)) {
427 if (!$this->obj_tree_cache[$tree_cache_key]) {
428 $this->current_info->addInfoItem(
433 $this->storeAccessResult(
437 $this->obj_tree_cache[$tree_cache_key],
441 return $this->obj_tree_cache[$tree_cache_key];
444 if (!$this->
repositoryTree->isInTree($a_ref_id) || $this->repositoryTree->isDeleted($a_ref_id)) {
448 if (count($this->obj_tree_cache) < self::MAX_CACHE_SIZE) {
449 $this->obj_tree_cache[$tree_cache_key] =
false;
454 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
461 if (count($this->obj_tree_cache) < self::MAX_CACHE_SIZE) {
462 $this->obj_tree_cache[$tree_cache_key] =
true;
465 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
true, $a_user_id);
473 string $a_permission,
479 if ($a_permission ==
"") {
481 '%s::doRBACCheck(): No operations given! $a_ref_id: %s',
489 if (isset($this->stored_rbac_access[$a_user_id .
"-" . $a_permission .
"-" . $a_ref_id])) {
490 $access = $this->stored_rbac_access[$a_user_id .
"-" . $a_permission .
"-" . $a_ref_id];
492 $access = $this->rbacsystem->checkAccessOfUser($a_user_id, $a_permission, $a_ref_id, $a_type);
493 if (!is_array($this->stored_rbac_access) || count($this->stored_rbac_access) < self::MAX_CACHE_SIZE) {
494 if ($a_permission !=
"create") {
495 $this->stored_rbac_access[$a_user_id .
"-" . $a_permission .
"-" . $a_ref_id] = $access;
501 $this->current_info->addInfoItem(
506 if ($a_permission !=
"create") {
507 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
true, $a_user_id);
516 string $a_permission,
524 if ($a_ref_id ===
$id) {
527 $access = $this->checkAccessOfUser($a_user_id,
"read",
"info",
$id);
528 if ($access ==
false) {
529 $this->current_info->addInfoItem(
534 if ($a_all ==
false) {
546 string $a_permission,
553 $cache_perm = ($a_permission ===
"visible" || $a_permission ===
'leave')
557 if (isset($this->ac_cache[$cache_perm][$a_ref_id][$a_user_id])) {
558 return $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id];
562 if ($a_permission ===
'write') {
567 if ($a_user_id === $this->
user->getId()) {
570 if ($memview->isActiveForRefId($a_ref_id) &&
571 $memview->getContainer() == $a_ref_id) {
577 if ($this->checkAccessOfUser($a_user_id,
"write",
"", $a_ref_id)) {
578 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
584 $this->objDefinition->supportsOfflineHandling($a_type) &&
587 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
false;
592 if ($item_data ===
null || (is_array($item_data) && count($item_data) == 0) ||
594 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
598 if (($item_data[
'timing_start'] == 0 || time() >= $item_data[
'timing_start']) and
599 ($item_data[
'timing_end'] == 0 || time() <= $item_data[
'timing_end'])) {
600 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
605 if ($this->checkAccessOfUser($a_user_id,
"write",
"", $a_ref_id)) {
606 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
611 if (($a_permission ===
'visible' || $a_permission ===
'leave')
612 && $item_data[
'visible']) {
613 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
618 if ($a_permission ==
'read_learning_progress') {
619 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
623 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
false;
631 string $a_permission,
639 ($a_permission ==
'visible') &&
640 !$this->checkAccessOfUser($a_user_id,
"write",
"", $a_ref_id, $a_type, $a_obj_id)
642 if (ilConditionHandler::lookupEffectiveHiddenStatusByTarget($a_ref_id)) {
644 $conditions = ilConditionHandler::_getEffectiveConditionsOfTarget($a_ref_id, $a_obj_id, $a_type);
645 foreach ($conditions as $condition) {
646 $this->current_info->addInfoItem(
648 $this->
getLanguage()->txt(
"missing_precondition") .
": " .
650 $this->
getLanguage()->txt(
"condition_" . $condition[
"operator"]) .
" " .
652 serialize($condition)
660 if (($a_permission ==
"read" or $a_permission ==
'join') &&
661 !$this->checkAccessOfUser($a_user_id,
"write",
"", $a_ref_id, $a_type, $a_obj_id)) {
663 $conditions = ilConditionHandler::_getEffectiveConditionsOfTarget($a_ref_id, $a_obj_id, $a_type);
664 foreach ($conditions as $condition) {
665 $this->current_info->addInfoItem(
667 $this->
getLanguage()->txt(
"missing_precondition") .
": " .
669 $this->
getLanguage()->txt(
"condition_" . $condition[
"operator"]) .
" " .
671 serialize($condition)
684 string $a_permission,
692 if ($this->objDefinition->isPluginTypeName($a_type) && !$this->objDefinition->isPlugin($a_type)) {
699 $class = $this->objDefinition->getClassName($a_type);
700 $location = $this->objDefinition->getLocation($a_type);
701 $full_class =
"ilObj" . $class .
"Access";
704 if ($this->objDefinition->isPluginTypeName($a_type)) {
706 include_once(
$location .
"/class." . $full_class .
".php");
710 $this->ac_logger->error(
"Cannot find class for object type $a_type, obj id $a_obj_id, ref id $a_ref_id. Abort status check.");
714 $full_class =
new $full_class();
716 $obj_access = call_user_func(
717 array($full_class,
"_checkAccess"),
724 if ($obj_access !==
true) {
728 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
731 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
true, $a_user_id);
740 $this->results = array();
741 $this->last_result = [];
743 $this->stored_rbac_access = [];
750 public function enable(
string $a_str,
bool $a_bool): void
752 $this->$a_str = $a_bool;
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
$location
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...
const IL_MISSING_PRECONDITION
const IL_NO_PARENT_ACCESS
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
enable(string $a_str, bool $a_bool)
@deprected
array $stored_rbac_access
hasUserRBACorAnyPositionAccess(string $rbac_perm, int $ref_id)
isCurrentUserBasedOnPositionsAllowedTo(string $permission, array $on_user_ids)
bool getAvailablePositionRelatedPermissions for available permissions
addInfoItem(string $a_type, string $a_text, string $a_data="")
add an info item to current info object
checkRbacOrPositionPermissionAccess(string $rbac_perm, string $pos_perm, int $ref_id)
bool
filterUserIdsByPositionOfUser(int $user_id, string $pos_perm, int $ref_id, array $user_ids)
int[] getAvailablePositionRelatedPermissions for available permissions
doPathCheck(string $a_permission, string $a_cmd, int $a_ref_id, int $a_user_id, bool $a_all=false)
check read permission for all parents
filterUserIdsByPositionOfCurrentUser(string $pos_perm, int $ref_id, array $user_ids)
int[] getAvailablePositionRelatedPermissions for available permissions
storeAccessResult(string $a_permission, string $a_cmd, int $a_ref_id, bool $a_access_granted, ?int $a_user_id=null, ?ilAccessInfo $a_info=null)
store access result
doConditionCheck(string $a_permission, string $a_cmd, int $a_ref_id, int $a_user_id, int $a_obj_id, string $a_type)
condition check (currently only implemented for read permission)
filterUserIdsByRbacOrPositionOfCurrentUser(string $rbac_perm, string $pos_perm, int $ref_id, array $user_ids)
int[]
doRBACCheck(string $a_permission, string $a_cmd, int $a_ref_id, int $a_user_id, string $a_type)
rbac check for current object -> type is used for create permission
getResultLast()
get last info object
checkPositionAccess(string $pos_perm, int $ref_id)
bool getAvailablePositionRelatedPermissions for available permissions
array $current_result_element
getPreventCachingLastResult()
Get prevent caching last result.
bool $prevent_caching_last_result
ilAccessInfo $current_info
doCacheCheck(string $a_permission, string $a_cmd, int $a_ref_id, int $a_user_id)
look if result for current query is already in cachearray<{hit: bool, granted: bool,...
doActivationCheck(string $a_permission, string $a_cmd, int $a_ref_id, int $a_user_id, int $a_obj_id, string $a_type)
check for activation and centralized offline status.
getResultAll(int $a_ref_id=0)
ilObjectDefinition $objDefinition
filterUserIdsForCurrentUsersPositionsAndPermission(array $user_ids, string $permission)
int[] Filtered List of ILIAS-User-IDs ilOrgUnitAccessException when a unknown permission is used....
doStatusCheck(string $a_permission, string $a_cmd, int $a_ref_id, int $a_user_id, int $a_obj_id, string $a_type)
object type specific check
hasCurrentUserAnyPositionAccess(int $ref_id)
bool
setResults(array $a_results)
checkAccessOfUser(int $a_user_id, string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=0, ?int $a_tree_id=0)
check access for an object (provide $a_type and $a_obj_id if available for better performance)
isUserBasedOnPositionsAllowedTo(int $which_user_id, string $permission, array $on_user_ids)
bool getAvailablePositionRelatedPermissions for available permissions
ilOrgUnitPositionAccess $ilOrgUnitPositionAccess
checkAccess(string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=null, ?int $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance)
filterUserIdsForUsersPositionsAndPermission(array $user_ids, int $for_user_id, string $permission)
int[] Filtered List of ILIAS-User-IDs ilOrgUnitAccessException when a unknown permission is used....
getInfo()
get last info objectilAccessInfo::getInfoItems()
doTreeCheck(string $a_permission, string $a_cmd, int $a_ref_id, int $a_user_id)
check if object is in tree and not deleted
setPreventCachingLastResult(bool $a_val)
Set prevent caching last result.
getStoredAccessResult(string $a_permission, string $a_cmd, int $a_ref_id, ?int $a_user_id=null)
get stored access resultarray<{granted: bool, info: ?ilAccessInfo, prevent_db_cache: bool}>
static _checkAllConditionsOfTarget(int $a_target_ref_id, int $a_target_id, string $a_target_type="", int $a_usr_id=0)
checks wether all conditions of a target object are fulfilled
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
static getItem(int $ref_id)
parses the objects.xml it handles the xml-description of all ilias objects
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static lookupOfflineStatus(int $obj_id)
Lookup offline status using objectDataCache.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
filterUserIdsByRbacOrPositionOfCurrentUser(string $rbac_perm, string $pos_perm, int $ref_id, array $user_ids)
isUserBasedOnPositionsAllowedTo(int $which_user_id, string $permission, array $on_user_ids)
filterUserIdsByPositionOfCurrentUser(string $pos_perm, int $ref_id, array $user_ids)
isCurrentUserBasedOnPositionsAllowedTo(string $permission, array $on_user_ids)
hasUserRBACorAnyPositionAccess(string $rbac_perm, int $ref_id)
hasCurrentUserAnyPositionAccess(int $ref_id)
checkRbacOrPositionPermissionAccess(string $rbac_perm, string $pos_perm, int $ref_id)
checkPositionAccess(string $pos_perm, int $ref_id)
filterUserIdsForCurrentUsersPositionsAndPermission(array $user_ids, string $permission)
filterUserIdsForUsersPositionsAndPermission(array $user_ids, int $for_user_id, string $permission)
filterUserIdsByPositionOfUser(int $user_id, string $pos_perm, int $ref_id, array $user_ids)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...