ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilClaimingPermissionHelper.php
Go to the documentation of this file.
1<?php
2
25{
26 protected int $user_id = 0;
27 protected int $ref_id = 0;
28 protected array $map = [];
29 protected array $context_ids = [];
31 protected ?array $plugins = null;
32 protected static array $instances = [];
33
34 protected function __construct(int $a_user_id, int $a_ref_id)
35 {
36 $this->setUserId($a_user_id);
37 $this->setRefId($a_ref_id);
38 $this->map = $this->buildPermissionMap();
39 $this->reset();
40 }
41
42 public static function getInstance(int $a_user_id, int $a_ref_id): self
43 {
44 if (!isset(self::$instances[$a_user_id][$a_ref_id])) {
45 self::$instances[$a_user_id][$a_ref_id] = new static($a_user_id, $a_ref_id);
46 }
47 return self::$instances[$a_user_id][$a_ref_id];
48 }
49
53 public function reset(): void
54 {
55 $this->context_ids = [];
56 }
57
58
59 // properties
60
61 protected function setUserId(int $a_value): void
62 {
63 $this->user_id = $a_value;
64 }
65
66 protected function getUserId(): int
67 {
68 return $this->user_id;
69 }
70
71 protected function setRefId(int $a_value): void
72 {
73 $this->ref_id = $a_value;
74 }
75
76 protected function getRefId(): int
77 {
78 return $this->ref_id;
79 }
80
81
82 // caching
83
87 abstract protected function readContextIds(int $a_context_type): array;
88
89
90 // permissions
91
95 abstract protected function buildPermissionMap(): array;
96
100 protected function isValidContextAndAction(
101 int $a_context_type,
102 int $a_context_id,
103 int $a_action_id,
104 ?int $a_action_sub_id = null
105 ): bool {
106 $valid = false;
107
108 if (array_key_exists($a_context_type, $this->map)) {
109 if (!$a_action_sub_id) {
110 if (in_array($a_action_id, $this->map[$a_context_type]["actions"])) {
111 $valid = true;
112 }
113 } else {
114 if (array_key_exists($a_action_id, $this->map[$a_context_type]["subactions"]) &&
115 in_array($a_action_sub_id, $this->map[$a_context_type]["subactions"][$a_action_id])) {
116 $valid = true;
117 }
118 }
119 }
120
121 if ($valid &&
122 $a_context_id &&
123 !in_array($a_context_id, $this->getValidContextIds($a_context_type))) {
124 $valid = false;
125 }
126
127 if (DEVMODE && !$valid) {
128 trigger_error("INVALID permission context - " . $a_context_type . ":" . $a_context_id . ":" . $a_action_id . ":" . $a_action_sub_id, E_USER_WARNING);
129 }
130
131 return $valid;
132 }
133
139 protected function getValidContextIds(int $a_context_type): array
140 {
141 if (!array_key_exists($a_context_type, $this->context_ids)) {
142 $this->context_ids[$a_context_type] = $this->readContextIds($a_context_type);
143 }
144 return (array) $this->context_ids[$a_context_type];
145 }
146
150 public function hasPermission(
151 int $a_context_type,
152 int $a_context_id,
153 int $a_action_id,
154 ?int $a_action_sub_id = null
155 ): bool {
156 if ($this->isValidContextAndAction($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id)) {
157 return $this->checkPermission($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id);
158 }
159 // :TODO: exception?
160 return false;
161 }
162
166 public function hasPermissions(int $a_context_type, int $a_context_id, array $a_action_ids): array
167 {
168 $res = [];
169
170 foreach ($a_action_ids as $action_id) {
171 if (is_array($action_id)) {
172 $action_sub_id = $action_id[1];
173 $action_id = $action_id[0];
174
175 $res[$action_id][$action_sub_id] = $this->hasPermission($a_context_type, $a_context_id, $action_id, $action_sub_id);
176 } else {
177 $res[$action_id] = $this->hasPermission($a_context_type, $a_context_id, $action_id);
178 }
179 }
180
181 return $res;
182 }
183
187 protected function checkPermission(
188 int $a_context_type,
189 int $a_context_id,
190 int $a_action_id,
191 ?int $a_action_sub_id = null
192 ): bool {
193 return ($this->checkRBAC() &&
194 $this->checkPlugins($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id));
195 }
196
200 protected function checkRBAC(): bool
201 {
202 global $DIC;
203 $ilAccess = $DIC->access();
204
205 // we are currently only supporting write operations
206 return $ilAccess->checkAccessOfUser($this->getUserId(), "write", "", $this->getRefId());
207 }
208
212 abstract protected function getActivePlugins(): Generator;
213
217 protected function checkPlugins(
218 int $a_context_type,
219 int $a_context_id,
220 int $a_action_id,
221 ?int $a_action_sub_id = null
222 ): bool {
223 $valid = true;
224
225 if (!is_array($this->plugins)) {
226 $this->plugins = iterator_to_array($this->getActivePlugins());
227 }
228
229 foreach ($this->plugins as $plugin) {
230 $a_action_sub_id = is_null($a_action_sub_id)
232 : $a_action_sub_id;
233 if (!$plugin->checkPermission($this->getUserId(), $a_context_type, $a_context_id, $a_action_id, $a_action_sub_id)) {
234 $valid = false;
235 break;
236 }
237 }
238
239 return $valid;
240 }
241}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildPermissionMap()
Build map of context and actions.
getActivePlugins()
Get active plugins (for current slot)
readContextIds(int $a_context_type)
Get all context ids for context type (from DB, is cached)
getValidContextIds(int $a_context_type)
Get context ids for context type (uses cache)
hasPermission(int $a_context_type, int $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check permission.
isValidContextAndAction(int $a_context_type, int $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check if given combination of context and action is valid.
checkRBAC()
Check permission against RBAC.
checkPermission(int $a_context_type, int $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check permission (helper: rbac, plugins)
static getInstance(int $a_user_id, int $a_ref_id)
__construct(int $a_user_id, int $a_ref_id)
hasPermissions(int $a_context_type, int $a_context_id, array $a_action_ids)
Check permissions.
checkPlugins(int $a_context_type, int $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check permission against plugins.
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
foreach($_POST as $key=> $value) $res
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26