ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCASSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/CAS/classes/class.ilCASSettings.php';
5 
16 {
17  const SYNC_DISABLED = 0;
18  const SYNC_CAS = 1;
19  const SYNC_LDAP = 2;
20 
21  private $settings;
22 
23  private $ref_id;
24 
32  public function __construct($a_auth_ref_id)
33  {
34  global $lng,$ilCtrl,$tpl,$ilTabs;
35 
36  $this->ctrl = $ilCtrl;
37  $this->tabs_gui = $ilTabs;
38  $this->lng = $lng;
39  $this->lng->loadLanguageModule('registration');
40  $this->lng->loadLanguageModule('auth');
41 
42  $this->tpl = $tpl;
43  $this->ref_id = $a_auth_ref_id;
44 
46  }
47 
52  protected function getSettings()
53  {
54  return $this->settings;
55  }
56 
64  public function executeCommand()
65  {
66  global $ilAccess,$ilErr,$ilCtrl;
67 
68  $next_class = $this->ctrl->getNextClass($this);
69  $cmd = $this->ctrl->getCmd("settings");
70 
71  if(!$ilAccess->checkAccess('read','',$this->ref_id))
72  {
73  $ilErr->raiseError($this->lng->txt('msg_no_perm_write'),$ilErr->WARNING);
74  }
75 
76  if(!$ilAccess->checkAccess('write','',$this->ref_id) && $cmd != "settings")
77  {
78  ilUtil::sendFailure($this->lng->txt('msg_no_perm_write'), true);
79  $ilCtrl->redirect($this, "settings");
80  }
81 
82 
83  switch($next_class)
84  {
85  default:
86  if(!$cmd)
87  {
88  $cmd = "settings";
89  }
90  $this->$cmd();
91  break;
92  }
93  return true;
94 
95  }
96 
97 
101  protected function initFormSettings()
102  {
103  $this->lng->loadLanguageModule('auth');
104  $this->lng->loadLanguageModule('radius');
105 
106  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
107  $form = new ilPropertyFormGUI();
108  $form->setFormAction($this->ctrl->getFormAction($this));
109 
110  $form->setTitle($this->lng->txt('auth_cas_auth'));
111  $form->setDescription($this->lng->txt("auth_cas_auth_desc"));
112 
113  // Form checkbox
114  $check = new ilCheckboxInputGUI($this->lng->txt("active"),'active');
115  $check->setChecked($this->getSettings()->isActive() ? true : false);
116  $check->setValue(1);
117  $form->addItem($check);
118 
119  $text = new ilTextInputGUI($this->lng->txt('server'),'server');
120  $text->setValue($this->getSettings()->getServer());
121  $text->setRequired(true);
122  $text->setInfo($this->lng->txt('auth_cas_server_desc'));
123  $text->setSize(64);
124  $text->setMaxLength(255);
125  $form->addItem($text);
126 
127  $port = new ilNumberInputGUI($this->lng->txt("port"), 'port');
128  $port->setValue($this->getSettings()->getPort());
129  $port->setRequired(true);
130  $port->setMinValue(0);
131  $port->setMaxValue(65535);
132  $port->setSize(5);
133  $port->setMaxLength(5);
134  $port->setInfo($this->lng->txt('auth_cas_port_desc'));
135  $form->addItem($port);
136 
137  $text = new ilTextInputGUI($this->lng->txt('uri'), 'uri');
138  $text->setValue($this->getSettings()->getUri());
139  $text->setRequired(true);
140  $text->setInfo($this->lng->txt('auth_cas_uri_desc'));
141  $text->setSize(64);
142  $text->setMaxLength(255);
143  $form->addItem($text);
144 
145  // User synchronization
146  // 0: Disabled
147  // 1: CAS
148  // 2: LDAP
149  $sync = new ilRadioGroupInputGUI($this->lng->txt('auth_sync'), 'sync');
150  $sync->setRequired(true);
151  #$sync->setInfo($this->lng->txt('auth_radius_sync_info'));
152  $form->addItem($sync);
153 
154  // Disabled
155  $dis = new ilRadioOption(
156  $this->lng->txt('disabled'),
158  ''
159  );
160  #$dis->setInfo($this->lng->txt('auth_radius_sync_disabled_info'));
161  $sync->addOption($dis);
162 
163  // CAS
164  $rad = new ilRadioOption(
165  $this->lng->txt('auth_sync_cas'),
167  ''
168  );
169  $rad->setInfo($this->lng->txt('auth_sync_cas_info'));
170  $sync->addOption($rad);
171 
172  $select = new ilSelectInputGUI($this->lng->txt('auth_user_default_role'),'role');
173  $select->setOptions($this->prepareRoleSelection());
174  $select->setValue($this->getSettings()->getDefaultRole());
175  $rad->addSubItem($select);
176 
177 
178 
179  // LDAP
180  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
182 
183  if(count($server_ids))
184  {
185  $ldap = new ilRadioOption(
186  $this->lng->txt('auth_radius_ldap'),
188  ''
189  );
190  $ldap->setInfo($this->lng->txt('auth_radius_ldap_info'));
191  $sync->addOption($ldap);
192 
193  // TODO Handle more than one LDAP configuration
194  }
195 
197  {
198  $sync->setValue(self::SYNC_LDAP);
199  }
200  else
201  {
202  $sync->setValue(
203  $this->getSettings()->isUserCreationEnabled() ?
206  );
207  }
208 
209  $instruction = new ilTextAreaInputGUI($this->lng->txt('auth_login_instructions'), 'instruction');
210  $instruction->setCols(80);
211  $instruction->setRows(6);
212  $instruction->setValue($this->getSettings()->getLoginInstruction());
213  $form->addItem($instruction);
214 
215  $create = new ilCheckboxInputGUI($this->lng->txt('auth_allow_local'), 'local');
216  $create->setInfo($this->lng->txt('auth_cas_allow_local_desc'));
217  $create->setChecked($this->getSettings()->isLocalAuthenticationEnabled() ? true : false);
218  $create->setValue(1);
219  $form->addItem($create);
220 
221  $form->addCommandButton('save',$this->lng->txt('save'));
222 
223  return $form;
224  }
225 
233  public function settings()
234  {
235  $form = $this->initFormSettings();
236  $this->tpl->setContent($form->getHTML());
237  return;
238  }
239 
246  public function save()
247  {
248  $form = $this->initFormSettings();
249  if($form->checkInput())
250  {
251  $this->getSettings()->setActive($form->getInput('active'));
252  $this->getSettings()->setServer($form->getInput('server'));
253  $this->getSettings()->setPort($form->getInput('port'));
254  $this->getSettings()->setUri($form->getInput('uri'));
255  $this->getSettings()->setDefaultRole($form->getInput('role'));
256  $this->getSettings()->enableLocalAuthentication($form->getInput('local'));
257  $this->getSettings()->setLoginInstruction($form->getInput('instruction'));
258  $this->getSettings()->enableUserCreation($form->getInput('sync') == ilCASSettings::SYNC_CAS ? true : false);
259  $this->getSettings()->save();
260 
261  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
262  switch((int) $form->getInput('sync'))
263  {
266  break;
267 
270  break;
271 
272 
274  // TODO: handle multiple ldap configurations
276  break;
277  }
278 
279  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
280  $this->ctrl->redirect($this,'settings');
281  }
282 
283  $form->setValuesByPost();
284  ilUtil::sendFailure($this->lng->txt('err_ceck_input'));
285  $this->tpl->setContent($form->getHTML());
286  }
287 
288 
289 
290  private function prepareRoleSelection()
291  {
292  global $rbacreview,$ilObjDataCache;
293 
294  $global_roles = ilUtil::_sortIds($rbacreview->getGlobalRoles(),
295  'object_data',
296  'title',
297  'obj_id');
298 
299  $select[0] = $this->lng->txt('links_select_one');
300  foreach($global_roles as $role_id)
301  {
302  $select[$role_id] = ilObject::_lookupTitle($role_id);
303  }
304 
305  return $select;
306  }
307 }
308 ?>