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