4 require_once(
"Services/AccessControl/classes/class.ilAccessInfo.php");
27 global $rbacsystem,
$lng;
29 $this->rbacsystem =& $rbacsystem;
30 $this->results = array();
37 $this->condition =
true;
40 $this->obj_id_cache = array();
41 $this->obj_type_cache = array();
42 $this->obj_tree_cache=array();
55 function storeAccessResult($a_permission, $a_cmd, $a_ref_id, $a_access_granted, $a_user_id =
"",$a_info =
"")
61 $a_user_id = $ilUser->getId();
66 $a_info = $this->current_info;
73 $this->results[$a_ref_id][$a_permission][$a_cmd][$a_user_id] =
74 array(
"granted" => $a_access_granted,
"info" => $a_info,
77 $this->current_result_element = array($a_access_granted,$a_ref_id,$a_permission,$a_cmd,$a_user_id);
78 $this->last_result = $this->results[$a_ref_id][$a_permission][$a_cmd][$a_user_id];
79 $this->last_info = $a_info;
94 $this->prevent_caching_last_result = $a_val;
104 return $this->prevent_caching_last_result;
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 $query =
"DELETE FROM acc_cache WHERE user_id = ".$ilDB->quote($ilUser->getId(),
'integer');
143 $ilDB->insert(
'acc_cache', array(
144 'user_id' => array(
'integer',$ilUser->getId()),
145 'time' => array(
'integer',time()),
146 'result' => array(
'clob',serialize($this->results))
152 global $ilUser,
$ilDB;
156 $query =
"SELECT * FROM acc_cache WHERE user_id = ".
157 $ilDB->quote($ilUser->getId() ,
'integer');
158 $set = $ilDB->query(
$query);
160 if ((time() - $rec[
"time"]) < $a_secs)
162 $this->results = unserialize($rec[
"result"]);
177 $this->results = $a_results;
185 $this->current_info->addInfoItem($a_type, $a_text, $a_data);
200 function checkAccess($a_permission, $a_cmd, $a_ref_id, $a_type =
"", $a_obj_id =
"", $a_tree_id=
"")
204 return $this->
checkAccessOfUser($ilUser->getId(),$a_permission, $a_cmd, $a_ref_id, $a_type, $a_obj_id, $a_tree_id);
220 function checkAccessOfUser($a_user_id,$a_permission, $a_cmd, $a_ref_id, $a_type =
"", $a_obj_id =
"", $a_tree_id=
"")
226 $ilBench->start(
"AccessControl",
"0400_clear_info");
227 $this->current_info->clear();
228 $ilBench->stop(
"AccessControl",
"0400_clear_info");
232 $cached = $this->
doCacheCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id);
236 if (!$cached[
"granted"])
238 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
240 if ($cached[
"prevent_db_cache"])
244 return $cached[
"granted"];
247 $ilBench->start(
"AccessControl",
"0500_lookup_id_and_type");
251 if ($this->obj_id_cache[$a_ref_id] > 0)
253 $a_obj_id = $this->obj_id_cache[$a_ref_id];
258 $this->obj_id_cache[$a_ref_id] = $a_obj_id;
263 if ($this->obj_type_cache[$a_ref_id] !=
"")
265 $a_type = $this->obj_type_cache[$a_ref_id];
270 $this->obj_type_cache[$a_ref_id] = $a_type;
274 $ilBench->stop(
"AccessControl",
"0500_lookup_id_and_type");
280 if ($a_tree_id != 1 &&
281 !$this->
doTreeCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id))
283 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
289 if (!$this->
doRBACCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_type))
291 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
297 $par_check = $this->
doPathCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id);
301 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
307 if (!$this->
doConditionCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_obj_id, $a_type))
309 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
316 if (!$this->
doStatusCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_obj_id, $a_type))
318 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
325 if (!$this->
doLicenseCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_obj_id, $a_type))
344 return is_object($this->last_info) ? $this->last_info->getInfoItems() : array();
352 return $this->last_result;
362 return $this->results[$a_ref_id];
374 $ilBench->start(
"AccessControl",
"1000_checkAccess_get_cache_result");
377 if (is_array($stored_access))
379 $this->current_info = $stored_access[
"info"];
381 $ilBench->stop(
"AccessControl",
"1000_checkAccess_get_cache_result");
382 return array(
"hit" =>
true,
"granted" => $stored_access[
"granted"],
383 "prevent_db_cache" => $stored_access[
"prevent_db_cache"]);
387 $ilBench->stop(
"AccessControl",
"1000_checkAccess_get_cache_result");
388 return array(
"hit" =>
false,
"granted" =>
false,
389 "prevent_db_cache" =>
false);
396 function doTreeCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id)
402 $tree_cache_key = $a_user_id.
':'.$a_ref_id;
403 if (array_key_exists($tree_cache_key, $this->obj_tree_cache)) {
405 if (!$this->obj_tree_cache[$tree_cache_key])
407 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
409 $this->
storeAccessResult($a_permission, $a_cmd, $a_ref_id, $this->obj_tree_cache[$tree_cache_key], $a_user_id);
411 return $this->obj_tree_cache[$tree_cache_key];
414 $ilBench->start(
"AccessControl",
"2000_checkAccess_in_tree");
416 if(!$tree->isInTree($a_ref_id) or $tree->isDeleted($a_ref_id))
422 if (count($this->obj_tree_cache) < 1000)
424 $this->obj_tree_cache[$tree_cache_key] =
false;
428 $this->current_info->addInfoItem(
IL_DELETED, $lng->txt(
"object_deleted"));
431 $ilBench->stop(
"AccessControl",
"2000_checkAccess_in_tree");
440 if (count($this->obj_tree_cache) < 1000)
442 $this->obj_tree_cache[$tree_cache_key] =
true;
448 $ilBench->stop(
"AccessControl",
"2000_checkAccess_in_tree");
456 function doRBACCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_type)
460 $ilBench->start(
"AccessControl",
"2500_checkAccess_rbac_check");
462 if ($a_permission ==
"")
464 $message = sprintf(
'%s::doRBACCheck(): No operations given! $a_ref_id: %s',
467 $ilLog->write($message,$ilLog->FATAL);
468 $ilErr->raiseError($message,$ilErr->MESSAGE);
471 if (isset($this->stored_rbac_access[$a_user_id.
"-".$a_permission.
"-".$a_ref_id]))
473 $access = $this->stored_rbac_access[$a_user_id.
"-".$a_permission.
"-".$a_ref_id];
477 $access = $this->rbacsystem->checkAccessOfUser($a_user_id, $a_permission, $a_ref_id, $a_type);
478 if (!is_array($this->stored_rbac_access) || count($this->stored_rbac_access) < 1000)
480 if ($a_permission !=
"create")
482 $this->stored_rbac_access[$a_user_id.
"-".$a_permission.
"-".$a_ref_id] = $access;
490 $this->current_info->addInfoItem(
IL_NO_PERMISSION, $lng->txt(
"status_no_permission"));
492 if ($a_permission !=
"create")
496 $ilBench->stop(
"AccessControl",
"2500_checkAccess_rbac_check");
505 function doPathCheck($a_permission, $a_cmd, $a_ref_id, $a_user_id, $a_all =
false)
510 $ilBench->start(
"AccessControl",
"3100_checkAccess_check_parents_get_path");
518 $path = $tree->getPathId($a_ref_id);
521 $ilBench->stop(
"AccessControl",
"3100_checkAccess_check_parents_get_path");
523 foreach ($path as $id)
525 if ($a_ref_id == $id)
531 if($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($id)) ==
'crs')
541 if ($access ==
false)
565 $ilBench->start(
"AccessControl",
"3150_checkAccess_check_course_activation");
567 $cache_perm = ($a_permission ==
"visible")
573 if (isset($this->ac_cache[$cache_perm][$a_ref_id][$a_user_id]))
575 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
576 return $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id];
580 if($a_permission ==
'write')
582 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
585 include_once
'Modules/Course/classes/class.ilCourseItems.php';
588 if(isset($this->ac_times[$a_ref_id]))
591 $item_data = $this->ac_times[$a_ref_id];
596 $ilLog->write(__METHOD__.
': Error preloading activation times failed.');
598 $item_data = $item_data[$a_ref_id];
605 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
606 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
611 if((time() >= $item_data[
'timing_start']) and
612 (time() <= $item_data[
'timing_end']))
614 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
615 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
622 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
623 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
627 if($a_permission ==
'visible' and $item_data[
'visible'])
629 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
true;
630 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
634 $this->ac_cache[$cache_perm][$a_ref_id][$a_user_id] =
false;
635 $ilBench->stop(
"AccessControl",
"3150_checkAccess_check_course_activation");
649 include_once(
'Modules/Course/classes/class.ilCourseItems.php');
654 if(!isset($this->ac_times[$ref_id]))
674 if (($a_permission ==
"read" or $a_permission ==
'join') &&
675 !$this->
checkAccessOfUser($a_user_id,
"write",
"", $a_ref_id, $a_type, $a_obj_id))
677 $ilBench->start(
"AccessControl",
"4000_checkAccess_condition_check");
681 foreach ($conditions as $condition)
684 $lng->txt(
"missing_precondition").
": ".
686 $lng->txt(
"condition_".$condition[
"operator"]).
" ".
687 $condition[
"value"], $condition);
689 $ilBench->stop(
"AccessControl",
"4000_checkAccess_condition_check");
692 $ilBench->stop(
"AccessControl",
"4000_checkAccess_condition_check");
702 function doStatusCheck($a_permission, $a_cmd, $a_ref_id,$a_user_id, $a_obj_id, $a_type)
706 $ilBench->start(
"AccessControl",
"5000_checkAccess_object_check");
708 $class = $objDefinition->getClassName($a_type);
709 $location = $objDefinition->getLocation($a_type);
710 $full_class =
"ilObj".$class.
"Access";
711 include_once(
$location.
"/class.".$full_class.
".php");
714 $ilBench->start(
"AccessControl",
"5001_checkAccess_".$full_class.
"_check");
715 $obj_access = call_user_func(array($full_class,
"_checkAccess"),
716 $a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id);
717 $ilBench->stop(
"AccessControl",
"5001_checkAccess_".$full_class.
"_check");
718 if (!($obj_access ===
true))
726 $ilBench->stop(
"AccessControl",
"5000_checkAccess_object_check");
731 $ilBench->stop(
"AccessControl",
"5000_checkAccess_object_check");
738 function doLicenseCheck($a_permission, $a_cmd, $a_ref_id,$a_user_id, $a_obj_id, $a_type)
743 if (!in_array($a_type, array(
'sahs',
'htlm'))
744 or !in_array($a_permission, array(
'read')))
750 require_once(
"Services/License/classes/class.ilLicenseAccess.php");
779 $this->current_info->addInfoItem(
IL_NO_LICENSE, $lng->txt(
"no_license_available"));
787 $this->results = array();
788 $this->last_result =
"";
794 $this->$a_str = $a_bool;