ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilShibbolethRoleAssignmentRule.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23require_once('./Services/AuthShibboleth/classes/class.ilShibbolethRoleAssignmentRules.php');
24
36
37 const ERR_MISSING_NAME = 'shib_missing_attr_name';
38 const ERR_MISSING_VALUE = 'shib_missing_attr_value';
39 const ERR_MISSING_ROLE = 'shib_missing_role';
40 const ERR_MISSING_PLUGIN_ID = 'shib_missing_plugin_id';
41 const TABLE_NAME = 'shib_role_assignment';
45 protected $db;
49 private $rule_id = 0;
53 private $role_id = 0;
57 private $attribute_name = '';
61 private $attribute_value = '';
65 private $plugin_active = false;
69 private $add_on_update = false;
73 private $remove_on_update = false;
77 private $plugin_id = 0;
78
79
83 public function __construct($a_rule_id = 0) {
84 global $DIC;
85 $ilDB = $DIC['ilDB'];
86 $this->db = $ilDB;
87 $this->rule_id = $a_rule_id;
88 $this->read();
89 }
90
91
95 public function setRuleId($a_id) {
96 $this->rule_id = $a_id;
97 }
98
99
103 public function getRuleId() {
104 return $this->rule_id;
105 }
106
107
111 public function setRoleId($a_id) {
112 $this->role_id = $a_id;
113 }
114
115
119 public function getRoleId() {
120 return $this->role_id;
121 }
122
123
127 public function setName($a_name) {
128 $this->attribute_name = $a_name;
129 }
130
131
135 public function getName() {
137 }
138
139
143 public function setValue($a_value) {
144 $this->attribute_value = $a_value;
145 }
146
147
151 public function getValue() {
153 }
154
155
159 public function enablePlugin($a_status) {
160 $this->plugin_active = $a_status;
161 }
162
163
167 public function isPluginActive() {
168 return (bool)$this->plugin_active;
169 }
170
171
175 public function enableAddOnUpdate($a_status) {
176 $this->add_on_update = $a_status;
177 }
178
179
183 public function isAddOnUpdateEnabled() {
184 return (bool)$this->add_on_update;
185 }
186
187
191 public function enableRemoveOnUpdate($a_status) {
192 $this->remove_on_update = $a_status;
193 }
194
195
199 public function isRemoveOnUpdateEnabled() {
200 return (bool)$this->remove_on_update;
201 }
202
203
207 public function setPluginId($a_id) {
208 $this->plugin_id = $a_id;
209 }
210
211
215 public function getPluginId() {
216 return $this->plugin_id;
217 }
218
219
223 public function conditionToString() {
224 global $DIC;
225 $lng = $DIC['lng'];
226 if ($this->isPluginActive()) {
227 return $lng->txt('shib_plugin_id') . ': ' . $this->getPluginId();
228 } else {
229 return $this->getName() . '=' . $this->getValue();
230 }
231 }
232
233
237 public function validate() {
238 if (! $this->getRoleId()) {
240 }
241 if (! $this->isPluginActive()) {
242 if (! $this->getName()) {
244 }
245 if (! $this->getValue()) {
247 }
248 } else {
249 // check plugin id is given
250 if (! $this->getPluginId()) {
252 }
253 }
254
255 return '';
256 }
257
258
262 public function delete() {
263 $query = 'DELETE FROM ' . self::TABLE_NAME . ' ' . 'WHERE rule_id = ' . $this->db->quote($this->getRuleId(), 'integer');
264 $this->db->manipulate($query);
265
266 return true;
267 }
268
269
273 public function add() {
274 $next_id = $this->db->nextId(self::TABLE_NAME);
275 $query = 'INSERT INTO ' . self::TABLE_NAME . ' (rule_id,role_id,name,value,plugin,plugin_id,add_on_update,remove_on_update ) ' . 'VALUES( '
276 . $this->db->quote($next_id, 'integer') . ', ' . $this->db->quote($this->getRoleId(), 'integer') . ', '
277 . $this->db->quote($this->getName(), 'text') . ', ' . $this->db->quote($this->getValue(), 'text') . ', '
278 . $this->db->quote((int)$this->isPluginActive(), 'integer') . ', ' . $this->db->quote((int)$this->getPluginId(), 'integer') . ', '
279 . $this->db->quote((int)$this->isAddOnUpdateEnabled(), 'integer') . ', '
280 . $this->db->quote((int)$this->isRemoveOnUpdateEnabled(), 'integer') . ') ';
281 $this->db->manipulate($query);
282 $this->setRuleId($this->db->getLastInsertId());
283
284 return true;
285 }
286
287
291 public function update() {
292 $query = 'UPDATE ' . self::TABLE_NAME . ' ' . 'SET role_id = ' . $this->db->quote($this->getRoleId(), 'integer') . ', ' . 'name = '
293 . $this->db->quote($this->getName(), 'text') . ', ' . 'value = ' . $this->db->quote($this->getValue(), 'text') . ', ' . 'plugin = '
294 . $this->db->quote((int)$this->isPluginActive(), 'integer') . ', ' . 'plugin_id = '
295 . $this->db->quote((int)$this->getPluginId(), 'integer') . ', ' . 'add_on_update = '
296 . $this->db->quote((int)$this->isAddOnUpdateEnabled(), 'integer') . ', ' . 'remove_on_update = '
297 . $this->db->quote((int)$this->isRemoveOnUpdateEnabled(), 'integer') . ' '
298 . 'WHERE rule_id = ' . $this->db->quote($this->getRuleId(), 'integer');
299 $this->db->manipulate($query);
300
301 return true;
302 }
303
304
311 public function matches($a_data) {
312 if ($this->isPluginActive()) {
314 }
315 // No value
316 if (! isset($a_data[$this->getName()])) {
317 return false;
318 }
319 $values = $a_data[$this->getName()];
320 if (is_array($values)) {
321 return in_array($this->getValue(), $values);
322 } else {
323 return $this->wildcardCompare($this->getValue(), $values);
324 }
325 }
326
327
335 protected function wildcardCompare($a_str1, $a_str2) {
336 $pattern = str_replace('*', '.*?', $a_str1);
337
338 return (bool)preg_match("/" . $pattern . "/us", $a_str2);
339 }
340
341
347 public function doesMatch(array $a_data) {
348 if ($this->isPluginActive()) {
350 }
351 if (! isset($a_data[$this->getName()])) {
352 return false;
353 }
354 $values = $a_data[$this->getName()];
355 if (is_array($values)) {
356 return in_array($this->getValue(), $values);
357 } else {
358 $pattern = str_replace('*', '.*?', $this->getValue());
359
360 return (bool)preg_match('/^' . $pattern . '$/us', $values);
361 }
362 }
363
364
368 private function read() {
369 if (! $this->getRuleId()) {
370 return true;
371 }
372 $query = 'SELECT * FROM ' . self::TABLE_NAME . ' ' . 'WHERE rule_id = ' . $this->db->quote($this->getRuleId(), 'integer');
373 $res = $this->db->query($query);
374 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
375 $this->setRoleId($row->role_id);
376 $this->setName($row->name);
377 $this->setValue($row->value);
378 $this->enablePlugin($row->plugin);
379 $this->setPluginId($row->plugin_id);
380 $this->enableAddOnUpdate($row->add_on_update);
381 $this->enableRemoveOnUpdate($row->remove_on_update);
382 }
383 }
384}
385
386?>
An exception for terminatinating execution or to throw for unit testing.
global $lng
Definition: privfeed.php:17
global $ilDB
global $DIC