3 declare(strict_types=1);
64 $this->
user = $DIC->user();
65 $this->db = $DIC->database();
66 $this->review = $DIC->rbac()->review();
67 $this->objectDataCache = $DIC[
'ilObjDataCache'];
68 $this->tree = $DIC->repositoryTree();
69 $this->
http = $DIC->http();
75 if (self::$instance === null) {
76 self::$instance =
new self();
78 return self::$instance;
86 self::$user_role_cache = [];
88 self::$_checkAccessOfUserCache = [];
108 public function checkAccess(
string $a_operations,
int $a_ref_id,
string $a_type =
""): bool
113 public function checkAccessOfUser(
int $a_user_id,
string $a_operations,
int $a_ref_id,
string $a_type =
""): bool
116 $cacheKey = $a_user_id .
':' . $a_operations .
':' . $a_ref_id .
':' . $a_type;
119 if (!is_array(self::$_checkAccessOfUserCache)) {
120 self::$_checkAccessOfUserCache = [];
123 if (array_key_exists($cacheKey, self::$_checkAccessOfUserCache)) {
124 return self::$_checkAccessOfUserCache[$cacheKey];
134 if (count(self::$_checkAccessOfUserCache) < self::MAX_CACHE_ENTRIES) {
135 self::$_checkAccessOfUserCache[$cacheKey] =
true;
147 if (count(self::$_checkAccessOfUserCache) < self::MAX_CACHE_ENTRIES) {
148 self::$_checkAccessOfUserCache[$cacheKey] =
true;
154 $paCacheKey = $a_user_id .
':' . $a_ref_id;
155 if (!is_array(self::$_paCache)) {
156 self::$_paCache = array();
159 if (array_key_exists($paCacheKey, self::$_paCache)) {
161 $ops = self::$_paCache[$paCacheKey];
164 $q =
"SELECT * FROM rbac_pa " .
165 "WHERE ref_id = " . $this->db->quote($a_ref_id,
'integer');
167 $r = $this->db->query($q);
171 if (in_array((
int) $row->rol_id, $roles)) {
172 $ops = array_merge($ops, unserialize(stripslashes($row->ops_id)));
176 if (count(self::$_paCache) < self::MAX_CACHE_ENTRIES) {
177 self::$_paCache[$paCacheKey] = $ops;
181 $operations = explode(
",", $a_operations);
182 foreach ($operations as $operation) {
183 if ($operation ==
"create") {
184 if (empty($a_type)) {
186 'checkAccess(): ' .
"Expect a type definition for checking a 'create' permission" 193 if (!in_array($ops_id, (array) $ops)) {
194 if (count(self::$_checkAccessOfUserCache) < self::MAX_CACHE_ENTRIES) {
195 self::$_checkAccessOfUserCache[$cacheKey] =
false;
203 if (count(self::$_checkAccessOfUserCache) < self::MAX_CACHE_ENTRIES) {
205 self::$_checkAccessOfUserCache[$cacheKey] =
true;
214 foreach ($a_ref_ids as
$ref_id) {
215 if (!isset(self::$_paCache[$a_user_id .
":" . $ref_id])) {
222 if ($ref_ids !== []) {
224 $q =
"SELECT * FROM rbac_pa " .
225 "WHERE " . $this->db->in(
"ref_id", $ref_ids,
false,
"integer");
227 $r = $this->db->query($q);
230 if (in_array($row->rol_id, $roles[(
int) $row->ref_id])) {
231 $ops[(
int) $row->ref_id] = array_merge(
232 $ops[(
int) $row->ref_id],
233 unserialize(stripslashes($row->ops_id))
237 foreach ($a_ref_ids as $ref_id) {
239 if (!isset(self::$_paCache[$a_user_id .
":" . $ref_id])) {
249 public function checkPermission(
int $a_ref_id,
int $a_rol_id,
string $a_operation): bool
252 $query =
'SELECT ops_id FROM rbac_operations ' .
253 'WHERE operation = ' . $this->db->quote($a_operation,
'text');
256 while ($row = $this->db->fetchObject(
$res)) {
257 $ops_id = (
int) $row->ops_id;
260 $query =
"SELECT * FROM rbac_pa " .
261 "WHERE rol_id = " . $this->db->quote($a_rol_id,
'integer') .
" " .
262 "AND ref_id = " . $this->db->quote($a_ref_id,
'integer') .
" ";
265 while ($row = $this->db->fetchObject(
$res)) {
266 $ops = array_merge($ops, unserialize($row->ops_id));
268 return in_array($ops_id, $ops);
274 if (($this->mem_view[
'active'] ?? null) and $a_user_id == $this->
user->getId()) {
275 if (in_array($a_ref_id, $this->mem_view[
'items'])) {
276 return $a_operations;
280 if ($a_user_id != $this->objectDataCache->lookupOwner($this->objectDataCache->lookupObjId($a_ref_id))) {
281 return $a_operations;
285 foreach (explode(
",", $a_operations) as $operation) {
286 if ($operation !=
'cat_administrate_users' &&
287 $operation !=
'edit_permission' &&
288 $operation !=
'edit_learning_progress' &&
289 $operation !=
'read_learning_progress' &&
290 !preg_match(
'/^create/', $operation) &&
291 $operation !=
'read_outcomes' 295 if (!strlen($new_ops)) {
296 $new_ops = $operation;
298 $new_ops .= (
',' . $operation);
311 if (isset($this->mem_view[
'active']) && $this->mem_view[
'active'] && $a_usr_id == $this->
user->getId()) {
313 if (in_array($a_ref_id, $this->mem_view[
'items']) && $this->mem_view[
'role']) {
315 return [$this->mem_view[
'role']];
319 if (isset(self::$user_role_cache[$a_usr_id]) and is_array(self::$user_role_cache)) {
320 return self::$user_role_cache[$a_usr_id];
322 return self::$user_role_cache[$a_usr_id] = $this->review->assignedRoles($a_usr_id);
328 $member_view_activation = null;
329 if ($this->
http->wrapper()->query()->has(
'mv')) {
330 $member_view_activation = $this->
http->wrapper()->query()->retrieve(
336 if ($this->
http->wrapper()->query()->has(
'ref_id')) {
337 $ref_id = $this->
http->wrapper()->query()->retrieve(
342 if ($member_view_activation ===
true) {
348 if ($member_view_activation ===
false) {
352 $this->mem_view[
'active'] =
false;
353 $this->mem_view[
'items'] = [];
354 $this->mem_view[
'role'] = 0;
356 $this->mem_view[
'active'] =
true;
357 $this->mem_view[
'items'] = $this->tree->getSubTreeIds(
$settings->getContainer());
358 $this->mem_view[
'items'] = array_merge($this->mem_view[
'items'], array(
$settings->getContainer()));
365 if (!in_array($a_role_id, self::$user_role_cache[$a_usr_id])) {
366 self::$user_role_cache[$a_usr_id][] = $a_role_id;
372 $paCacheKey = $a_usr_id .
':' . $a_ref_id;
373 unset(self::$_paCache[$paCacheKey]);
Interface GlobalHttpState.
preloadRbacPaCache(array $a_ref_ids, int $a_user_id)
filterOwnerPermissions(int $a_user_id, string $a_operations, int $a_ref_id)
static getDefaultMemberRole(int $a_ref_id)
static resetCaches()
Reset internal caches.
checkAccessOfUser(int $a_user_id, string $a_operations, int $a_ref_id, string $a_type="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkPermission(int $a_ref_id, int $a_rol_id, string $a_operation)
check if a specific role has the permission '$a_operation' of an object
checkAccess(string $a_operations, int $a_ref_id, string $a_type="")
checkAccess represents the main method of the RBAC-system in ILIAS3 developers want to use With this ...
static http()
Fetches the global http state from ILIAS.
addTemporaryRole(int $a_usr_id, int $a_role_id)
ilObjectDataCache $objectDataCache
static ilRbacSystem $instance
static _getOperationIdByName(string $a_operation)
get operation id by name of operation
static array $_checkAccessOfUserCache
resetPACache(int $a_usr_id, int $a_ref_id)
static array $user_role_cache
__construct()
Constructor.
fetchAssignedRoles(int $a_usr_id, int $a_ref_id)
Fetch assigned roles This method caches the assigned roles per user.