ILIAS  release_8 Revision v8.24
class.ilCASSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public const SYNC_DISABLED = 0;
27 public const SYNC_CAS = 1;
28 public const SYNC_LDAP = 2;
29
31
32 private int $ref_id;
33
34 private \ilGlobalTemplateInterface $tpl;
35 private ilCtrl $ctrl;
40
41 public function __construct(int $a_auth_ref_id)
42 {
43 global $DIC;
44 $this->tpl = $DIC->ui()->mainTemplate();
45
46 $this->ctrl = $DIC->ctrl();
47 $this->rbacSystem = $DIC->rbac()->system();
48 $this->rbacReview = $DIC->rbac()->review();
49 $this->ilErr = $DIC['ilErr'];
50 $this->lng = $DIC->language();
51 $this->lng->loadLanguageModule('registration');
52 $this->lng->loadLanguageModule('auth');
53
54 $this->renderer = $DIC->ui()->renderer();
55 $this->factory = $DIC->ui()->factory();
56
57 $this->ref_id = $a_auth_ref_id;
58
60 }
61
62 protected function getSettings(): ilCASSettings
63 {
64 return $this->settings;
65 }
66
67 public function executeCommand(): bool
68 {
69 $next_class = $this->ctrl->getNextClass($this);
70 $cmd = $this->ctrl->getCmd("settings");
71
72 if (!$this->rbacSystem->checkAccess("visible,read", $this->ref_id)) {
73 $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $this->ilErr->WARNING);
74 }
75
76 switch ($next_class) {
77 default:
78 if (!$cmd) {
79 $cmd = "settings";
80 }
81 $this->$cmd();
82 break;
83 }
84 return true;
85 }
86
87 protected function initFormSettings(): ilPropertyFormGUI
88 {
89 $this->lng->loadLanguageModule('auth');
90
91 $form = new ilPropertyFormGUI();
92 $form->setFormAction($this->ctrl->getFormAction($this));
93
94 $form->setTitle($this->lng->txt('auth_cas_auth'));
95
96 $drop_in_replacements_url = 'https://github.com/ILIAS-eLearning/ILIAS/tree/trunk/components/ILIAS/HTTP#dropinreplacements';
97 $drop_in_replacements_link = $this->factory->link()->standard(
98 $this->lng->txt("auth_cas_auth_desc"),
99 $drop_in_replacements_url
100 );
101 $form->setDescription($this->renderer->render(
102 $drop_in_replacements_link
103 ));
104
105 // Form checkbox
106 $check = new ilCheckboxInputGUI($this->lng->txt("active"), 'active');
107 $check->setChecked($this->getSettings()->isActive());
108 $check->setValue("1");
109 $form->addItem($check);
110
111 $text = new ilTextInputGUI($this->lng->txt('server'), 'server');
112 $text->setValue($this->getSettings()->getServer());
113 $text->setRequired(true);
114 $text->setInfo($this->lng->txt('auth_cas_server_desc'));
115 $text->setSize(64);
116 $text->setMaxLength(255);
117 $form->addItem($text);
118
119 $port = new ilNumberInputGUI($this->lng->txt("port"), 'port');
120 $port->setValue((string) $this->getSettings()->getPort());
121 $port->setRequired(true);
122 $port->setMinValue(0);
123 $port->setMaxValue(65535);
124 $port->setSize(5);
125 $port->setMaxLength(5);
126 $port->setInfo($this->lng->txt('auth_cas_port_desc'));
127 $form->addItem($port);
128
129 $text = new ilTextInputGUI($this->lng->txt('uri'), 'uri');
130 $text->setValue($this->getSettings()->getUri());
131 $text->setRequired(true);
132 $text->setInfo($this->lng->txt('auth_cas_uri_desc'));
133 $text->setSize(64);
134 $text->setMaxLength(255);
135 $form->addItem($text);
136
137 // User synchronization
138 // 0: Disabled
139 // 1: CAS
140 // 2: LDAP
141 $sync = new ilRadioGroupInputGUI($this->lng->txt('auth_sync'), 'sync');
142 $sync->setRequired(true);
143 $form->addItem($sync);
144
145 // Disabled
146 $dis = new ilRadioOption(
147 $this->lng->txt('disabled'),
148 (string) self::SYNC_DISABLED,
149 ''
150 );
151 $sync->addOption($dis);
152
153 // CAS
154 $rad = new ilRadioOption(
155 $this->lng->txt('auth_sync_cas'),
156 (string) self::SYNC_CAS,
157 ''
158 );
159 $rad->setInfo($this->lng->txt('auth_sync_cas_info'));
160 $sync->addOption($rad);
161
162 $select = new ilSelectInputGUI($this->lng->txt('auth_user_default_role'), 'role');
163 $select->setOptions($this->prepareRoleSelection());
164 $select->setValue($this->getSettings()->getDefaultRole());
165 $rad->addSubItem($select);
166
167
168 // LDAP
170
171 if (count($server_ids)) {
172 $ldap = new ilRadioOption(
173 $this->lng->txt('auth_css_ldap'),
175 ''
176 );
177 $ldap->setInfo($this->lng->txt('auth_cas_ldap_info'));
178 $sync->addOption($ldap);
179
180 $ldap_server_select = new ilSelectInputGUI($this->lng->txt('auth_ldap_server_ds'), 'ldap_sid');
181 $options[0] = $this->lng->txt('select_one');
182 foreach ($server_ids as $ldap_sid) {
183 $ldap_server = new ilLDAPServer($ldap_sid);
184 $options[$ldap_sid] = $ldap_server->getName();
185 }
186 $ldap_server_select->setOptions($options);
187 $ldap_server_select->setRequired(true);
189 $ldap_server_select->setValue($ds);
190
191 $ldap->addSubItem($ldap_server_select);
192 }
193
195 $sync->setValue((string) ilCASSettings::SYNC_LDAP);
196 } else {
197 $sync->setValue(
198 $this->getSettings()->isUserCreationEnabled() ?
199 (string) ilCASSettings::SYNC_CAS :
201 );
202 }
203
204 $instruction = new ilTextAreaInputGUI($this->lng->txt('auth_login_instructions'), 'instruction');
205 $instruction->setCols(80);
206 $instruction->setRows(6);
207 $instruction->setValue($this->getSettings()->getLoginInstruction());
208 $form->addItem($instruction);
209
210 $create = new ilCheckboxInputGUI($this->lng->txt('auth_allow_local'), 'local');
211 $create->setInfo($this->lng->txt('auth_cas_allow_local_desc'));
212 $create->setChecked($this->getSettings()->isLocalAuthenticationEnabled());
213 $create->setValue("1");
214 $form->addItem($create);
215
216 if ($this->rbacSystem->checkAccess('write', $this->ref_id)) {
217 $form->addCommandButton('save', $this->lng->txt('save'));
218 }
219
220 return $form;
221 }
222
223 public function settings(): void
224 {
225 $form = $this->initFormSettings();
226 $this->tpl->setContent($form->getHTML());
227 }
228
229 public function save(): void
230 {
231 $form = $this->initFormSettings();
232 if ($form->checkInput()) {
233 $this->getSettings()->setActive((bool) $form->getInput('active'));
234 $this->getSettings()->setServer($form->getInput('server'));
235 $this->getSettings()->setPort((int) $form->getInput('port'));
236 $this->getSettings()->setUri($form->getInput('uri'));
237 $this->getSettings()->setDefaultRole((int) $form->getInput('role'));
238 $this->getSettings()->enableLocalAuthentication((bool) $form->getInput('local'));
239 $this->getSettings()->setLoginInstruction($form->getInput('instruction'));
240 $this->getSettings()->enableUserCreation((int) $form->getInput('sync') === ilCASSettings::SYNC_CAS);
241 $this->getSettings()->save();
242
243 switch ((int) $form->getInput('sync')) {
247 break;
248
250 if (!(int) $form->getInput('ldap_sid')) {
251 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
252 $this->settings();
253 //TODO do we need return false?
254 return;
255 }
256
257 ilLDAPServer::toggleDataSource((int) $form->getInput('ldap_sid'), ilAuthUtils::AUTH_CAS, 1);
258 break;
259 }
260
261 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
262 $this->ctrl->redirect($this, 'settings');
263 }
264
265 $form->setValuesByPost();
266 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_ceck_input'));
267 $this->tpl->setContent($form->getHTML());
268 }
269
270 private function prepareRoleSelection(): array
271 {
272 $global_roles = ilUtil::_sortIds(
273 $this->rbacReview->getGlobalRoles(),
274 'object_data',
275 'title',
276 'obj_id'
277 );
278
279 $select[0] = $this->lng->txt('links_select_one');
280 foreach ($global_roles as $role_id) {
281 $select[$role_id] = ilObject::_lookupTitle((int) $role_id);
282 }
283
284 return $select;
285 }
286}
$check
Definition: buildRTE.php:81
__construct(int $a_auth_ref_id)
ilGlobalTemplateInterface $tpl
static getInstance()
Get singleton instance.
This class represents a checkbox property in a property form.
Class ilCtrl provides processing control methods.
Error Handling & global info handling uses PEAR error class.
static disableDataSourceForAuthMode(int $a_authmode)
Disable data source.
static isDataSourceActive(int $a_auth_mode)
Check if a data source is active for a specific auth mode.
static toggleDataSource(int $a_ldap_server_id, int $a_auth_mode, int $a_status)
Toggle Data Source.
static getDataSource(int $a_auth_mode)
static getAvailableDataSources(int $a_auth_mode)
language handling
This class represents a number property in a property form.
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
class ilRbacReview Contains Review functions of core Rbac.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This class represents a selection list property in a property form.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static _sortIds(array $a_ids, string $a_table, string $a_field, string $a_id_name)
Function that sorts ids by a given table field using WHERE IN E.g: __sort(array(6,...
global $DIC
Definition: feed.php:28