19declare(strict_types=1);
66 $this->
user = $DIC->user();
67 $this->db =
$DIC->database();
68 $this->rbacsystem =
$DIC[
'rbacsystem'];
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];
179 $this->results = $a_results;
185 public function addInfoItem(
string $a_type,
string $a_text,
string $a_data =
""): void
187 $this->current_info->addInfoItem($a_type, $a_text, $a_data);
194 string $a_permission,
198 ?
int $a_obj_id =
null,
199 ?
int $a_tree_id =
null
201 return $this->checkAccessOfUser(
217 string $a_permission,
226 $ilBench =
$DIC[
'ilBench'];
228 $this->setPreventCachingLastResult(
false);
230 $ilBench->start(
"AccessControl",
"0400_clear_info");
231 $this->current_info->clear();
232 $ilBench->stop(
"AccessControl",
"0400_clear_info");
235 $cached = $this->doCacheCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id);
236 if ($cached[
"hit"]) {
238 if (!$cached[
"granted"]) {
241 if ($cached[
"prevent_db_cache"]) {
242 $this->setPreventCachingLastResult(
true);
244 return $cached[
"granted"];
247 $ilBench->start(
"AccessControl",
"0500_lookup_id_and_type");
249 if ($a_obj_id == 0) {
250 if (isset($this->obj_id_cache[$a_ref_id]) && $this->obj_id_cache[$a_ref_id] > 0) {
251 $a_obj_id = $this->obj_id_cache[$a_ref_id];
254 $this->obj_id_cache[$a_ref_id] = $a_obj_id;
258 if (isset($this->obj_type_cache[$a_ref_id]) && $this->obj_type_cache[$a_ref_id] !=
"") {
259 $a_type = $this->obj_type_cache[$a_ref_id];
262 $this->obj_type_cache[$a_ref_id] = $a_type;
266 $ilBench->stop(
"AccessControl",
"0500_lookup_id_and_type");
270 if ($a_tree_id != 1 &&
271 !$this->doTreeCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id)) {
273 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
278 if (!$this->doRBACCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_type)) {
280 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
285 $act_check = $this->doActivationCheck(
296 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
301 $par_check = $this->doPathCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id);
304 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
309 if (!$this->doConditionCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_obj_id, $a_type)) {
311 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
312 $this->setPreventCachingLastResult(
true);
317 if (!$this->doStatusCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_obj_id, $a_type)) {
319 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
320 $this->setPreventCachingLastResult(
true);
325 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
true, $a_user_id);
334 return is_object($this->last_info) ? $this->last_info->getInfoItems() : [];
342 return $this->last_result;
350 if ($a_ref_id ==
"") {
354 return $this->results[$a_ref_id];
360 public function doCacheCheck(
string $a_permission,
string $a_cmd,
int $a_ref_id,
int $a_user_id): array
362 $stored_access = $this->getStoredAccessResult($a_permission, $a_cmd, $a_ref_id, $a_user_id);
365 if ($stored_access !== []) {
366 if (isset($stored_access[
'info']) && $stored_access[
'info'] instanceof
ilAccessInfo) {
367 $this->current_info = $stored_access[
"info"];
372 "granted" => $stored_access[
"granted"],
373 "prevent_db_cache" => $stored_access[
"prevent_db_cache"]
381 "prevent_db_cache" => false
388 public function doTreeCheck(
string $a_permission,
string $a_cmd,
int $a_ref_id,
int $a_user_id): bool
391 $tree_cache_key = $a_user_id .
':' . $a_ref_id;
392 if (array_key_exists($tree_cache_key, $this->obj_tree_cache)) {
394 if (!$this->obj_tree_cache[$tree_cache_key]) {
395 $this->current_info->addInfoItem(
400 $this->storeAccessResult(
404 $this->obj_tree_cache[$tree_cache_key],
408 return $this->obj_tree_cache[$tree_cache_key];
411 if (!$this->
repositoryTree->isInTree($a_ref_id) || $this->repositoryTree->isDeleted($a_ref_id)) {
415 if (count($this->obj_tree_cache) < self::MAX_CACHE_SIZE) {
416 $this->obj_tree_cache[$tree_cache_key] =
false;
421 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
428 if (count($this->obj_tree_cache) < self::MAX_CACHE_SIZE) {
429 $this->obj_tree_cache[$tree_cache_key] =
true;
432 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
true, $a_user_id);
440 string $a_permission,
446 if ($a_permission ==
"") {
448 '%s::doRBACCheck(): No operations given! $a_ref_id: %s',
456 if (isset($this->stored_rbac_access[$a_user_id .
"-" . $a_permission .
"-" . $a_ref_id])) {
457 $access = $this->stored_rbac_access[$a_user_id .
"-" . $a_permission .
"-" . $a_ref_id];
459 $access = $this->rbacsystem->checkAccessOfUser($a_user_id, $a_permission, $a_ref_id, $a_type);
460 if (!is_array($this->stored_rbac_access) || count($this->stored_rbac_access) < self::MAX_CACHE_SIZE) {
461 if ($a_permission !=
"create") {
462 $this->stored_rbac_access[$a_user_id .
"-" . $a_permission .
"-" . $a_ref_id] = $access;
468 $this->current_info->addInfoItem(
473 if ($a_permission !=
"create") {
474 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
true, $a_user_id);
483 string $a_permission,
491 if ($a_ref_id ===
$id) {
494 $access = $this->checkAccessOfUser($a_user_id,
"read",
"info",
$id);
495 if ($access ==
false) {
496 $this->current_info->addInfoItem(
501 if ($a_all ==
false) {
513 string $a_permission,
520 $cache_perm = ($a_permission ===
"visible" || $a_permission ===
'leave')
524 if (isset($this->ac_cache[$cache_perm][$a_ref_id][$a_user_id])) {
525 return $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id];
529 if ($a_permission ===
'write') {
534 if ($a_user_id === $this->
user->getId()) {
537 if ($memview->isActiveForRefId($a_ref_id) &&
538 $memview->getContainer() == $a_ref_id) {
545 $class = $this->objDefinition->getClassName($a_type);
546 $full_class =
"ilObj" . $class .
"Access";
548 $bypass = method_exists($full_class,
'getBypassActivationCheckForPermissions') ?
549 $full_class::getBypassActivationCheckForPermissions() : [
'write'];
551 foreach ($bypass as $permission) {
552 if ($this->checkAccessOfUser($a_user_id, $permission,
"", $a_ref_id)) {
553 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
560 $this->objDefinition->supportsOfflineHandling($a_type) &&
563 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
false;
568 if ($item_data ===
null || (is_array($item_data) && count($item_data) == 0) ||
570 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
574 if (($item_data[
'timing_start'] == 0 || time() >= $item_data[
'timing_start']) and
575 ($item_data[
'timing_end'] == 0 || time() <= $item_data[
'timing_end'])) {
576 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
581 if ($this->checkAccessOfUser($a_user_id,
"write",
"", $a_ref_id)) {
582 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
587 if (($a_permission ===
'visible' || $a_permission ===
'leave')
588 && $item_data[
'visible']) {
589 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
594 if ($a_permission ==
'read_learning_progress') {
595 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
599 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
false;
607 string $a_permission,
615 ($a_permission ==
'visible') &&
616 !$this->checkAccessOfUser($a_user_id,
"write",
"", $a_ref_id, $a_type, $a_obj_id)
618 if (ilConditionHandler::lookupEffectiveHiddenStatusByTarget($a_ref_id)) {
620 $conditions = ilConditionHandler::_getEffectiveConditionsOfTarget($a_ref_id, $a_obj_id, $a_type);
621 foreach ($conditions as $condition) {
622 $this->current_info->addInfoItem(
624 $this->
getLanguage()->txt(
"missing_precondition") .
": " .
626 $this->
getLanguage()->txt(
"condition_" . $condition[
"operator"]) .
" " .
628 serialize($condition)
636 if (($a_permission ==
"read" or $a_permission ==
'join') &&
637 !$this->checkAccessOfUser($a_user_id,
"write",
"", $a_ref_id, $a_type, $a_obj_id)) {
639 $conditions = ilConditionHandler::_getEffectiveConditionsOfTarget($a_ref_id, $a_obj_id, $a_type);
640 foreach ($conditions as $condition) {
641 $this->current_info->addInfoItem(
643 $this->
getLanguage()->txt(
"missing_precondition") .
": " .
645 $this->
getLanguage()->txt(
"condition_" . $condition[
"operator"]) .
" " .
647 serialize($condition)
660 string $a_permission,
668 if ($this->objDefinition->isPluginTypeName($a_type) && !$this->objDefinition->isPlugin($a_type)) {
675 $class = $this->objDefinition->getClassName($a_type);
676 $location = $this->objDefinition->getLocation($a_type);
677 $full_class =
"ilObj" . $class .
"Access";
680 $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.");
684 $full_class =
new $full_class();
686 $obj_access = call_user_func(
687 [$full_class,
"_checkAccess"],
694 if ($obj_access !==
true) {
698 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
701 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
true, $a_user_id);
711 $this->last_result = [];
713 $this->stored_rbac_access = [];
720 public function enable(
string $a_str,
bool $a_bool): void
722 $this->$a_str = $a_bool;
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
const IL_MISSING_PRECONDITION
const IL_NO_PARENT_ACCESS
Class ilAccessHandler Checks access for ILIAS objects.
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)
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
if(!file_exists('../ilias.ini.php'))