24 require_once(
"Services/AccessControl/classes/class.ilAccessInfo.php");
49 $this->rbacsystem =& $rbacsystem;
50 $this->results = array();
57 $this->condition =
true;
60 $this->obj_id_cache = array();
61 $this->obj_type_cache = array();
62 $this->obj_tree_cache=array();
75 function storeAccessResult($a_permission, $a_cmd, $a_ref_id, $a_access_granted, $a_user_id =
"",$a_info =
"")
81 $a_user_id = $ilUser->getId();
86 $a_info = $this->current_info;
93 $this->results[$a_ref_id][$a_permission][$a_cmd][$a_user_id] =
94 array(
"granted" => $a_access_granted,
"info" => $a_info);
96 $this->current_result_element = array($a_access_granted,$a_ref_id,$a_permission,$a_cmd,$a_user_id);
97 $this->last_result = $this->results[$a_ref_id][$a_permission][$a_cmd][$a_user_id];
98 $this->last_info = $a_info;
123 if ($a_user_id ==
"")
125 $a_user_id = $ilUser->getId();
133 return $this->results[$a_ref_id][$a_permission][$a_cmd][$a_user_id];
138 global $ilDB, $ilUser;
140 $q =
"REPLACE INTO acc_cache (user_id, time, result) VALUES ".
141 "(".$ilDB->quote($ilUser->getId()).
",".time().
",".
142 $ilDB->quote(serialize($this->results)).
")";
148 global $ilUser, $ilDB;
152 $q =
"SELECT * FROM acc_cache WHERE user_id = ".
153 $ilDB->quote($ilUser->getId());
154 $set = $ilDB->query($q);
156 if ((time() - $rec[
"time"]) < $a_secs)
158 $this->results = unserialize($rec[
"result"]);
173 $this->results = $a_results;
181 $this->current_info->addInfoItem($a_type, $a_text, $a_data);
196 function checkAccess($a_permission, $a_cmd, $a_ref_id, $a_type =
"", $a_obj_id =
"", $a_tree_id=
"")
200 return $this->
checkAccessOfUser($ilUser->getId(),$a_permission, $a_cmd, $a_ref_id, $a_type, $a_obj_id, $a_tree_id);
216 function checkAccessOfUser($a_user_id,$a_permission, $a_cmd, $a_ref_id, $a_type =
"", $a_obj_id =
"", $a_tree_id=
"")
220 $ilBench->start(
"AccessControl",
"0400_clear_info");
221 $this->current_info->clear();
222 $ilBench->stop(
"AccessControl",
"0400_clear_info");
225 $cached = $this->
doCacheCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id);
229 if (!$cached[
"granted"])
231 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
233 return $cached[
"granted"];
236 $ilBench->start(
"AccessControl",
"0500_lookup_id_and_type");
240 if ($this->obj_id_cache[$a_ref_id] > 0)
242 $a_obj_id = $this->obj_id_cache[$a_ref_id];
247 $this->obj_id_cache[$a_ref_id] = $a_obj_id;
252 if ($this->obj_type_cache[$a_ref_id] !=
"")
254 $a_type = $this->obj_type_cache[$a_ref_id];
259 $this->obj_type_cache[$a_ref_id] = $a_type;
262 $ilBench->stop(
"AccessControl",
"0500_lookup_id_and_type");
268 if ($a_tree_id != 1 &&
269 !$this->
doTreeCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id))
271 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
277 if (!$this->
doRBACCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id))
279 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
285 $par_check = $this->
doPathCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id);
294 if (!$this->
doConditionCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_obj_id, $a_type))
296 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
302 if (!$this->
doStatusCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_obj_id, $a_type))
304 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
322 return is_object($this->last_info) ? $this->last_info->getInfoItems() : array();
330 return $this->last_result;
340 return $this->results[$a_ref_id];
352 $ilBench->start(
"AccessControl",
"1000_checkAccess_get_cache_result");
355 if (is_array($stored_access))
358 $this->current_info = $stored_access[
"info"];
360 $ilBench->stop(
"AccessControl",
"1000_checkAccess_get_cache_result");
361 return array(
"hit" =>
true,
"granted" => $stored_access[
"granted"]);
365 $ilBench->stop(
"AccessControl",
"1000_checkAccess_get_cache_result");
366 return array(
"hit" =>
false,
"granted" =>
false);
373 function doTreeCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id)
379 $tree_cache_key = $a_user_id.
':'.$a_ref_id;
380 if (array_key_exists($tree_cache_key, $this->obj_tree_cache)) {
382 if (!$this->obj_tree_cache[$tree_cache_key])
384 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
386 $this->
storeAccessResult($a_permission, $a_cmd, $a_ref_id, $this->obj_tree_cache[$tree_cache_key], $a_user_id);
388 return $this->obj_tree_cache[$tree_cache_key];
391 $ilBench->start(
"AccessControl",
"2000_checkAccess_in_tree");
393 if(!$tree->isInTree($a_ref_id) or $tree->isDeleted($a_ref_id))
399 if (count($this->obj_tree_cache) < 1000)
401 $this->obj_tree_cache[$tree_cache_key] =
false;
405 $this->current_info->addInfoItem(
IL_DELETED, $lng->txt(
"object_deleted"));
408 $ilBench->stop(
"AccessControl",
"2000_checkAccess_in_tree");
417 if (count($this->obj_tree_cache) < 1000)
419 $this->obj_tree_cache[$tree_cache_key] =
true;
425 $ilBench->stop(
"AccessControl",
"2000_checkAccess_in_tree");
433 function doRBACCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id)
437 $ilBench->start(
"AccessControl",
"2500_checkAccess_rbac_check");
439 if ($a_permission ==
"")
441 $message = sprintf(
'%s::doRBACCheck(): No operations given! $a_ref_id: %s',
444 $ilLog->write($message,$ilLog->FATAL);
445 $ilErr->raiseError($message,$ilErr->MESSAGE);
448 $access = $this->rbacsystem->checkAccessOfUser($a_user_id, $a_permission, $a_ref_id);
453 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
456 $ilBench->stop(
"AccessControl",
"2500_checkAccess_rbac_check");
465 function doPathCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_all =
false)
470 $ilBench->start(
"AccessControl",
"3100_checkAccess_check_parents_get_path");
471 $path = $tree->getPathId($a_ref_id);
472 $ilBench->stop(
"AccessControl",
"3100_checkAccess_check_parents_get_path");
474 $tmp_info = $this->current_info;
477 foreach ($path as $id)
479 if ($a_ref_id == $id)
485 if($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($id)) ==
'crs')
495 if ($access ==
false)
519 $ilBench->start(
"AccessControl",
"3150_checkAccess_check_course_activation");
521 $cache_perm = ($a_permission ==
"visible")
527 if (isset($this->ac_cache[$cache_perm][$a_ref_id][$a_user_id]))
529 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
530 return $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id];
534 if($a_permission ==
'write')
536 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
539 include_once
'Modules/Course/classes/class.ilCourseItems.php';
542 if(isset($this->ac_times[$a_ref_id]))
545 $item_data = $this->ac_times[$a_ref_id];
550 $ilLog->write(__METHOD__.
': Error preloading activation times failed.');
552 $item_data = $item_data[$a_ref_id];
559 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
560 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
565 if((time() >= $item_data[
'timing_start']) and
566 (time() <= $item_data[
'timing_end']))
568 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
569 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
576 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
577 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
581 if($a_permission ==
'visible' and $item_data[
'visible'])
583 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
584 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
588 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
false;
589 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
603 include_once(
'Modules/Course/classes/class.ilCourseItems.php');
608 if(!isset($this->ac_times[$ref_id]))
628 if (($a_permission ==
"read" or $a_permission ==
'join') &&
629 !$this->
checkAccessOfUser($a_user_id,
"write",
"", $a_ref_id, $a_type, $a_obj_id))
631 $ilBench->start(
"AccessControl",
"4000_checkAccess_condition_check");
635 foreach ($conditions as $condition)
638 $lng->txt(
"missing_precondition").
": ".
640 $lng->txt(
"condition_".$condition[
"operator"]).
" ".
641 $condition[
"value"], $condition);
643 $ilBench->stop(
"AccessControl",
"4000_checkAccess_condition_check");
646 $ilBench->stop(
"AccessControl",
"4000_checkAccess_condition_check");
656 function doStatusCheck($a_permission, $a_cmd, $a_ref_id,$a_user_id, $a_obj_id, $a_type)
660 $ilBench->start(
"AccessControl",
"5000_checkAccess_object_check");
662 $class = $objDefinition->getClassName($a_type);
663 $location = $objDefinition->getLocation($a_type);
664 $full_class =
"ilObj".$class.
"Access";
665 include_once(
$location.
"/class.".$full_class.
".php");
668 $ilBench->start(
"AccessControl",
"5001_checkAccess_".$full_class.
"_check");
669 $obj_access = call_user_func(array($full_class,
"_checkAccess"),
670 $a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id);
671 $ilBench->stop(
"AccessControl",
"5001_checkAccess_".$full_class.
"_check");
672 if (!($obj_access ===
true))
680 $ilBench->stop(
"AccessControl",
"5000_checkAccess_object_check");
685 $ilBench->stop(
"AccessControl",
"5000_checkAccess_object_check");
691 $this->results = array();
692 $this->last_result =
"";
698 $this->$a_str = $a_bool;