ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 */
23 
34 {
35  const ERR_MISSING_NAME = 'shib_missing_attr_name';
36  const ERR_MISSING_VALUE = 'shib_missing_attr_value';
37  const ERR_MISSING_ROLE = 'shib_missing_role';
38  const ERR_MISSING_PLUGIN_ID = 'shib_missing_plugin_id';
39 
40  protected $db = null;
41 
42  private $rule_id = 0;
43  private $role_id = 0;
44  private $attribute_name = '';
45  private $attribute_value = '';
46  private $plugin_active = false;
47  private $add_on_update = false;
48  private $remove_on_update = false;
49  private $plugin_id = 0;
50 
51  public function __construct($a_rule_id = 0)
52  {
53  global $ilDB;
54 
55  $this->db = $ilDB;
56 
57  $this->rule_id = $a_rule_id;
58  $this->read();
59  }
60 
61  public function setRuleId($a_id)
62  {
63  $this->rule_id = $a_id;
64  }
65 
66  public function getRuleId()
67  {
68  return $this->rule_id;
69  }
70 
71  public function setRoleId($a_id)
72  {
73  $this->role_id = $a_id;
74  }
75 
76  public function getRoleId()
77  {
78  return $this->role_id;
79  }
80 
81  public function setName($a_name)
82  {
83  $this->attribute_name = $a_name;
84  }
85 
86  public function getName()
87  {
88  return $this->attribute_name;
89  }
90 
91  public function setValue($a_value)
92  {
93  $this->attribute_value = $a_value;
94  }
95 
96  public function getValue()
97  {
99  }
100 
101  public function enablePlugin($a_status)
102  {
103  $this->plugin_active = $a_status;
104  }
105 
106  public function isPluginActive()
107  {
108  return (bool) $this->plugin_active;
109  }
110 
111  public function enableAddOnUpdate($a_status)
112  {
113  $this->add_on_update = $a_status;
114  }
115 
116  public function isAddOnUpdateEnabled()
117  {
118  return (bool) $this->add_on_update;
119  }
120 
121  public function enableRemoveOnUpdate($a_status)
122  {
123  $this->remove_on_update = $a_status;
124  }
125 
126  public function isRemoveOnUpdateEnabled()
127  {
128  return (bool) $this->remove_on_update;
129  }
130 
131  public function setPluginId($a_id)
132  {
133  $this->plugin_id = $a_id;
134  }
135 
136  public function getPluginId()
137  {
138  return $this->plugin_id;
139  }
140 
141  public function conditionToString()
142  {
143  global $lng;
144 
145  if($this->isPluginActive())
146  {
147  return $lng->txt('shib_plugin_id').': '.$this->getPluginId();
148  }
149  else
150  {
151  return $this->getName().'='.$this->getValue();
152  }
153  }
154 
155  public function validate()
156  {
157  if(!$this->getRoleId())
158  {
159  return self::ERR_MISSING_ROLE;
160  }
161 
162  if(!$this->isPluginActive())
163  {
164  if(!$this->getName())
165  {
166  return self::ERR_MISSING_NAME;
167  }
168  if(!$this->getValue())
169  {
171  }
172  }
173  else
174  {
175  // check plugin id is given
176  if(!$this->getPluginId())
177  {
179  }
180  }
181 
182  return '';
183  }
184 
185  public function delete()
186  {
187  global $ilDB;;
188 
189  $query = "DELETE FROM shib_role_assignment ".
190  "WHERE rule_id = ".$this->db->quote($this->getRuleId() , 'integer');
191  $ilDB->manipulate($query);
192  return true;
193  }
194 
195  public function add()
196  {
197  global $ilDB;
198 
199  $next_id = $ilDB->nextId('shib_role_assignment');
200  $query = "INSERT INTO shib_role_assignment (rule_id,role_id,name,value,plugin,plugin_id,add_on_update,remove_on_update ) ".
201  "VALUES( ".
202  $ilDB->quote($next_id,'integer').', '.
203  $this->db->quote($this->getRoleId(),'integer').', '.
204  $this->db->quote($this->getName(),'text').', '.
205  $this->db->quote($this->getValue(),'text').', '.
206  $this->db->quote((int) $this->isPluginActive(),'integer').', '.
207  $this->db->quote((int) $this->getPluginId(),'integer').', '.
208  $this->db->quote((int) $this->isAddOnUpdateEnabled(),'integer').', '.
209  $this->db->quote((int) $this->isRemoveOnUpdateEnabled(),'integer').
210  ') ';
211  $ilDB->manipulate($query);
212 
213  $this->setRuleId($this->db->getLastInsertId());
214  return true;
215  }
216 
217  public function update()
218  {
219  global $ilDB;
220 
221  $query = "UPDATE shib_role_assignment ".
222  "SET role_id = ".$this->db->quote($this->getRoleId(),'integer').', '.
223  "name = ".$this->db->quote($this->getName(),'text').', '.
224  "value = ".$this->db->quote($this->getValue(),'text').', '.
225  "plugin = ".$this->db->quote((int) $this->isPluginActive(),'integer').', '.
226  "plugin_id = ".$this->db->quote((int) $this->getPluginId(),'integer').', '.
227  "add_on_update = ".$this->db->quote((int) $this->isAddOnUpdateEnabled(),'integer').', '.
228  "remove_on_update = ".$this->db->quote((int) $this->isRemoveOnUpdateEnabled(),'integer').' '.
229  "WHERE rule_id = ".$this->db->quote($this->getRuleId(),'integer');
230  $ilDB->manipulate($query);
231 
232  return true;
233  }
234 
235  public function matches($a_data)
236  {
237  if($this->isPluginActive())
238  {
239  include_once './Services/AuthShibboleth/classes/class.ilShibbolethRoleAssignmentRules.php';
241  }
242  // No value
243  if(!isset($a_data[$this->getName()]))
244  {
245  return false;
246  }
247 
248  $values = $a_data[$this->getName()];
249 
250  if(is_array($values))
251  {
252  return in_array($this->getValue(),$values);
253  }
254  else
255  {
256  return $this->getValue() == $values;
257  }
258  }
259 
260 
261 
262  private function read()
263  {
264  if(!$this->getRuleId())
265  {
266  return true;
267  }
268 
269  $query = "SELECT * FROM shib_role_assignment ".
270  "WHERE rule_id = ".$this->db->quote($this->getRuleId(),'integer');
271  $res = $this->db->query($query);
272  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
273  {
274  $this->setRoleId($row->role_id);
275  $this->setName($row->name);
276  $this->setValue($row->value);
277  $this->enablePlugin($row->plugin);
278  $this->setPluginId($row->plugin_id);
279  $this->enableAddOnUpdate($row->add_on_update);
280  $this->enableRemoveOnUpdate($row->remove_on_update);
281  }
282  }
283 
284 }
285 ?>