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);
283 if (!$this->doRBACCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_type)) {
285 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
290 $act_check = $this->doActivationCheck(
301 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
306 $par_check = $this->doPathCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id);
309 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
314 if (!$this->doConditionCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_obj_id, $a_type)) {
316 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
317 $this->setPreventCachingLastResult(
true);
322 if (!$this->doStatusCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_obj_id, $a_type)) {
324 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
325 $this->setPreventCachingLastResult(
true);
330 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
true, $a_user_id);
339 return is_object($this->last_info) ? $this->last_info->getInfoItems() : [];
347 return $this->last_result;
355 if ($a_ref_id ==
"") {
359 return $this->results[$a_ref_id];
365 public function doCacheCheck(
string $a_permission,
string $a_cmd,
int $a_ref_id,
int $a_user_id): array
367 $stored_access = $this->getStoredAccessResult($a_permission, $a_cmd, $a_ref_id, $a_user_id);
370 if ($stored_access !== []) {
371 if (isset($stored_access[
'info']) && $stored_access[
'info'] instanceof
ilAccessInfo) {
372 $this->current_info = $stored_access[
"info"];
377 "granted" => $stored_access[
"granted"],
378 "prevent_db_cache" => $stored_access[
"prevent_db_cache"]
386 "prevent_db_cache" => false
393 public function doTreeCheck(
string $a_permission,
string $a_cmd,
int $a_ref_id,
int $a_user_id): bool
396 $tree_cache_key = $a_user_id .
':' . $a_ref_id;
397 if (array_key_exists($tree_cache_key, $this->obj_tree_cache)) {
399 if (!$this->obj_tree_cache[$tree_cache_key]) {
400 $this->current_info->addInfoItem(
405 $this->storeAccessResult(
409 $this->obj_tree_cache[$tree_cache_key],
413 return $this->obj_tree_cache[$tree_cache_key];
416 if (!$this->
repositoryTree->isInTree($a_ref_id) || $this->repositoryTree->isDeleted($a_ref_id)) {
420 if (count($this->obj_tree_cache) < self::MAX_CACHE_SIZE) {
421 $this->obj_tree_cache[$tree_cache_key] =
false;
426 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
433 if (count($this->obj_tree_cache) < self::MAX_CACHE_SIZE) {
434 $this->obj_tree_cache[$tree_cache_key] =
true;
437 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
true, $a_user_id);
445 string $a_permission,
451 if ($a_permission ==
"") {
453 '%s::doRBACCheck(): No operations given! $a_ref_id: %s',
457 $this->ac_logger->error($message);
461 if (isset($this->stored_rbac_access[$a_user_id .
"-" . $a_permission .
"-" . $a_ref_id])) {
462 $access = $this->stored_rbac_access[$a_user_id .
"-" . $a_permission .
"-" . $a_ref_id];
464 $access = $this->rbacsystem->checkAccessOfUser($a_user_id, $a_permission, $a_ref_id, $a_type);
465 if (!is_array($this->stored_rbac_access) || count($this->stored_rbac_access) < self::MAX_CACHE_SIZE) {
466 if ($a_permission !=
"create") {
467 $this->stored_rbac_access[$a_user_id .
"-" . $a_permission .
"-" . $a_ref_id] = $access;
473 $this->current_info->addInfoItem(
478 if ($a_permission !=
"create") {
479 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
true, $a_user_id);
488 string $a_permission,
496 if ($a_ref_id ===
$id) {
499 $access = $this->checkAccessOfUser($a_user_id,
"read",
"info",
$id);
500 if ($access ==
false) {
501 $this->current_info->addInfoItem(
506 if ($a_all ==
false) {
518 string $a_permission,
525 $cache_perm = ($a_permission ===
"visible" || $a_permission ===
'leave')
529 if (isset($this->ac_cache[$cache_perm][$a_ref_id][$a_user_id])) {
530 return $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id];
534 if ($a_permission ===
'write') {
539 if ($a_user_id === $this->
user->getId()) {
542 if ($memview->isActiveForRefId($a_ref_id) &&
543 $memview->getContainer() == $a_ref_id) {
550 $class = $this->objDefinition->getClassName($a_type);
551 $full_class =
"ilObj" . $class .
"Access";
553 $bypass = method_exists($full_class,
'getBypassActivationCheckForPermissions') ?
554 $full_class::getBypassActivationCheckForPermissions() : [
'write'];
556 foreach ($bypass as $permission) {
557 if ($this->checkAccessOfUser($a_user_id, $permission,
"", $a_ref_id)) {
558 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
565 $this->objDefinition->supportsOfflineHandling($a_type) &&
568 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
false;
573 if ($item_data ===
null || (is_array($item_data) && count($item_data) == 0) ||
575 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
579 if (($item_data[
'timing_start'] == 0 || time() >= $item_data[
'timing_start']) and
580 ($item_data[
'timing_end'] == 0 || time() <= $item_data[
'timing_end'])) {
581 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
586 if ($this->checkAccessOfUser($a_user_id,
"write",
"", $a_ref_id)) {
587 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
592 if (($a_permission ===
'visible' || $a_permission ===
'leave')
593 && $item_data[
'visible']) {
594 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
599 if ($a_permission ==
'read_learning_progress') {
600 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
604 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
false;
612 string $a_permission,
620 ($a_permission ==
'visible') &&
621 !$this->checkAccessOfUser($a_user_id,
"write",
"", $a_ref_id, $a_type, $a_obj_id)
625 $conditions = ilConditionHandler::_getEffectiveConditionsOfTarget($a_ref_id, $a_obj_id, $a_type);
626 foreach ($conditions as $condition) {
627 $this->current_info->addInfoItem(
629 $this->
getLanguage()->txt(
"missing_precondition") .
": " .
631 $this->
getLanguage()->txt(
"condition_" . $condition[
"operator"]) .
" " .
633 serialize($condition)
641 if (($a_permission ==
"read" or $a_permission ==
'join') &&
642 !$this->checkAccessOfUser($a_user_id,
"write",
"", $a_ref_id, $a_type, $a_obj_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)
665 string $a_permission,
673 if ($this->objDefinition->isPluginTypeName($a_type) && !$this->objDefinition->isPlugin($a_type)) {
680 $class = $this->objDefinition->getClassName($a_type);
681 $location = $this->objDefinition->getLocation($a_type);
682 $full_class =
"ilObj" . $class .
"Access";
685 $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.");
689 $full_class =
new $full_class();
691 $obj_access = call_user_func(
692 [$full_class,
"_checkAccess"],
699 if ($obj_access !==
true) {
703 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
false, $a_user_id);
706 $this->storeAccessResult($a_permission, $a_cmd, $a_ref_id,
true, $a_user_id);
716 $this->last_result = [];
718 $this->stored_rbac_access = [];
725 public function enable(
string $a_str,
bool $a_bool): void
727 $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 lookupEffectiveHiddenStatusByTarget(int $a_target_ref_id)
Lookup hidden status (also take container control into account)
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'))