19declare(strict_types=1);
46 public function setBlockedStatus(
int $a_role_id,
int $a_ref_id,
bool $a_blocked_status): void
49 $query =
'UPDATE rbac_fa set blocked = ' . $this->db->quote($a_blocked_status,
'integer') .
' ' .
50 'WHERE rol_id = ' . $this->db->quote($a_role_id,
'integer') .
' ' .
51 'AND parent = ' . $this->db->quote($a_ref_id,
'integer');
52 $this->db->manipulate($query);
61 foreach ($this->rbacreview->assignedRoles($a_usr_id) as $role_id) {
64 $query =
"DELETE FROM rbac_ua WHERE usr_id = " . $this->db->quote($a_usr_id,
'integer');
65 $res = $this->db->manipulate($query);
71 public function deleteRole(
int $a_rol_id,
int $a_ref_id): void
75 throw new DomainException(
'System administrator role is not deletable.');
79 $mapping->deleteRole($a_rol_id);
85 $query =
"DELETE FROM rbac_ua " .
86 "WHERE rol_id = " . $this->db->quote($a_rol_id,
'integer');
87 $res = $this->db->manipulate($query);
90 $query =
"DELETE FROM rbac_pa " .
91 "WHERE rol_id = " . $this->db->quote($a_rol_id,
'integer') .
" ";
92 $res = $this->db->manipulate($query);
103 $query =
'DELETE FROM rbac_templates ' .
104 'WHERE rol_id = ' . $this->db->quote($a_obj_id,
'integer');
105 $res = $this->db->manipulate($query);
107 $query =
'DELETE FROM rbac_fa ' .
108 'WHERE rol_id = ' . $this->db->quote($a_obj_id,
'integer');
109 $res = $this->db->manipulate($query);
120 $this->
logger->notice(
'System administrator role is not deletable.');
125 if ($a_ref_id != 0) {
126 $clause =
'AND parent = ' . $this->db->quote($a_ref_id,
'integer') .
' ';
129 $query =
'DELETE FROM rbac_fa ' .
130 'WHERE rol_id = ' . $this->db->quote($a_rol_id,
'integer') .
' ' .
132 $res = $this->db->manipulate($query);
134 $query =
'DELETE FROM rbac_templates ' .
135 'WHERE rol_id = ' . $this->db->quote($a_rol_id,
'integer') .
' ' .
137 $res = $this->db->manipulate($query);
144 array $a_limited_roles = []
147 $ilAtomQuery = $this->db->buildAtomQuery();
148 $ilAtomQuery->addTableLock(
'rbac_ua');
149 $ilAtomQuery->addQueryCallable(
150 function (
ilDBInterface $ilDB) use (&$ret, $a_role_id, $a_usr_id, $a_limit, $a_limited_roles):
void {
152 $limit_query =
'SELECT COUNT(*) num FROM rbac_ua ' .
153 'WHERE ' .
$ilDB->in(
'rol_id', (array) $a_limited_roles,
false,
'integer');
156 if ($row->num >= $a_limit) {
161 $query =
"INSERT INTO rbac_ua (usr_id, rol_id) " .
163 $ilDB->quote($a_usr_id,
'integer') .
"," .
$ilDB->quote($a_role_id,
'integer') .
174 $this->rbacreview->setAssignedCacheEntry($a_role_id, $a_usr_id,
true);
176 $mapping->assign($a_role_id, $a_usr_id);
184 public function assignUser(
int $a_rol_id,
int $a_usr_id): void
187 $alreadyAssigned = $this->rbacreview->isAssigned($a_usr_id, $a_rol_id);
190 if (!$alreadyAssigned) {
191 $query =
"INSERT INTO rbac_ua (usr_id, rol_id) " .
192 "VALUES (" . $this->db->quote($a_usr_id,
'integer') .
"," . $this->db->quote(
196 $res = $this->db->manipulate($query);
198 $this->rbacreview->setAssignedCacheEntry($a_rol_id, $a_usr_id,
true);
202 $mapping->assign($a_rol_id, $a_usr_id);
204 $ref_id = $this->rbacreview->getObjectReferenceOfRole($a_rol_id);
208 if (!$alreadyAssigned) {
210 $GLOBALS[
'DIC'][
'ilAppEventHandler']->raise(
211 'components/ILIAS/AccessControl',
215 'usr_id' => $a_usr_id,
216 'role_id' => $a_rol_id,
228 $query =
"DELETE FROM rbac_ua " .
229 "WHERE usr_id = " . $this->db->quote($a_usr_id,
'integer') .
" " .
230 "AND rol_id = " . $this->db->quote($a_rol_id,
'integer') .
" ";
231 $res = $this->db->manipulate($query);
233 $this->rbacreview->setAssignedCacheEntry($a_rol_id, $a_usr_id,
false);
236 $mapping->deassign($a_rol_id, $a_usr_id);
239 $ref_id =
$GLOBALS[
'DIC'][
'rbacreview']->getObjectReferenceOfRole($a_rol_id);
244 $GLOBALS[
'DIC'][
'ilAppEventHandler']->raise(
'components/ILIAS/AccessControl',
'deassignUser', [
246 'usr_id' => $a_usr_id,
247 'role_id' => $a_rol_id,
265 foreach ($a_ops as $key => $operation) {
266 $a_ops[$key] = (
int) $operation;
269 $ops_ids = serialize($a_ops);
271 $query =
'DELETE FROM rbac_pa ' .
272 'WHERE rol_id = %s ' .
274 $res = $this->db->queryF(
276 [
'integer',
'integer'],
277 [$a_rol_id, $a_ref_id]
284 $query =
"INSERT INTO rbac_pa (rol_id,ops_id,ref_id) " .
286 "(" . $this->db->quote($a_rol_id,
'integer') .
"," . $this->db->quote(
289 ) .
"," . $this->db->quote($a_ref_id,
'integer') .
")";
290 $res = $this->db->manipulate($query);
298 public function revokePermission(
int $a_ref_id,
int $a_rol_id = 0,
bool $a_keep_protected =
true): void
306 if ($a_keep_protected !=
true) {
308 $and1 =
" AND rol_id = " . $this->db->quote($a_rol_id,
'integer') .
" ";
313 $query =
"DELETE FROM rbac_pa " .
314 "WHERE ref_id = " . $this->db->quote($a_ref_id,
'integer') .
316 $res = $this->db->manipulate($query);
323 $roles_in_scope = $this->rbacreview->getParentRoleIds($a_ref_id);
328 foreach ($roles_in_scope as $role) {
329 if ($role[
'protected'] ==
true) {
333 $role_ids[] = $role[
'obj_id'];
337 if ($role_ids === []) {
341 $query =
'DELETE FROM rbac_pa ' .
342 'WHERE ' . $this->db->in(
'rol_id', $role_ids,
false,
'integer') .
' ' .
343 'AND ref_id = ' . $this->db->quote($a_ref_id,
'integer');
344 $res = $this->db->manipulate($query);
347 if ($roles_in_scope[$a_rol_id][
'protected'] ==
true) {
351 $query =
"DELETE FROM rbac_pa " .
352 "WHERE ref_id = " . $this->db->quote($a_ref_id,
'integer') .
" " .
353 "AND rol_id = " . $this->db->quote($a_rol_id,
'integer') .
" ";
354 $res = $this->db->manipulate($query);
363 $query =
'DELETE FROM rbac_pa ' .
365 '( ' .
$GLOBALS[
'DIC'][
'tree']->getSubTreeQuery($a_ref_id, [
'child']) .
' ) ' .
366 'AND rol_id = ' . $this->db->quote($a_role_id,
'integer');
368 $this->db->manipulate($query);
376 $query =
'DELETE FROM rbac_templates ' .
377 'WHERE parent IN ( ' .
378 $GLOBALS[
'DIC'][
'tree']->getSubTreeQuery($a_ref_id, [
'child']) .
' ) ' .
379 'AND rol_id = ' . $this->db->quote($a_rol_id,
'integer');
381 $this->db->manipulate($query);
383 $query =
'DELETE FROM rbac_fa ' .
384 'WHERE parent IN ( ' .
385 $GLOBALS[
'DIC'][
'tree']->getSubTreeQuery($a_ref_id, [
'child']) .
' ) ' .
386 'AND rol_id = ' . $this->db->quote($a_rol_id,
'integer');
388 $this->db->manipulate($query);
401 $query =
"DELETE FROM rbac_pa " .
402 "WHERE " . $this->db->in(
'ref_id', $a_ref_ids,
false,
'integer') .
' ' .
403 "AND rol_id = " . $this->db->quote($a_rol_id,
'integer');
404 $res = $this->db->manipulate($query);
412 int $a_source_parent,
415 bool $a_consider_protected =
true
418 $this->copyRoleTemplatePermissions(
423 $a_consider_protected
425 $ops = $this->rbacreview->getRoleOperationsOnObject($a_source_id, $a_source_parent);
427 $this->revokePermission($a_dest_parent, $a_dest_id);
428 $this->grantPermission($a_dest_id, $ops, $a_dest_parent);
437 int $a_source_parent,
440 bool $a_consider_protected =
true
449 $query =
'SELECT * FROM rbac_templates ' .
450 'WHERE rol_id = ' . $this->db->quote($a_source_id,
'integer') .
' ' .
451 'AND parent = ' . $this->db->quote($a_source_parent,
'integer');
452 $res = $this->db->query($query);
455 while ($row = $this->db->fetchObject(
$res)) {
456 $operations[$rownum][
'type'] = $row->type;
457 $operations[$rownum][
'ops_id'] = $row->ops_id;
462 $query =
'DELETE FROM rbac_templates WHERE rol_id = ' . $this->db->quote($a_dest_id,
'integer') .
' ' .
463 'AND parent = ' . $this->db->quote($a_dest_parent,
'integer');
464 $res = $this->db->manipulate($query);
466 foreach ($operations as $op) {
467 $query =
'INSERT INTO rbac_templates (rol_id,type,ops_id,parent) ' .
469 $this->db->quote($a_dest_id,
'integer') .
"," .
470 $this->db->quote($op[
'type'],
'text') .
"," .
471 $this->db->quote($op[
'ops_id'],
'integer') .
"," .
472 $this->db->quote($a_dest_parent,
'integer') .
")";
473 $this->db->manipulate($query);
477 if ($a_consider_protected ==
true) {
478 if ($this->rbacreview->isProtected($a_source_parent, $a_source_id)) {
479 $this->setProtected($a_dest_parent, $a_dest_id,
'y');
490 int $a_source1_parent,
492 int $a_source2_parent,
501 $query =
"SELECT s1.type, s1.ops_id " .
502 "FROM rbac_templates s1, rbac_templates s2 " .
503 "WHERE s1.rol_id = " . $this->db->quote($a_source1_id,
'integer') .
" " .
504 "AND s1.parent = " . $this->db->quote($a_source1_parent,
'integer') .
" " .
505 "AND s2.rol_id = " . $this->db->quote($a_source2_id,
'integer') .
" " .
506 "AND s2.parent = " . $this->db->quote($a_source2_parent,
'integer') .
" " .
507 "AND s1.type = s2.type " .
508 "AND s1.ops_id = s2.ops_id";
510 $res = $this->db->query($query);
514 $operations[$rowNum][
'type'] = $row->type;
515 $operations[$rowNum][
'ops_id'] = $row->ops_id;
521 $query =
'DELETE FROM rbac_templates WHERE rol_id = ' . $this->db->quote($a_dest_id,
'integer') .
' ' .
522 'AND parent = ' . $this->db->quote($a_dest_parent,
'integer');
523 $res = $this->db->manipulate($query);
525 $query =
'INSERT INTO rbac_templates (rol_id,type,ops_id,parent) ' .
527 $sta = $this->db->prepareManip($query, [
'integer',
'text',
'integer',
'integer']);
528 foreach ($operations as $set) {
529 $this->db->execute($sta, [
540 int $a_source1_parent,
542 int $a_source2_parent,
551 $s1_ops = $this->rbacreview->getAllOperationsOfRole($a_source1_id, $a_source1_parent);
552 $s2_ops = $this->rbacreview->getAllOperationsOfRole($a_source2_id, $a_source2_parent);
553 $this->deleteRolePermission($a_dest_id, $a_dest_parent);
555 foreach ($s1_ops as $type => $ops) {
556 foreach ($ops as $op) {
559 $query =
'INSERT INTO rbac_templates (rol_id,type,ops_id,parent) ' .
561 $this->db->quote($a_dest_id,
'integer') .
', ' .
562 $this->db->quote($type,
'text') .
', ' .
563 $this->db->quote($op,
'integer') .
', ' .
564 $this->db->quote($a_dest_parent,
'integer') .
' ' .
566 $this->db->manipulate($query);
571 foreach ($s2_ops as $type => $ops) {
572 foreach ($ops as $op) {
573 if (!isset($s1_ops[$type]) || !in_array($op, $s1_ops[$type])) {
574 $query =
'INSERT INTO rbac_templates (rol_id,type,ops_id,parent) ' .
576 $this->db->quote($a_dest_id,
'integer') .
', ' .
577 $this->db->quote($type,
'text') .
', ' .
578 $this->db->quote($op,
'integer') .
', ' .
579 $this->db->quote($a_dest_parent,
'integer') .
' ' .
581 $this->db->manipulate($query);
592 int $a_source_parent,
600 $s1_ops = $this->rbacreview->getAllOperationsOfRole($a_source_id, $a_source_parent);
601 $d_ops = $this->rbacreview->getAllOperationsOfRole($a_dest_id, $a_dest_parent);
603 foreach ($s1_ops as $type => $ops) {
604 foreach ($ops as $op) {
605 if (isset($d_ops[$type]) && in_array($op, $d_ops[$type])) {
606 $query =
'DELETE FROM rbac_templates ' .
607 'WHERE rol_id = ' . $this->db->quote($a_dest_id,
'integer') .
' ' .
608 'AND type = ' . $this->db->quote($type,
'text') .
' ' .
609 'AND ops_id = ' . $this->db->quote($op,
'integer') .
' ' .
610 'AND parent = ' . $this->db->quote($a_dest_parent,
'integer');
611 $this->db->manipulate($query);
625 ?
string $a_type =
null
632 if ($a_type !==
null) {
633 $and_type =
" AND type=" . $this->db->quote($a_type,
'text') .
" ";
635 $query =
'DELETE FROM rbac_templates ' .
636 'WHERE rol_id = ' . $this->db->quote($a_rol_id,
'integer') .
' ' .
637 'AND parent = ' . $this->db->quote($a_ref_id,
'integer') .
' ' .
639 $res = $this->db->manipulate($query);
646 public function setRolePermission(
int $a_rol_id,
string $a_type, array $a_ops,
int $a_ref_id): void
649 $this->
logger->logStack();
652 foreach ($a_ops as $op) {
656 'rol_id' => [
'integer', $a_rol_id],
657 'type' => [
'text', $a_type],
658 'ops_id' => [
'integer', $op],
659 'parent' => [
'integer', $a_ref_id]
676 string $a_assign =
"y"
683 if ($a_assign !=
"y") {
688 $query =
'SELECT rol_id FROM rbac_fa ' .
689 'WHERE rol_id = ' . $this->db->quote($a_rol_id,
'integer') .
' ' .
690 'AND parent = ' . $this->db->quote($a_parent,
'integer');
691 $res = $this->db->query($query);
692 if (
$res->numRows()) {
696 'INSERT INTO rbac_fa (rol_id, parent, assign, protected) ' .
697 'VALUES (%s,%s,%s,%s)',
698 $this->db->quote($a_rol_id,
'integer'),
699 $this->db->quote($a_parent,
'integer'),
700 $this->db->quote($a_assign,
'text'),
701 $this->db->quote(
'n',
'text')
703 $res = $this->db->manipulate($query);
712 $query =
"INSERT INTO rbac_ta (typ_id, ops_id) " .
713 "VALUES(" . $this->db->quote($a_type_id,
'integer') .
"," . $this->db->quote($a_ops_id,
'integer') .
")";
714 $res = $this->db->manipulate($query);
723 $query =
"DELETE FROM rbac_ta " .
724 "WHERE typ_id = " . $this->db->quote($a_type_id,
'integer') .
" " .
725 "AND ops_id = " . $this->db->quote($a_ops_id,
'integer');
726 $res = $this->db->manipulate($query);
732 public function setProtected(
int $a_ref_id,
int $a_role_id,
string $a_value): void
736 $query =
'UPDATE rbac_fa ' .
737 'SET protected = ' . $this->db->quote($a_value,
'text') .
' ' .
738 'WHERE rol_id = ' . $this->db->quote($a_role_id,
'integer');
739 $res = $this->db->manipulate($query);
750 foreach ($this->rbacreview->getRolesOfRoleFolder($a_source_id,
false) as $role_data) {
752 if (substr($title, 0, 3) ==
'il_') {
755 $real_local[] = $role_data;
757 if ($real_local === []) {
761 foreach ($real_local as $role) {
766 $roleObj->setTitle($orig->getTitle());
767 $roleObj->setDescription($orig->getDescription());
768 $roleObj->setImportId($orig->getImportId());
771 $this->assignRoleToFolder($roleObj->getId(), $a_target_id,
"y");
772 $this->copyRolePermissions($role, $a_source_id, $a_target_id, $roleObj->getId(),
true);
781 int $a_template_parent
783 if ($this->rbacreview->isProtected($a_role_parent, $a_role_id)) {
785 $new_ops = $this->rbacreview->getOperationsOfRole(
792 $this->grantPermission(
799 if (!$a_template_id) {
804 $this->copyRolePermissionIntersection(
814 $this->assignRoleToFolder(
821 $new_ops = $this->rbacreview->getOperationsOfRole(
828 $this->revokePermission($a_ref_id, $a_role_id);
831 $this->grantPermission(
853 $action->setRefId($a_ref_id);
868 $tree =
$DIC[
'tree'];
870 $new_parent = $tree->getParentId($ref_id);
871 $old_context_roles = $this->rbacreview->getParentRoleIds($old_parent,
false);
872 $new_context_roles = $this->rbacreview->getParentRoleIds($new_parent,
false);
879 $tree->useCache(
false);
881 $for_addition = $for_deletion = [];
882 foreach ($new_context_roles as $new_role_id => $new_role) {
883 if (!isset($old_context_roles[$new_role_id])) {
884 $for_addition[] = $new_role_id;
885 } elseif ($new_role[
'parent'] != $old_context_roles[$new_role_id][
'parent']) {
887 $for_deletion[] = $new_role_id;
888 $for_addition[] = $new_role_id;
891 foreach ($old_context_roles as $old_role_id => $old_role) {
892 if (!isset($new_context_roles[$old_role_id])) {
893 $for_deletion[] = $old_role_id;
896 if ($for_deletion === [] && $for_addition === []) {
897 $this->applyMovedObjectDidacticTemplates($ref_id, $old_parent);
902 if ($rbac_log_active) {
903 $role_ids = array_unique(array_merge(array_keys($for_deletion), array_keys($for_addition)));
906 foreach ($tree->getSubTree($tree->getNodeData($ref_id),
true) as $node_data) {
907 $node_id = (
int) $node_data[
'child'];
908 if ($rbac_log_active) {
915 if (!($node_data[
'type'] ??
false)) {
922 foreach ($for_deletion as $role_id) {
923 $this->deleteLocalRole($role_id, $node_id);
924 $this->revokePermission($node_id, $role_id,
false);
926 foreach ($for_addition as $role_id) {
927 $role_parent_id = $this->rbacreview->getParentOfRole($role_id, $ref_id);
928 switch ($node_data[
'type']) {
932 $this->initIntersectionPermissions(
943 $this->initIntersectionPermissions(
953 $this->grantPermission(
955 $this->rbacreview->getOperationsOfRole($role_id, $node_data[
'type'], $role_parent_id),
962 if ($rbac_log_active) {
974 $this->applyMovedObjectDidacticTemplates($ref_id, $old_parent);
static getActionsByTemplateId(int $a_tpl_id)
Get actions of one template.
represents a creation of local roles action
static lookupTemplateId(int $a_ref_id)
static _getInstance()
Get singleton instance of this class.
static getLogger(string $a_component_id)
Get component logger.
static lookupCourseNonMemberTemplatesId()
static lookupGroupStatusTemplateId(int $a_obj_id)
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
Class ilRbacAdmin Core functions for role based access control.
setBlockedStatus(int $a_role_id, int $a_ref_id, bool $a_blocked_status)
removeUser(int $a_usr_id)
deletes a user from rbac_ua all user <-> role relations are deleted
copyRolePermissionUnion(int $a_source1_id, int $a_source1_parent, int $a_source2_id, int $a_source2_parent, int $a_dest_id, int $a_dest_parent)
assignOperationToObject(int $a_type_id, int $a_ops_id)
Assign an existing operation to an object Update of rbac_ta.
applyMovedObjectDidacticTemplates(int $a_ref_id, int $a_old_parent)
Apply didactic templates after object movement.
__construct(protected ilDBInterface $db, protected ilRbacReview $rbacreview, protected LoggerInterface $logger)
Constructor @access public.
adjustMovedObjectPermissions(int $ref_id, int $old_parent)
Adjust permissions of moved objects.
setProtected(int $a_ref_id, int $a_role_id, string $a_value)
Set protected.
deassignOperationFromObject(int $a_type_id, int $a_ops_id)
Deassign an existing operation from an object Update of rbac_ta.
deassignUser(int $a_rol_id, int $a_usr_id)
Deassigns a user from a role.
deleteSubtreeTemplates(int $a_ref_id, int $a_rol_id)
Delete all template permissions of subtree nodes.
copyRolePermissionSubtract(int $a_source_id, int $a_source_parent, int $a_dest_id, int $a_dest_parent)
Subtract role permissions.
assignRoleToFolder(int $a_rol_id, int $a_parent, string $a_assign="y")
Assigns a role to a role folder A role folder is an object to store roles.
deleteRolePermission(int $a_rol_id, int $a_ref_id, ?string $a_type=null)
Deletes all entries of a template.
deleteLocalRole(int $a_rol_id, int $a_ref_id=0)
Deletes a local role and entries in rbac_fa and rbac_templates.
revokeSubtreePermissions(int $a_ref_id, int $a_role_id)
Revoke subtree permissions.
initIntersectionPermissions(int $a_ref_id, int $a_role_id, int $a_role_parent, int $a_template_id, int $a_template_parent)
copyRolePermissionIntersection(int $a_source1_id, int $a_source1_parent, int $a_source2_id, int $a_source2_parent, int $a_dest_parent, int $a_dest_id)
Copies the intersection of the template permissions of two roles to a third role.
copyLocalRoles(int $a_source_id, int $a_target_id)
Copy local roles This method creates a copy of all local role.
revokePermissionList(array $a_ref_ids, int $a_rol_id)
Revokes permissions of a LIST of objects of ONE role.
deleteRole(int $a_rol_id, int $a_ref_id)
Deletes a role and deletes entries in rbac_pa, rbac_templates, rbac_ua, rbac_fa.
revokePermission(int $a_ref_id, int $a_rol_id=0, bool $a_keep_protected=true)
Revokes permissions of an object of one role.
copyRoleTemplatePermissions(int $a_source_id, int $a_source_parent, int $a_dest_parent, int $a_dest_id, bool $a_consider_protected=true)
Copies template permissions of one role to another.
setRolePermission(int $a_rol_id, string $a_type, array $a_ops, int $a_ref_id)
Inserts template permissions in rbac_templates for an specific object type.
deleteTemplate(int $a_obj_id)
Deletes a template from role folder and deletes all entries in rbac_templates, rbac_fa.
copyRolePermissions(int $a_source_id, int $a_source_parent, int $a_dest_parent, int $a_dest_id, bool $a_consider_protected=true)
Copies template permissions and permission of one role to another.
grantPermission(int $a_rol_id, array $a_ops, int $a_ref_id)
Grants a permission to an object and a specific role.
assignUserLimited(int $a_role_id, int $a_usr_id, int $a_limit, array $a_limited_roles=[])
assignUser(int $a_rol_id, int $a_usr_id)
Assigns an user to a role.
static add(int $action, int $ref_id, array $diff, bool $source_ref_id=false)
static gatherFaPa(int $ref_id, array $role_ids, bool $add_action=false)
static diffFaPa(array $old, array $new)
class ilRbacReview Contains Review functions of core Rbac.
foreach($_POST as $key=> $value) $res
if(!file_exists('../ilias.ini.php'))