ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilShibbolethRoleAssignmentRules.php
Go to the documentation of this file.
1<?php
2
30{
34 public static function getAllRules(): array
35 {
36 global $DIC;
37 $db = $DIC->database();
38 $rules = [];
42 $query = "SELECT rule_id FROM shib_role_assignment ORDER BY rule_id";
43 $res = $db->query($query);
44 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
45 $rules[$row->rule_id] = new ilShibbolethRoleAssignmentRule($row->rule_id);
46 }
47
48 return $rules;
49 }
50
51 public static function getCountRules(): int
52 {
53 global $DIC;
54 $db = $DIC->database();
55 $query = "SELECT COUNT(*) num FROM shib_role_assignment ";
56 $res = $db->query($query);
57 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
58 return (int) ($row->num ?? 0);
59 }
60
61 public static function updateAssignments(int $a_usr_id, array $a_data): bool
62 {
63 global $DIC;
64 $db = $DIC->database();
65 $rbac_admin = $DIC->rbac()->admin();
66 $rbac_review = $DIC->rbac()->review();
67 $logger = $DIC->logger()->root();
68 $query = "SELECT rule_id,add_on_update,remove_on_update FROM shib_role_assignment " . "WHERE add_on_update = 1 OR remove_on_update = 1";
69 $res = $db->query($query);
70 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
71 $rule = new ilShibbolethRoleAssignmentRule($row->rule_id);
72 // $matches = $rule->matches($a_data);
73 if ($row->add_on_update && $rule->doesMatch($a_data)) {
74 $logger->write(__METHOD__ . ': Assigned to role ' . ilObject::_lookupTitle($rule->getRoleId()));
75 $rbac_admin->assignUser($rule->getRoleId(), $a_usr_id);
76 }
77 if ($row->remove_on_update && !$rule->doesMatch($a_data)) {
78 $logger->write(__METHOD__ . ': Deassigned from role ' . ilObject::_lookupTitle($rule->getRoleId()));
79 $rbac_admin->deassignUser($rule->getRoleId(), $a_usr_id);
80 }
81 }
82 // check if is assigned to minimum one global role
83 if (!array_intersect($rbac_review->assignedRoles($a_usr_id), $rbac_review->getGlobalRoles())) {
84 $settings = new ilShibbolethSettings();
85 $default_role = $settings->getDefaultRole();
86 $logger->write(__METHOD__ . ': Assigned to default role ' . ilObject::_lookupTitle($default_role));
87 $rbac_admin->assignUser($default_role, $a_usr_id);
88 }
89
90 return true;
91 }
92
93 public static function doAssignments(int $a_usr_id, array $a_data): bool
94 {
95 global $DIC;
96 $db = $DIC->database();
97 $rbac_admin = $DIC->rbac()->admin();
98 $logger = $DIC->logger()->root();
99 $query = "SELECT rule_id,add_on_update FROM shib_role_assignment WHERE add_on_update = 1";
100 $num_matches = 0;
101 $res = $db->query($query);
102 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
103 $rule = new ilShibbolethRoleAssignmentRule($row->rule_id);
104 if ($rule->doesMatch($a_data)) {
105 $num_matches++;
106 $logger->write(__METHOD__ . ': Assigned to role ' . ilObject::_lookupTitle($rule->getRoleId()));
107 $rbac_admin->assignUser($rule->getRoleId(), $a_usr_id);
108 }
109 }
110 // Assign to default if no matching found
111 if ($num_matches === 0) {
112 $settings = new ilShibbolethSettings();
113 $default_role = $settings->getDefaultRole();
114 $logger->write(__METHOD__ . ': Assigned to default role ' . ilObject::_lookupTitle($default_role));
115 $rbac_admin->assignUser($default_role, $a_usr_id);
116 }
117
118 return true;
119 }
120
121 public static function callPlugin(string $a_plugin_id, array $a_user_data): bool
122 {
123 global $DIC;
124 foreach ($DIC['component.factory']->getActivePluginsInSlot('shibhk') as $plugin) {
125 if ($plugin->checkRoleAssignment($a_plugin_id, $a_user_data)) {
126 return true;
127 }
128 }
129 return false;
130 }
131}
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static doAssignments(int $a_usr_id, array $a_data)
static updateAssignments(int $a_usr_id, array $a_data)
static callPlugin(string $a_plugin_id, array $a_user_data)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26