ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilLDAPSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
28 {
29  private int $ref_id;
34 
35  private ilCtrl $ctrl;
37  private ilLanguage $lng;
50 
51  //vars for storing request parameters
53  private ?array $rule_ids = null;
54  private ?int $rule_id = null;
55  private ?int $role_id = null;
57  private ?array $mappings = null;
58  private ?string $mapping_template = null;
59  private ?int $ldap_server_id = null;
61  private ?array $server_ids = null;
62  private ?int $mapping_id = null;
63  private ?string $role_bind_user = null;
64  private ?string $role_bind_pass = null;
65  private bool $role_sync_active = false;
66  private array $attribute_mappings = [];
67  private readonly \ILIAS\UI\Factory $ui_factory;
68  private readonly \ILIAS\UI\Renderer $ui_renderer;
69  private readonly \ILIAS\HTTP\GlobalHttpState $http;
70  private readonly \ILIAS\Refinery\Factory $refinery;
72 
76  public function __construct(int $a_auth_ref_id)
77  {
78  global $DIC;
79 
80  $this->ctrl = $DIC->ctrl();
81  $this->tabs_gui = $DIC->tabs();
82  $this->lng = $DIC->language();
83  $this->lng->loadLanguageModule('ldap');
84  $this->lng->loadLanguageModule('ui');
85  $this->ilErr = $DIC['ilErr'];
86  $this->ilAccess = $DIC->access();
87  $this->component_repository = $DIC["component.repository"];
88  $this->rbacReview = $DIC->rbac()->review();
89  $this->rbacSystem = $DIC->rbac()->system();
90  $this->toolbar = $DIC->toolbar();
91  $this->main_tpl = $DIC->ui()->mainTemplate();
92  $this->http = $DIC->http();
93  $this->ui_factory = $DIC->ui()->factory();
94  $this->ui_renderer = $DIC->ui()->renderer();
95  $this->refinery = $DIC->refinery();
96  $this->object_data_cache = $DIC['ilObjDataCache'];
97 
98  $this->tpl = $DIC->ui()->mainTemplate();
99 
100  if ($this->ctrl->getCmd() !== "addServerSettings") {
101  $this->ctrl->saveParameter($this, 'ldap_server_id');
102  }
103 
104  $http_wrapper = $DIC->http()->wrapper();
105  $is_post_request = $DIC->http()->request()->getMethod() === "POST";
106  $refinery = $DIC->refinery();
107  if ($http_wrapper->query()->has("rule_id")) {
108  $this->rule_id = $http_wrapper->query()->retrieve(
109  "rule_id",
110  $refinery->kindlyTo()->int()
111  );
112  }
113 
114  if ($http_wrapper->query()->has('ldap_server_id')) {
115  $this->ldap_server_id = $http_wrapper->query()->retrieve(
116  'ldap_server_id',
117  $refinery->kindlyTo()->int()
118  );
119  } elseif ($http_wrapper->query()->has('ldap_servers_server_id')) {
120  $this->ldap_server_id = $http_wrapper->query()->retrieve(
121  'ldap_servers_server_id',
122  $this->refinery->in()->series([
123  $refinery->kindlyTo()->listOf(
124  $refinery->kindlyTo()->int()
125  ),
126  $this->refinery->custom()->constraint(
127  fn($value): bool => count($value) === 1,
128  $this->lng->txt('select_one')
129  ),
130  $this->refinery->custom()->transformation(
131  fn($value): int => $value[0]
132  )
133  ])
134  );
135  }
136  $this->initServer();
137 
138 
139  if ($http_wrapper->query()->has("mapping_id")) {
140  $this->mapping_id = $http_wrapper->query()->retrieve(
141  "mapping_id",
142  $refinery->kindlyTo()->int()
143  );
144  }
145  if ($http_wrapper->query()->has('ldap_role_mapping_mapping_ids')) {
146  $this->mappings = $http_wrapper->query()->retrieve(
147  'ldap_role_mapping_mapping_ids',
148  $refinery->kindlyTo()->listOf($refinery->kindlyTo()->string())
149  );
150  if ($this->mappings === ['ALL_OBJECTS']) {
151  $mapping_instance = ilLDAPRoleGroupMappingSettings::_getInstanceByServerId($this->server->getServerId());
152  $this->mappings = array_map(static function (array $mapping): int {
153  return $mapping['mapping_id'];
154  }, $mapping_instance->getMappings());
155  }
156  $this->mappings = $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())->transform($this->mappings);
157  if (count($this->mappings) === 1) {
158  $this->mapping_id = current($this->mappings);
159  }
160  }
161  if ($http_wrapper->query()->has('ldap_role_assignment_rule_ids')) {
162  $this->rule_ids = $http_wrapper->query()->retrieve(
163  'ldap_role_assignment_rule_ids',
164  $refinery->kindlyTo()->listOf($refinery->kindlyTo()->string())
165  );
166  if ($this->rule_ids === ['ALL_OBJECTS']) {
167  $rule_objs = ilLDAPRoleAssignmentRule::_getRules($this->server->getServerId());
168  $this->rule_ids = array_map(static function (ilLDAPRoleAssignmentRule $rule): int {
169  return $rule->getRuleId();
170  }, $rule_objs);
171  }
172  $this->rule_ids = $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())->transform($this->rule_ids);
173  if (count($this->rule_ids) === 1) {
174  $this->rule_id = current($this->rule_ids);
175  }
176  }
177  if ($is_post_request) {
178  if ($http_wrapper->post()->has('rule_ids')) {
179  $this->rule_ids = $http_wrapper->post()->retrieve(
180  'rule_ids',
181  $refinery->kindlyTo()->listOf($refinery->kindlyTo()->int())
182  );
183  }
184  if ($http_wrapper->post()->has('role_id')) {
185  $this->role_id = $http_wrapper->post()->retrieve(
186  'role_id',
187  $refinery->kindlyTo()->int()
188  );
189  }
190  if ($http_wrapper->post()->has('rule_id')) {
191  $this->rule_id = $http_wrapper->post()->retrieve(
192  'rule_id',
193  $refinery->kindlyTo()->int()
194  );
195  }
196  if ($http_wrapper->post()->has('mappings')) {
197  $this->mappings = $http_wrapper->post()->retrieve(
198  'mappings',
199  $refinery->kindlyTo()->listOf($refinery->kindlyTo()->int())
200  );
201  }
202  if ($http_wrapper->post()->has('server_ids')) {
203  $this->server_ids = $http_wrapper->post()->retrieve(
204  'server_ids',
205  $refinery->kindlyTo()->listOf($refinery->kindlyTo()->int())
206  );
207  }
208  if ($http_wrapper->post()->has('mapping_template')) {
209  $this->mapping_template = $http_wrapper->post()->retrieve(
210  'mapping_template',
211  $refinery->kindlyTo()->string()
212  );
213  }
214  if ($http_wrapper->post()->has('role_bind_user')) {
215  $this->role_bind_user = ilUtil::stripSlashes($http_wrapper->post()->retrieve(
216  'role_bind_user',
217  $refinery->kindlyTo()->string()
218  ));
219  }
220  if ($http_wrapper->post()->has('role_bind_pass')) {
221  $this->role_bind_pass = ilUtil::stripSlashes($http_wrapper->post()->retrieve(
222  'role_bind_pass',
223  $refinery->kindlyTo()->string()
224  ));
225  }
226  if ($http_wrapper->post()->has('role_sync_active')) {
227  $this->role_sync_active = $http_wrapper->post()->retrieve(
228  'role_sync_active',
229  $refinery->kindlyTo()->bool()
230  );
231  }
232  foreach ($this->getAttributeMappingKeys() as $key) {
233  if ($http_wrapper->post()->has($key . '_value')) {
234  $this->attribute_mappings[$key] = [ilUtil::stripSlashes($http_wrapper->post()->retrieve(
235  $key . '_value',
236  $refinery->kindlyTo()->string()
237  )), $http_wrapper->post()->has($key . '_update')];
238  } else {
239  $this->attribute_mappings[$key] = ["", false];
240  }
241  }
242  }
243 
244  $this->ref_id = $a_auth_ref_id;
245  }
246 
250  public function executeCommand(): bool
251  {
252  $next_class = $this->ctrl->getNextClass($this);
253  $cmd = $this->ctrl->getCmd();
254  if ($this->http->wrapper()->query()->has('ldap_role_mapping_table_action')) {
255  $cmd = $this->http->wrapper()->query()->retrieve(
256  'ldap_role_mapping_table_action',
257  $this->refinery->kindlyTo()->string()
258  );
259  }
260  if ($this->http->wrapper()->query()->has('ldap_role_assignment_table_action')) {
261  $cmd = $this->http->wrapper()->query()->retrieve(
262  'ldap_role_assignment_table_action',
263  $this->refinery->kindlyTo()->string()
264  );
265  }
266 
267  if ($cmd !== "serverList" && !$this->rbacSystem->checkAccess("visible,read", $this->ref_id)) {
268  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_write'), true);
269  $this->ctrl->redirect($this, "serverList");
270  }
271  switch ($next_class) {
272  default:
273  if (!$cmd) {
274  $cmd = "serverList";
275  }
276  $this->$cmd();
277  break;
278  }
279  return true;
280  }
281 
282  private function checkAccess(string $a_permission): void
283  {
284  if (!$this->ilAccess->checkAccess($a_permission, '', $this->ref_id)) {
285  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $this->ilErr->WARNING);
286  }
287  }
288 
293  private function getAttributeMappingKeys(): array
294  {
295  $keys = [];
296  foreach (array_keys($this->getMappingFields()) as $key) {
297  $keys[] = $key;
298  }
299  foreach (ilUserDefinedFields::_getInstance()->getDefinitions() as $definition) {
300  $keys[] = 'udf_' . $definition['field_id'];
301  }
302  return $keys;
303  }
304 
305 
309  public function getServer(): ilLDAPServer
310  {
311  return $this->server;
312  }
313 
317  public function roleAssignments(): void
318  {
319  $this->setSubTabs();
320  $this->tabs_gui->activateTab('role_assignments');
321 
322  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.ldap_role_assignments.html', 'components/ILIAS/LDAP');
323 
324  $this->initFormRoleAssignments('create');
325  $this->role_mapping_rule = ilLDAPRoleAssignmentRule::_getInstanceByRuleId(0);
326  $this->tpl->setVariable('NEW_ASSIGNMENT_TBL', $this->form->getHTML());
327 
328 
329  if (count($rules = ilLDAPRoleAssignmentRule::_getRules($this->server->getServerId()))) {
330  $this->tpl->setVariable('RULES_TBL', $this->ui_renderer->render($this->getRoleAssignmentTable()));
331  }
332  }
333 
338  public function editRoleAssignment(): void
339  {
340  if (!$this->rule_id) {
341  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
342  $this->roleAssignments();
343  return;
344  }
345  $this->setSubTabs();
346  $this->tabs_gui->activateTab('role_assignments');
347 
348  $this->ctrl->setParameter($this, 'rule_id', $this->rule_id);
350  'edit'
351  );
352  $this->role_mapping_rule = ilLDAPRoleAssignmentRule::_getInstanceByRuleId($this->rule_id);
353  $this->setValuesByArray();
354  $this->tpl->setContent($this->form->getHTML());
355  }
356 
357 
361  private function setValuesByArray(): void
362  {
363  $role_id = $this->role_mapping_rule->getRoleId();
364  if ($this->rbacReview->isGlobalRole($role_id)) {
365  $val['role_name'] = 0;
366  $val['role_id'] = $role_id;
367  } else {
368  $val['role_name'] = 1;
369  $val['role_search'] = ilObject::_lookupTitle($role_id);
370  }
371  $val['add_missing'] = (int) $this->role_mapping_rule->isAddOnUpdateEnabled();
372  $val['remove_deprecated'] = (int) $this->role_mapping_rule->isRemoveOnUpdateEnabled();
373  $val['type'] = $this->role_mapping_rule->getType();
374  $val['dn'] = $this->role_mapping_rule->getDN();
375  $val['at'] = $this->role_mapping_rule->getMemberAttribute();
376  $val['isdn'] = $this->role_mapping_rule->isMemberAttributeDN();
377  $val['name'] = $this->role_mapping_rule->getAttributeName();
378  $val['value'] = $this->role_mapping_rule->getAttributeValue();
379  $val['plugin_id'] = $this->role_mapping_rule->getPluginId();
380 
381  $this->form->setValuesByArray($val);
382  }
383 
387  public function updateRoleAssignment(): bool
388  {
389  if (!$this->ilAccess->checkAccess('write', '', $this->ref_id)) {
390  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
391  $this->roleAssignments();
392  return false;
393  }
394 
395  $this->initFormRoleAssignments('edit');
396 
397  $formWithoutErrors = $this->form->checkInput();
398  $roleErrorMessage = $this->checkRoleAssignmentInput($this->rule_id);
399  if (!$formWithoutErrors || $roleErrorMessage !== '') {
400  if ($roleErrorMessage !== '') {
401  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt($roleErrorMessage));
402  }
403 
404  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.ldap_role_assignments.html', 'components/ILIAS/LDAP');
405 
406  $this->form->setValuesByPost();
407  $this->tpl->setVariable('NEW_ASSIGNMENT_TBL', $this->form->getHTML());
408  $this->tabs_gui->activateSubTab('role_assignments');
409  return true;
410  }
411 
412  // Might redirect
413  if ($this->roleSelectionRequired()) {
414  $this->ctrl->redirect($this, 'showRoleSelection');
415  } else {
416  $this->rule->update();
417  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
418  $this->roleAssignments();
419  }
420  return true;
421  }
422 
427  public function confirmDeleteRules(): void
428  {
429  $this->checkAccess("write");
430 
431  if (!$this->rule_ids) {
432  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
433  $this->roleAssignments();
434  return;
435  }
436  $this->setSubTabs();
437  $this->tabs_gui->activateTab('role_assignments');
438 
439  $c_gui = new ilConfirmationGUI();
440 
441  // set confirm/cancel commands
442  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteRules"));
443  $c_gui->setHeaderText($this->lng->txt("ldap_confirm_del_role_ass"));
444  $c_gui->setCancel($this->lng->txt("cancel"), "roleAssignments");
445  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteRules");
446 
447  // add items to delete
448  foreach ($this->rule_ids as $rule_id) {
450  $c_gui->addItem('rule_ids[]', (string) $rule_id, $rule->conditionToString());
451  }
452  $this->tpl->setContent($c_gui->getHTML());
453  }
454 
458  public function deleteRules(): void
459  {
460  if (!$this->rule_ids) {
461  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('select_once'));
462  $this->roleAssignments();
463  return;
464  }
465  foreach ($this->rule_ids as $rule_id) {
467  $rule->delete();
468  }
469  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('ldap_deleted_rule'));
470  $this->ctrl->redirect($this, 'roleAssignments');
471  }
472 
476  public function addRoleAssignment(): bool
477  {
478  if (!$this->ilAccess->checkAccess('write', '', $this->ref_id)) {
479  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
480  $this->roleAssignments();
481  return false;
482  }
483  $this->setSubTabs();
484  $this->initFormRoleAssignments('create');
485  $formWithoutErrors = $this->form->checkInput();
486  $roleErrorMessage = $this->checkRoleAssignmentInput();
487  if (!$formWithoutErrors || $roleErrorMessage !== '') {
488  if ($roleErrorMessage !== '') {
489  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt($roleErrorMessage));
490  }
491 
492  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.ldap_role_assignments.html', 'components/ILIAS/LDAP');
493 
494  // DONE: wrap this
495  $this->form->setValuesByPost();
496  $this->tpl->setVariable('NEW_ASSIGNMENT_TBL', $this->form->getHTML());
497  $this->tpl->setVariable('RULES_TBL', $this->ui_renderer->render($this->getRoleAssignmentTable()));
498  $this->tabs_gui->activateSubTab('role_assignments');
499  return true;
500  }
501 
502  if ($this->roleSelectionRequired()) {
503  $this->ctrl->redirect($this, 'showRoleSelection');
504  } else {
505  $this->rule->create();
506  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
507  $this->ctrl->redirect($this, 'roleAssignments');
508  }
509  return true;
510  }
511 
512  private function roleSelectionRequired(): bool
513  {
514  if ($this->rule->getRoleId() > 0) {
515  return false;
516  }
517  $rule = [];
518  $rule['server_id'] = $this->getServer()->getServerId();
519  $rule['rule_id'] = $this->rule_id ?: 0;
520  $rule['role_search'] = $this->form->getInput('role_search');
521  $rule['add_on_update'] = $this->form->getInput('add_missing');
522  $rule['remove_on_update'] = $this->form->getInput('remove_deprecated');
523  $rule['type'] = $this->form->getInput('type');
524  $rule['dn'] = $this->form->getInput('dn');
525  $rule['at'] = $this->form->getInput('at');
526  $rule['isdn'] = $this->form->getInput('isdn');
527  $rule['name'] = $this->form->getInput('name');
528  $rule['value'] = $this->form->getInput('value');
529  $rule['plugin'] = $this->form->getInput('plugin_id');
530  ilSession::set("ldap_role_ass", serialize($rule));
531  $this->ctrl->saveParameter($this, 'rule_id');
532  return true;
533  }
534 
535 
536 
540  protected function showRoleSelection(): bool
541  {
542  $this->setSubTabs();
543  $this->tabs_gui->activateTab('role_assignment');
544  $this->ctrl->saveParameter($this, 'rule_id');
545 
546  $parser = new ilQueryParser(unserialize(ilSession::get('ldap_role_ass'), ["allowed_classes" => false])['role_search']);
547  $parser->setMinWordLength(1);
548  $parser->setCombination(ilQueryParser::QP_COMBINATION_AND);
549  $parser->parse();
550 
551  $object_search = new ilLikeObjectSearch($parser);
552  $object_search->setFilter(array('role'));
553  $res = $object_search->performSearch();
554 
555  $entries = $res->getEntries();
556 
557  $table = new ilRoleSelectionTableGUI($this, 'showRoleSelection');
558  $table->setTitle($this->lng->txt('ldap_role_selection'));
559  $table->addMultiCommand('saveRoleSelection', $this->lng->txt('ldap_choose_role'));
560  $table->parse($entries);
561 
562  $this->tpl->setContent($table->getHTML());
563  return true;
564  }
565 
570  protected function saveRoleSelection(): bool
571  {
572  if (!$this->ilAccess->checkAccess('write', '', $this->ref_id)) {
573  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
574  $this->roleAssignments();
575  return false;
576  }
577 
578  if (!$this->role_id) {
579  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
580  $this->showRoleSelection();
581  return false;
582  }
583 
584  $this->loadRoleAssignmentRule($this->rule_id ?? 0, false);
585  $this->rule->setRoleId($this->role_id);
586 
587  if ($this->rule_id) {
588  $this->rule->update();
589  } else {
590  $this->rule->create();
591  }
592 
593  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
594  $this->roleAssignments();
595  return true;
596  }
597 
598 
602  private function checkRoleAssignmentInput(int $a_rule_id = 0): string
603  {
604  $this->loadRoleAssignmentRule($a_rule_id);
605  $this->rule->validate();
606  return $this->ilErr->getMessage();
607  }
608 
612  protected function getRoleAssignmentTable(): ?Table
613  {
614  if (count($rules = ilLDAPRoleAssignmentRule::_getRules($this->server->getServerId()))) {
615  $table = new LDAPRoleAssignmentTable(
616  $this->http->request(),
617  $this->lng,
619  new Factory(),
620  $this->server->getServerId(),
621  );
622  return $table->getComponent();
623  }
624  return null;
625  }
626 
627 
631  private function loadRoleAssignmentRule(int $a_rule_id, bool $load_from_form = true): void
632  {
633  if (is_object($this->rule)) {
634  return;
635  }
636 
637  $this->rule = ilLDAPRoleAssignmentRule::_getInstanceByRuleId($a_rule_id);
638 
639  if ($load_from_form) {
640  if ($this->form->getInput('role_name') === '0') {
641  $this->rule->setRoleId((int) $this->form->getInput('role_id'));
642  } elseif ($this->form->getInput('role_search')) {
643  $parser = new ilQueryParser('"' . $this->form->getInput('role_search') . '"');
644 
645  // TODO: Handle minWordLength
646  $parser->setMinWordLength(1);
647  $parser->setCombination(ilQueryParser::QP_COMBINATION_AND);
648  $parser->parse();
649 
650  $object_search = new ilLikeObjectSearch($parser);
651  $object_search->setFilter(array('role'));
652  $res = $object_search->performSearch();
653 
654  $entries = $res->getEntries();
655  if (count($entries) === 1) {
656  $role = current($entries);
657  $this->rule->setRoleId($role['obj_id']);
658  } elseif (count($entries) > 1) {
659  $this->rule->setRoleId(-1);
660  }
661  }
662 
663  $this->rule->setAttributeName($this->form->getInput('name'));
664  $this->rule->setAttributeValue($this->form->getInput('value'));
665  $this->rule->setDN($this->form->getInput('dn'));
666  $this->rule->setMemberAttribute($this->form->getInput('at'));
667  $this->rule->setMemberIsDN((bool) $this->form->getInput('isdn'));
668  $this->rule->enableAddOnUpdate((bool) $this->form->getInput('add_missing'));
669  $this->rule->enableRemoveOnUpdate((bool) $this->form->getInput('remove_deprecated'));
670  $this->rule->setPluginId((int) $this->form->getInput('plugin_id'));
671  $this->rule->setType((int) $this->form->getInput('type'));
672  $this->rule->setServerId($this->getServer()->getServerId());
673  return;
674  }
675 
676  // LOAD from session
677  $this->rule->setServerId($this->getServer()->getServerId());
678  $rule = unserialize(ilSession::get('ldap_role_ass'), ["allowed_classes" => false]);
679 
680  $this->rule->enableAddOnUpdate((bool) ($rule['add_on_update'] ?? false));
681  $this->rule->enableRemoveOnUpdate((bool) ($rule['remove_on_update'] ?? false));
682  $this->rule->setType((int) ilUtil::stripSlashes(
683  $rule['type'] ?? (string) ilLDAPRoleAssignmentRule::TYPE_ATTRIBUTE
684  ));
685  $this->rule->setDN(ilUtil::stripSlashes($rule['dn'] ?? ''));
686  $this->rule->setMemberAttribute(ilUtil::stripSlashes($rule['at'] ?? ''));
687  $this->rule->setMemberIsDN((bool) (ilUtil::stripSlashes($rule['isdn'] ?? false)));
688  $this->rule->setAttributeName(ilUtil::stripSlashes($rule['name'] ?? ''));
689  $this->rule->setAttributeValue(ilUtil::stripSlashes($rule['value'] ?? ''));
690  $this->rule->setPluginId((int) ilUtil::stripSlashes((string) ($rule['plugin'] ?? '0')));
691  }
692 
693  public function deleteRoleMapping(): bool
694  {
695  if (!$this->mappings) {
696  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
697  $this->roleMapping();
698  return false;
699  }
700 
701  $this->initRoleMapping();
702 
703  foreach ($this->mappings as $mapping_id) {
704  $this->role_mapping->delete($mapping_id);
705  }
706  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('ldap_deleted_role_mapping'));
707  $this->roleMapping();
708  return true;
709  }
710 
711  public function chooseMapping(): void
712  {
713  if (!$this->mapping_template) {
714  $this->userMapping();
715  return;
716  }
717 
718  $this->initAttributeMapping();
719  $this->mapping->clearRules();
720 
721  foreach (ilLDAPAttributeMappingUtils::_getMappingRulesByClass($this->mapping_template) as $key => $value) {
722  $this->mapping->setRule($key, $value, false);
723  }
724  $this->userMapping();
725  }
726 
727  public function saveMapping(): void
728  {
729  $this->initAttributeMapping();
730  $this->tabs_gui->activateTab('role_mapping');
731 
732  foreach (array_keys($this->getMappingFields()) as $key) {
733  $this->mapping->setRule(
734  $key,
735  $this->attribute_mappings[$key][0],
736  $this->attribute_mappings[$key][1]
737  );
738  }
739  $this->initUserDefinedFields();
740  foreach ($this->udf->getDefinitions() as $definition) {
741  $key = 'udf_' . $definition['field_id'];
742  $this->mapping->setRule(
743  $key,
744  $this->attribute_mappings[$key][0],
745  $this->attribute_mappings[$key][1]
746  );
747  }
748 
749  $this->mapping->save();
750  $this->userMapping();
751 
752  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
753  }
754 
755  private function handleServerTableActions(): void
756  {
757  $action = $this->http->wrapper()->query()->retrieve(
758  'ldap_servers_table_action',
759  $this->refinery->byTrying([
760  $this->refinery->kindlyTo()->string(),
761  $this->refinery->always('')
762  ])
763  );
764  match ($action) {
765  'editServerSettings' => $this->editServerSettings(),
766  'activateServer' => $this->activateServer(),
767  'deactivateServer' => $this->deactivateServer(),
768  'confirmDeleteServerSettings' => $this->confirmDeleteServerSettings(),
769  default => $this->ctrl->redirect($this, 'serverList'),
770  };
771  }
772 
773  private function serverList(): void
774  {
775  if (!$this->rbacSystem->checkAccess('visible,read', $this->ref_id)) {
776  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $this->ilErr->WARNING);
777  }
778 
779  if (!ilLDAPServer::checkLDAPLib() && $this->server->isActive()) {
780  $this->main_tpl->setOnScreenMessage('failure', 'Missing LDAP libraries. Please ensure that the PHP LDAP module is installed on your server.');
781  }
782 
783  if ($this->rbacSystem->checkAccess('write', $this->ref_id)) {
784  $this->toolbar->addButton(
785  $this->lng->txt('add_ldap_server'),
786  $this->ctrl->getLinkTarget($this, 'addServerSettings')
787  );
788  }
789 
790  $table = new \ILIAS\LDAP\Server\UI\ServerTable(
792  $this,
793  $this->ui_factory,
794  $this->ui_renderer,
795  $this->lng,
796  $this->ctrl,
797  $this->http->request(),
798  new \ILIAS\Data\Factory(),
799  'handleServerTableActions',
800  $this->rbacSystem->checkAccess('write', $this->ref_id)
801  );
802 
803  $this->tpl->setContent($this->ui_renderer->render($table->getComponent()));
804  }
805 
806  public function setServerFormValues(): void
807  {
808  $this->form_gui->setValuesByArray(array(
809  'active' => $this->server->isActive(),
810  'ds' => !$this->server->isAuthenticationEnabled(),
811  'server_name' => $this->server->getName(),
812  'server_url' => $this->server->getUrlString(),
813  'version' => $this->server->getVersion(),
814  'base_dn' => $this->server->getBaseDN(),
815  'referrals' => $this->server->isActiveReferrer(),
816  'tls' => $this->server->isActiveTLS(),
817  'binding_type' => $this->server->getBindingType(),
818  'bind_dn' => $this->server->getBindUser(),
819  'bind_pass' => $this->server->getBindPassword(),
820  'bind_pass_retype' => $this->server->getBindPassword(),
821  'search_base' => $this->server->getSearchBase(),
822  'user_scope' => $this->server->getUserScope(),
823  'user_attribute' => $this->server->getUserAttribute(),
824  'filter' => $this->server->getFilter(),
825  'group_dn' => $this->server->getGroupDN(),
826  'group_scope' => $this->server->getGroupScope(),
827  'group_filter' => $this->server->getGroupFilter(),
828  'group_member' => $this->server->getGroupMember(),
829  'memberisdn' => $this->server->enabledGroupMemberIsDN(),
830  'group' => $this->server->getGroupName(),
831  'group_attribute' => $this->server->getGroupAttribute(),
832  'group_optional' => $this->server->isMembershipOptional(),
833  'group_user_filter' => $this->server->getGroupUserFilter(),
834  'sync_on_login' => $this->server->enabledSyncOnLogin(),
835  'sync_per_cron' => $this->server->enabledSyncPerCron(),
836  'global_role' => ilLDAPAttributeMapping::_lookupGlobalRole($this->server->getServerId()),
837  'migration' => (int) $this->server->isAccountMigrationEnabled(),
838  "name_filter" => $this->server->getUsernameFilter(),
839  'escape_dn' => $this->server->enabledEscapeDN()
840  ));
841  }
842 
843  private function initForm(): void
844  {
845  $this->form_gui = new ilPropertyFormGUI();
846  $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'save'));
847  $this->form_gui->setTitle($this->lng->txt('ldap_configure'));
848 
849  $active = new ilCheckboxInputGUI($this->lng->txt('auth_ldap_enable'), 'active');
850  $active->setValue("1");
851  $this->form_gui->addItem($active);
852 
853  $ds = new ilCheckboxInputGUI($this->lng->txt('ldap_as_ds'), 'ds');
854  $ds->setValue("1");
855  $ds->setInfo($this->lng->txt('ldap_as_ds_info'));
856  $this->form_gui->addItem($ds);
857 
858  $servername = new ilTextInputGUI($this->lng->txt('ldap_server_name'), 'server_name');
859  $servername->setRequired(true);
860  $servername->setInfo($this->lng->txt('ldap_server_name_info'));
861  $servername->setSize(32);
862  $servername->setMaxLength(32);
863  $this->form_gui->addItem($servername);
864 
865  // start Patch Name Filter
866  $namefilter = new ilTextInputGUI($this->lng->txt('ldap_username_filter'), "name_filter");//ADD LANG VAR
867  $namefilter->setInfo($this->lng->txt("ldap_username_filter_info"));
868  $namefilter->setSize(64);
869  $namefilter->setMaxLength(255);
870  $this->form_gui->addItem($namefilter);
871  // end Patch Name Filter
872 
873  $serverurl = new ilTextInputGUI($this->lng->txt('ldap_server'), 'server_url');
874  $serverurl->setRequired(true);
875  $serverurl->setInfo($this->lng->txt('ldap_server_url_info'));
876  $serverurl->setSize(64);
877  $serverurl->setMaxLength(255);
878  $this->form_gui->addItem($serverurl);
879 
880  $version = new ilSelectInputGUI($this->lng->txt('ldap_version'), 'version');
881  $version->setOptions(array(2 => 2, 3 => 3));
882  $version->setInfo($this->lng->txt('ldap_server_version_info'));
883  $this->form_gui->addItem($version);
884 
885  $basedsn = new ilTextInputGUI($this->lng->txt('basedn'), 'base_dn');
886  $basedsn->setRequired(true);
887  $basedsn->setSize(64);
888  $basedsn->setMaxLength(255);
889  $this->form_gui->addItem($basedsn);
890 
891  $referrals = new ilCheckboxInputGUI($this->lng->txt('ldap_referrals'), 'referrals');
892  $referrals->setValue("1");
893  $referrals->setInfo($this->lng->txt('ldap_referrals_info'));
894  $this->form_gui->addItem($referrals);
895 
896  $section_security = new ilFormSectionHeaderGUI();
897  $section_security->setTitle($this->lng->txt('ldap_server_security_settings'));
898  $this->form_gui->addItem($section_security);
899 
900  $tls = new ilCheckboxInputGUI($this->lng->txt('ldap_tls'), 'tls');
901  $tls->setValue("1");
902  $this->form_gui->addItem($tls);
903 
904  $binding = new ilRadioGroupInputGUI($this->lng->txt('ldap_server_binding'), 'binding_type');
905  $anonymous = new ilRadioOption($this->lng->txt('ldap_bind_anonymous'), (string) ilLDAPServer::LDAP_BIND_ANONYMOUS);
906  $binding->addOption($anonymous);
907  $user = new ilRadioOption($this->lng->txt('ldap_bind_user'), (string) ilLDAPServer::LDAP_BIND_USER);
908  $dn = new ilTextInputGUI($this->lng->txt('ldap_server_bind_dn'), 'bind_dn');
909  $dn->setSize(64);
910  $dn->setMaxLength(255);
911  $user->addSubItem($dn);
912  $pass = new ilPasswordInputGUI($this->lng->txt('ldap_server_bind_pass'), 'bind_pass');
913  $pass->setSkipSyntaxCheck(true);
914  $pass->setSize(12);
915  $pass->setMaxLength(100);
916  $user->addSubItem($pass);
917  $binding->addOption($user);
918  $this->form_gui->addItem($binding);
919 
920  $section_auth = new ilFormSectionHeaderGUI();
921  $section_auth->setTitle($this->lng->txt('ldap_authentication_settings'));
922  $this->form_gui->addItem($section_auth);
923 
924  $search_base = new ilTextInputGUI($this->lng->txt('ldap_user_dn'), 'search_base');
925  $search_base->setInfo($this->lng->txt('ldap_search_base_info'));
926  $search_base->setSize(64);
927  $search_base->setMaxLength(255);
928  $this->form_gui->addItem($search_base);
929 
930  $user_scope = new ilSelectInputGUI($this->lng->txt('ldap_user_scope'), 'user_scope');
931  $user_scope->setOptions(array(ilLDAPServer::LDAP_SCOPE_ONE => $this->lng->txt('ldap_scope_one'),
932  ilLDAPServer::LDAP_SCOPE_SUB => $this->lng->txt('ldap_scope_sub')));
933  $user_scope->setInfo($this->lng->txt('ldap_user_scope_info'));
934  $this->form_gui->addItem($user_scope);
935 
936  $user_attribute = new ilTextInputGUI($this->lng->txt('ldap_user_attribute'), 'user_attribute');
937  $user_attribute->setSize(16);
938  $user_attribute->setMaxLength(64);
939  $user_attribute->setRequired(true);
940  $this->form_gui->addItem($user_attribute);
941 
942  $filter = new ilTextInputGUI($this->lng->txt('ldap_search_filter'), 'filter');
943  $filter->setInfo($this->lng->txt('ldap_filter_info'));
944  $filter->setSize(64);
945  $filter->setMaxLength(512);
946  $this->form_gui->addItem($filter);
947 
948  $section_restrictions = new ilFormSectionHeaderGUI();
949  $section_restrictions->setTitle($this->lng->txt('ldap_group_restrictions'));
950  $this->form_gui->addItem($section_restrictions);
951 
952  $group_dn = new ilTextInputGUI($this->lng->txt('ldap_group_search_base'), 'group_dn');
953  $group_dn->setInfo($this->lng->txt('ldap_group_dn_info'));
954  $group_dn->setSize(64);
955  $group_dn->setMaxLength(255);
956  $this->form_gui->addItem($group_dn);
957 
958  $group_scope = new ilSelectInputGUI($this->lng->txt('ldap_group_scope'), 'group_scope');
959  $group_scope->setOptions(array(ilLDAPServer::LDAP_SCOPE_ONE => $this->lng->txt('ldap_scope_one'),
960  ilLDAPServer::LDAP_SCOPE_SUB => $this->lng->txt('ldap_scope_sub')));
961  $group_scope->setInfo($this->lng->txt('ldap_group_scope_info'));
962  $this->form_gui->addItem($group_scope);
963 
964  $group_filter = new ilTextInputGUI($this->lng->txt('ldap_group_filter'), 'group_filter');
965  $group_filter->setInfo($this->lng->txt('ldap_group_filter_info'));
966  $group_filter->setSize(64);
967  $group_filter->setMaxLength(255);
968  $this->form_gui->addItem($group_filter);
969 
970  $group_member = new ilTextInputGUI($this->lng->txt('ldap_group_member'), 'group_member');
971  $group_member->setInfo($this->lng->txt('ldap_group_member_info'));
972  $group_member->setSize(32);
973  $group_member->setMaxLength(255);
974  $this->form_gui->addItem($group_member);
975 
976 
977  $group_member_isdn = new ilCheckboxInputGUI($this->lng->txt('ldap_memberisdn'), 'memberisdn');
978  #$group_member_isdn->setInfo($this->lng->txt('ldap_group_member_info'));
979  $this->form_gui->addItem($group_member_isdn);
980  #$group_member->addSubItem($group_member_isdn);
981 
982  $escapedn = new ilCheckboxInputGUI($this->lng->txt('ldap_escapedn'), 'escape_dn');
983  $escapedn->setValue("1");
984  $escapedn->setInfo($this->lng->txt('ldap_escapedn_info'));
985  $this->form_gui->addItem($escapedn);
986 
987  $group = new ilTextInputGUI($this->lng->txt('ldap_group_name'), 'group');
988  $group->setInfo($this->lng->txt('ldap_group_name_info'));
989  $group->setSize(32);
990  $group->setMaxLength(255);
991  $this->form_gui->addItem($group);
992 
993  $group_atrr = new ilTextInputGUI($this->lng->txt('ldap_group_attribute'), 'group_attribute');
994  $group_atrr->setInfo($this->lng->txt('ldap_group_attribute_info'));
995  $group_atrr->setSize(16);
996  $group_atrr->setMaxLength(64);
997  $this->form_gui->addItem($group_atrr);
998 
999  $group_optional = new ilCheckboxInputGUI($this->lng->txt('ldap_group_membership'), 'group_optional');
1000  $group_optional->setOptionTitle($this->lng->txt('ldap_group_member_optional'));
1001  $group_optional->setInfo($this->lng->txt('ldap_group_optional_info'));
1002  $group_optional->setValue("1");
1003  $group_user_filter = new ilTextInputGUI($this->lng->txt('ldap_group_user_filter'), 'group_user_filter');
1004  $group_user_filter->setSize(64);
1005  $group_user_filter->setMaxLength(255);
1006  $group_optional->addSubItem($group_user_filter);
1007  $this->form_gui->addItem($group_optional);
1008 
1009  $section_sync = new ilFormSectionHeaderGUI();
1010  $section_sync->setTitle($this->lng->txt('ldap_user_sync'));
1011  $this->form_gui->addItem($section_sync);
1012 
1013  $ci_gui = new ilCustomInputGUI($this->lng->txt('ldap_moment_sync'));
1014  $sync_on_login = new ilCheckboxInputGUI($this->lng->txt('ldap_sync_login'), 'sync_on_login');
1015  $sync_on_login->setValue("1");
1016  $ci_gui->addSubItem($sync_on_login);
1017  $sync_per_cron = new ilCheckboxInputGUI($this->lng->txt('ldap_sync_cron'), 'sync_per_cron');
1018  $sync_per_cron->setValue("1");
1019  $ci_gui->addSubItem($sync_per_cron);
1020  $ci_gui->setInfo($this->lng->txt('ldap_user_sync_info'));
1021  $this->form_gui->addItem($ci_gui);
1022 
1023  $global_role = new ilSelectInputGUI($this->lng->txt('ldap_global_role_assignment'), 'global_role');
1024  $global_role->setOptions($this->prepareGlobalRoleSelection());
1025  $global_role->setInfo($this->lng->txt('ldap_global_role_info'));
1026  $this->form_gui->addItem($global_role);
1027 
1028  $migr = new ilCheckboxInputGUI($this->lng->txt('auth_ldap_migration'), 'migration');
1029  $migr->setInfo($this->lng->txt('auth_ldap_migration_info'));
1030  $migr->setValue("1");
1031  $this->form_gui->addItem($migr);
1032 
1035  $this->form_gui,
1037  );
1038 
1039  $this->form_gui->addCommandButton('save', $this->lng->txt('save'));
1040  if ($this->ctrl->getCmd() === "addServerSettings") {
1041  $this->form_gui->addCommandButton('serverList', $this->lng->txt('cancel'));
1042  }
1043  }
1044 
1045  /*
1046  * Update Settings
1047  */
1048  public function save(): bool
1049  {
1050  $this->setSubTabs();
1051  $this->tabs_gui->setTabActive('settings');
1052 
1053  $this->initForm();
1054  if ($this->form_gui->checkInput()) {
1055  $this->server->toggleActive((bool) $this->form_gui->getInput('active'));
1056  $this->server->enableAuthentication(!(bool) $this->form_gui->getInput('ds'));
1057  $this->server->setName($this->form_gui->getInput('server_name'));
1058  $this->server->setUrl($this->form_gui->getInput('server_url'));
1059  $this->server->setVersion((int) $this->form_gui->getInput('version'));
1060  $this->server->setBaseDN($this->form_gui->getInput('base_dn'));
1061  $this->server->toggleReferrer((bool) $this->form_gui->getInput('referrals'));
1062  $this->server->toggleTLS((bool) $this->form_gui->getInput('tls'));
1063  $this->server->setBindingType((int) $this->form_gui->getInput('binding_type'));
1064  $this->server->setBindUser($this->form_gui->getInput('bind_dn'));
1065  $this->server->setBindPassword($this->form_gui->getInput('bind_pass'));
1066  $this->server->setSearchBase($this->form_gui->getInput('search_base'));
1067  $this->server->setUserScope((int) $this->form_gui->getInput('user_scope'));
1068  $this->server->setUserAttribute($this->form_gui->getInput('user_attribute'));
1069  $this->server->setFilter($this->form_gui->getInput('filter'));
1070  $this->server->setGroupDN($this->form_gui->getInput('group_dn'));
1071  $this->server->setGroupScope((int) $this->form_gui->getInput('group_scope'));
1072  $this->server->setGroupFilter($this->form_gui->getInput('group_filter'));
1073  $this->server->setGroupMember($this->form_gui->getInput('group_member'));
1074  $this->server->enableGroupMemberIsDN((bool) $this->form_gui->getInput('memberisdn'));
1075  $this->server->setGroupName($this->form_gui->getInput('group'));
1076  $this->server->setGroupAttribute($this->form_gui->getInput('group_attribute'));
1077  $this->server->setGroupUserFilter($this->form_gui->getInput('group_user_filter'));
1078  $this->server->toggleMembershipOptional((bool) $this->form_gui->getInput('group_optional'));
1079  $this->server->enableSyncOnLogin((bool) $this->form_gui->getInput('sync_on_login'));
1080  $this->server->enableSyncPerCron((bool) $this->form_gui->getInput('sync_per_cron'));
1081  $this->server->setGlobalRole((int) $this->form_gui->getInput('global_role'));
1082  $this->server->enableAccountMigration((bool) $this->form_gui->getInput('migration'));
1083  $this->server->setUsernameFilter($this->form_gui->getInput("name_filter"));
1084  $this->server->enableEscapeDN((bool) $this->form_gui->getInput('escape_dn'));
1085  if (!$this->server->validate()) {
1086  $this->main_tpl->setOnScreenMessage('failure', $this->ilErr->getMessage());
1087  $this->form_gui->setValuesByPost();
1088  $this->tpl->setContent($this->form_gui->getHTML());
1089  return false;
1090  }
1091 
1092  // Update or create
1093  if ($this->server->getServerId()) {
1094  $this->server->update();
1095  } else {
1096  $this->server->create();
1097  }
1098 
1099  // Now server_id exists => update LDAP attribute mapping
1100  $this->initAttributeMapping();
1101  $this->mapping->setRule('global_role', (string) $this->form_gui->getInput('global_role'), false);
1102  $this->mapping->save();
1103 
1104  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
1105  $this->ctrl->redirect($this, 'serverList');
1106  return true;
1107  }
1108 
1109  $this->form_gui->setValuesByPost();
1110  $this->tpl->setContent($this->form_gui->getHTML());
1111  return true;
1112  }
1113 
1114 
1115 
1119  private function setSubTabs(): void
1120  {
1121  $this->tabs_gui->clearTargets();
1122 
1123  $this->tabs_gui->setBackTarget(
1124  $this->lng->txt("back"),
1125  $this->ctrl->getLinkTarget($this, 'serverList')
1126  );
1127 
1128 
1129  $this->tabs_gui->addTab(
1130  "settings",
1131  $this->lng->txt("ldap_settings"),
1132  $this->ctrl->getLinkTarget($this, 'editServerSettings')
1133  );
1134 
1135  // Disable all other tabs, if server hasn't been configured.
1136  if (!count(ilLDAPServer::_getServerList())) {
1137  return;
1138  }
1139 
1140  $this->tabs_gui->addTab(
1141  "user_mapping",
1142  $this->lng->txt("ldap_user_mapping"),
1143  $this->ctrl->getLinkTarget($this, 'userMapping')
1144  );
1145 
1146  $this->tabs_gui->addTab(
1147  "role_assignments",
1148  $this->lng->txt('ldap_role_assignments'),
1149  $this->ctrl->getLinkTarget($this, 'roleAssignments')
1150  );
1151 
1152  $this->tabs_gui->addTab(
1153  "role_mapping",
1154  $this->lng->txt("ldap_role_mapping"),
1155  $this->ctrl->getLinkTarget($this, 'roleMapping')
1156  );
1157  }
1158 
1159 
1160  private function initServer(): void
1161  {
1162  $server_id = 0;
1163  if ($this->ldap_server_id) {
1164  $server_id = $this->ldap_server_id;
1165  }
1166 
1167 
1168  $this->server = new ilLDAPServer($server_id);
1169  }
1170 
1171  private function initAttributeMapping(): void
1172  {
1173  $this->mapping = ilLDAPAttributeMapping::_getInstanceByServerId($this->getServer()->getServerId());
1174  }
1175 
1176  private function initRoleMapping(): void
1177  {
1178  $this->role_mapping = ilLDAPRoleGroupMappingSettings::_getInstanceByServerId($this->getServer()->getServerId());
1179  }
1180 
1184  private function prepareGlobalRoleSelection(): array
1185  {
1186  $global_roles = ilUtil::_sortIds(
1187  $this->rbacReview->getGlobalRoles(),
1188  'object_data',
1189  'title',
1190  'obj_id'
1191  );
1192 
1193  $select[0] = $this->lng->txt('links_select_one');
1194  foreach ($global_roles as $role_id) {
1195  $select[$role_id] = ilObject::_lookupTitle((int) $role_id);
1196  }
1197  return $select;
1198  }
1199 
1200  private function getMappingFields(): array
1201  {
1202  return array('gender' => $this->lng->txt('gender'),
1203  'firstname' => $this->lng->txt('firstname'),
1204  'lastname' => $this->lng->txt('lastname'),
1205  'title' => $this->lng->txt('person_title'),
1206  'institution' => $this->lng->txt('institution'),
1207  'department' => $this->lng->txt('department'),
1208  'street' => $this->lng->txt('street'),
1209  'city' => $this->lng->txt('city'),
1210  'zipcode' => $this->lng->txt('zipcode'),
1211  'country' => $this->lng->txt('country'),
1212  'phone_office' => $this->lng->txt('phone_office'),
1213  'phone_home' => $this->lng->txt('phone_home'),
1214  'phone_mobile' => $this->lng->txt('phone_mobile'),
1215  'fax' => $this->lng->txt('fax'),
1216  'email' => $this->lng->txt('email'),
1217  'second_email' => $this->lng->txt('second_email'),
1218  'hobby' => $this->lng->txt('hobby'),
1219  'matriculation' => $this->lng->txt('matriculation'));
1220  }
1221 
1222  private function initUserDefinedFields(): void
1223  {
1224  $this->udf = ilUserDefinedFields::_getInstance();
1225  }
1226 
1227  private function prepareMappingSelect(): string
1228  {
1230  $this->mapping_template,
1231  'mapping_template',
1232  [0 => $this->lng->txt('ldap_mapping_template'),
1233  "inetOrgPerson" => 'inetOrgPerson',
1234  "organizationalPerson" => 'organizationalPerson',
1235  "person" => 'person',
1236  "ad_2003" => 'Active Directory (Win 2003)'
1237  ],
1238  false,
1239  true
1240  );
1241  }
1242 
1248  protected function initFormRoleAssignments(string $a_mode): void
1249  {
1250  $this->form = new ilPropertyFormGUI();
1251  $this->form->setFormAction($this->ctrl->getFormAction($this));
1252 
1253  switch ($a_mode) {
1254  case 'edit':
1255  $this->form->setTitle($this->lng->txt('ldap_edit_role_ass_rule'));
1256  $this->form->addCommandButton('updateRoleAssignment', $this->lng->txt('save'));
1257  //$this->form->addCommandButton('roleAssignments',$this->lng->txt('cancel'));
1258  break;
1259  case 'create':
1260  $this->form->setTitle($this->lng->txt('ldap_add_role_ass_rule'));
1261  $this->form->addCommandButton('addRoleAssignment', $this->lng->txt('ldap_btn_add_role_ass'));
1262  //$this->form->addCommandButton('roleAssignments',$this->lng->txt('cancel'));
1263  break;
1264  }
1265 
1266  // Role Selection
1267  $role = new ilRadioGroupInputGUI($this->lng->txt('ldap_ilias_role'), 'role_name');
1268  $role->setRequired(true);
1269 
1270  $global = new ilRadioOption($this->lng->txt('ldap_global_role'), "0");
1271 
1272  $role->addOption($global);
1273 
1274  $role_select = new ilSelectInputGUI('', 'role_id');
1275  $role_select->setOptions($this->prepareGlobalRoleSelection());
1276  $global->addSubItem($role_select);
1277 
1278  $local = new ilRadioOption($this->lng->txt('ldap_local_role'), "1");
1279 
1280  $role->addOption($local);
1281 
1282  $role_search = new ilRoleAutoCompleteInputGUI('', 'role_search', $this, 'addRoleAutoCompleteObject');
1283  $role_search->setSize(40);
1284  $local->addSubItem($role_search);
1285 
1286  $role->setInfo($this->lng->txt('ldap_role_name_info'));
1287  $this->form->addItem($role);
1288 
1289  // Update options
1290  $update = new ilNonEditableValueGUI($this->lng->txt('ldap_update_roles'), 'update_roles');
1291  $update->setValue($this->lng->txt('ldap_check_role_assignment'));
1292 
1293  $add = new ilCheckboxInputGUI('', 'add_missing');
1294  $add->setOptionTitle($this->lng->txt('ldap_add_missing'));
1295  $update->addSubItem($add);
1296 
1297  $remove = new ilCheckboxInputGUI('', 'remove_deprecated');
1298  $remove->setOptionTitle($this->lng->txt('ldap_remove_deprecated'));
1299  $update->addSubItem($remove);
1300 
1301  $this->form->addItem($update);
1302 
1303 
1304 
1305  // Assignment Type
1306  $group = new ilRadioGroupInputGUI($this->lng->txt('ldap_assignment_type'), 'type');
1307  #$group->setValue($current_rule->getType());
1308  $group->setRequired(true);
1309 
1310  // Option by group
1311  $radio_group = new ilRadioOption($this->lng->txt('ldap_role_by_group'), (string) ilLDAPRoleAssignmentRule::TYPE_GROUP);
1312 
1313  $dn = new ilTextInputGUI($this->lng->txt('ldap_group_dn'), 'dn');
1314  #$dn->setValue($current_rule->getDN());
1315  $dn->setSize(32);
1316  $dn->setMaxLength(512);
1317  $dn->setInfo($this->lng->txt('ldap_role_grp_dn_info'));
1318  $radio_group->addSubItem($dn);
1319  $at = new ilTextInputGUI($this->lng->txt('ldap_role_grp_at'), 'at');
1320  #$at->setValue($current_rule->getMemberAttribute());
1321  $at->setSize(16);
1322  $at->setMaxLength(128);
1323  $radio_group->addSubItem($at);
1324  $isdn = new ilCheckboxInputGUI($this->lng->txt('ldap_role_grp_isdn'), 'isdn');
1325  #$isdn->setChecked($current_rule->isMemberAttributeDN());
1326  $isdn->setInfo($this->lng->txt('ldap_group_member_info'));
1327  $radio_group->addSubItem($isdn);
1328  $radio_group->setInfo($this->lng->txt('ldap_role_grp_info'));
1329 
1330  $group->addOption($radio_group);
1331 
1332  // Option by Attribute
1333  $radio_attribute = new ilRadioOption($this->lng->txt('ldap_role_by_attribute'), (string) ilLDAPRoleAssignmentRule::TYPE_ATTRIBUTE);
1334  $name = new ilTextInputGUI($this->lng->txt('ldap_role_at_name'), 'name');
1335  #$name->setValue($current_rule->getAttributeName());
1336  $name->setSize(32);
1337  $name->setMaxLength(128);
1338  #$name->setInfo($this->lng->txt('ldap_role_at_name_info'));
1339  $radio_attribute->addSubItem($name);
1340 
1341  // Radio Attribute
1342  $val = new ilTextInputGUI($this->lng->txt('ldap_role_at_value'), 'value');
1343  #$val->setValue($current_rule->getAttributeValue());
1344  $val->setSize(32);
1345  $val->setMaxLength(128);
1346  #$val->setInfo($this->lng->txt('ldap_role_at_value_info'));
1347  $radio_attribute->addSubItem($val);
1348  $radio_attribute->setInfo($this->lng->txt('ldap_role_at_info'));
1349 
1350  $group->addOption($radio_attribute);
1351 
1352  // Option by Plugin
1353  $pl_active = $this->component_repository->getPluginSlotById("ldaphk")->hasActivePlugins();
1354  $pl = new ilRadioOption($this->lng->txt('ldap_plugin'), "3");
1355 
1356  $pl->setInfo($this->lng->txt('ldap_plugin_info'));
1357  $pl->setDisabled(!$pl_active);
1358 
1359  $id = new ilNumberInputGUI($this->lng->txt('ldap_plugin_id'), 'plugin_id');
1360  $id->setDisabled(!$pl_active);
1361  $id->setSize(3);
1362  $id->setMaxLength(3);
1363  $id->setMaxValue(999);
1364  $id->setMinValue(1);
1365  $pl->addSubItem($id);
1366 
1367  $group->addOption($pl);
1368  $this->form->addItem($group);
1369  }
1370 
1371 
1375  public function addRoleAutoCompleteObject(): void
1376  {
1378  }
1379 
1383  private function userMappingToolbar(): void
1384  {
1385  $select_form = new ilSelectInputGUI("mapping_template");
1386  $select_form->setPostVar("mapping_template");
1387  $options = array(
1388  "" => $this->lng->txt('ldap_mapping_template'),
1389  "inetOrgPerson" => 'inetOrgPerson',
1390  "organizationalPerson" => 'organizationalPerson',
1391  "person" => 'person',
1392  "ad_2003" => 'Active Directory (Win 2003)');
1393  $select_form->setOptions($options);
1394  $select_form->setValue($this->mapping_template);
1395 
1396  $this->toolbar->addInputItem($select_form);
1397  $this->toolbar->addFormButton($this->lng->txt('show'), "chooseMapping");
1398  $this->toolbar->setFormAction($this->ctrl->getFormAction($this, "chooseMapping"));
1399  }
1400 
1405  {
1406  $propertie_form = new ilPropertyFormGUI();
1407  $propertie_form->setTitle($this->lng->txt('ldap_mapping_table'));
1408  $propertie_form->setFormAction($this->ctrl->getFormAction($this, 'saveMapping'));
1409  $propertie_form->addCommandButton('saveMapping', $this->lng->txt('save'));
1410 
1411  foreach ($this->getMappingFields() as $mapping => $lang) {
1412  $text_form = new ilTextInputGUI($lang);
1413  $text_form->setPostVar($mapping . "_value");
1414  $text_form->setValue($this->mapping->getValue($mapping));
1415  $text_form->setSize(32);
1416  $text_form->setMaxLength(255);
1417  $propertie_form->addItem($text_form);
1418 
1419  $checkbox_form = new ilCheckboxInputGUI("");
1420  $checkbox_form->setPostVar($mapping . "_update");
1421  $checkbox_form->setChecked($this->mapping->enabledUpdate($mapping));
1422  $checkbox_form->setOptionTitle($this->lng->txt('ldap_update_field_info'));
1423  $propertie_form->addItem($checkbox_form);
1424  }
1425 
1426  $this->initUserDefinedFields();
1427  foreach ($this->udf->getDefinitions() as $definition) {
1428  $text_form = new ilTextInputGUI($definition['field_name']);
1429  $text_form->setPostVar('udf_' . $definition['field_id'] . '_value');
1430  $text_form->setValue($this->mapping->getValue('udf_' . $definition['field_id']));
1431  $text_form->setSize(32);
1432  $text_form->setMaxLength(255);
1433  $propertie_form->addItem($text_form);
1434 
1435  $checkbox_form = new ilCheckboxInputGUI("");
1436  $checkbox_form->setPostVar('udf_' . $definition['field_id'] . '_update');
1437  $checkbox_form->setChecked($this->mapping->enabledUpdate('udf_' . $definition['field_id']));
1438  $checkbox_form->setOptionTitle($this->lng->txt('ldap_update_field_info'));
1439  $propertie_form->addItem($checkbox_form);
1440  }
1441 
1442  return $propertie_form;
1443  }
1444 
1448  public function roleMapping(): void
1449  {
1450  $this->setSubTabs();
1451  $this->tabs_gui->setTabActive('role_mapping');
1452  $this->toolbar->addButton(
1453  $this->lng->txt("ldap_new_role_assignment"),
1454  $this->ctrl->getLinkTarget($this, 'addRoleMapping')
1455  );
1456 
1457  //Set propertyform for synchronization settings
1458  $propertie_form = new ilPropertyFormGUI();
1459  $propertie_form->setTitle($this->lng->txt('ldap_role_settings'));
1460  $propertie_form->setFormAction($this->ctrl->getFormAction($this, "saveSyncronizationSettings"));
1461  $propertie_form->addCommandButton("saveSyncronizationSettings", $this->lng->txt('save'));
1462  $role_active = new ilCheckboxInputGUI($this->lng->txt('ldap_role_active'));
1463  $role_active->setPostVar('role_sync_active');
1464  $role_active->setChecked($this->server->enabledRoleSynchronization());
1465  $propertie_form->addItem($role_active);
1466  $binding = new ilCombinationInputGUI($this->lng->txt('ldap_server_binding'));
1467  $binding->setInfo($this->lng->txt('ldap_role_bind_user_info'));
1468  $user = new ilTextInputGUI("");
1469  $user->setPostVar("role_bind_user");
1470  $user->setValue($this->server->getRoleBindDN());
1471  $user->setSize(50);
1472  $user->setMaxLength(255);
1473  $binding->addCombinationItem("0", $user, $this->lng->txt('ldap_role_bind_user'));
1474 
1475  $pass = new ilPasswordInputGUI("");
1476  $pass->setPostVar("role_bind_pass");
1477  $pass->setValue($this->server->getRoleBindPassword());
1478  $pass->setSize(12);
1479  $pass->setMaxLength(100);
1480  $pass->setRetype(false);
1481  $binding->addCombinationItem("1", $pass, $this->lng->txt('ldap_role_bind_pass'));
1482 
1483  $propertie_form->addItem($binding);
1484 
1485  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.ldap_role_mappings.html', 'components/ILIAS/LDAP');
1486  $this->tpl->setVariable("NEW_ASSIGNMENT_TBL", $propertie_form->getHTML());
1487 
1488  $table = new LDAPRoleMappingTable(
1489  $this->http->request(),
1490  $this->lng,
1492  new Factory(),
1493  $this->server->getServerId(),
1496  );
1497  $this->tpl->setVariable('RULES_TBL', $this->ui_renderer->render($table->getComponent()));
1498  }
1499 
1503  public function editRoleMapping(): void
1504  {
1505  $mapping = new ilLDAPRoleGroupMappingSetting($this->mapping_id);
1506  $mapping->read();
1507 
1508  $propertie_form = $this->initRoleMappingForm("updateRoleMapping");
1509  $propertie_form->setTitle($this->lng->txt('ldap_edit_role_assignment'));
1510  if ($propertie_form->getItemByPostVar("url")) {
1511  $propertie_form->getItemByPostVar("url")->setValue($mapping->getURL());
1512  }
1513  if ($propertie_form->getItemByPostVar("dn")) {
1514  $propertie_form->getItemByPostVar("dn")->setValue($mapping->getDN());
1515  }
1516  if ($propertie_form->getItemByPostVar("member")) {
1517  $propertie_form->getItemByPostVar("member")->setValue($mapping->getMemberAttribute());
1518  }
1519  if ($propertie_form->getItemByPostVar("memberisdn")) {
1520  $propertie_form->getItemByPostVar("memberisdn")->setChecked($mapping->getMemberISDN());
1521  }
1522  if ($propertie_form->getItemByPostVar("role")) {
1523  $propertie_form->getItemByPostVar("role")->setValue($mapping->getRoleName());
1524  }
1525  if ($propertie_form->getItemByPostVar("info")) {
1526  $propertie_form->getItemByPostVar("info")->setValue($mapping->getMappingInfo());
1527  }
1528  if ($propertie_form->getItemByPostVar("info_type")) {
1529  $propertie_form->getItemByPostVar("info_type")->setChecked($mapping->getMappingInfoType());
1530  }
1531 
1532  $this->tpl->setContent($propertie_form->getHTML());
1533  }
1534 
1535 
1536 
1540  public function createRoleMapping(): void
1541  {
1542  $propertie_form = $this->initRoleMappingForm("createRoleMapping");
1543 
1544  if ($propertie_form->checkInput() && $this->rbacReview->roleExists($propertie_form->getInput("role"))) {
1545  $mapping = new ilLDAPRoleGroupMappingSetting(0);
1546  $mapping->setServerId($this->server->getServerId());
1547  $mapping->setURL($propertie_form->getInput("url"));
1548  $mapping->setDN($propertie_form->getInput("dn"));
1549  $mapping->setMemberAttribute($propertie_form->getInput("member"));
1550  $mapping->setMemberISDN((bool) $propertie_form->getInput("memberisdn"));
1551  $mapping->setRoleByName($propertie_form->getInput("role"));
1552  $mapping->setMappingInfo($propertie_form->getInput("info"));
1553  $mapping->setMappingInfoType((bool) $propertie_form->getInput("info_type"));
1554  $mapping->save();
1555 
1556  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
1557  $this->ctrl->redirect($this, "roleMapping");
1558  } else {
1559  if (!$this->rbacReview->roleExists($propertie_form->getInput("role"))) {
1560  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("ldap_role_not_exists") . " " .
1561  $propertie_form->getInput("role"));
1562  }
1563  $propertie_form->setValuesByPost();
1564  $this->tpl->setContent($propertie_form->getHTML());
1565  }
1566  }
1567 
1571  public function confirmDeleteRoleMapping(): void
1572  {
1573  if (!$this->mappings) {
1574  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
1575  $this->ctrl->redirect($this, "roleMapping");
1576  return;
1577  }
1578 
1579  $c_gui = new ilConfirmationGUI();
1580 
1581  // set confirm/cancel commands
1582  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteRoleMapping"));
1583  $c_gui->setHeaderText($this->lng->txt("ldap_confirm_del_role_ass"));
1584  $c_gui->setCancel($this->lng->txt("cancel"), "roleMapping");
1585  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteRoleMapping");
1586 
1587  foreach ($this->mappings as $id) {
1588  $mapping = new ilLDAPRoleGroupMappingSetting($id);
1589  $mapping->read();
1590  $txt = $this->lng->txt('obj_role') . ": " . $mapping->getRoleName() . ", ";
1591  $txt .= $this->lng->txt('ldap_group_dn') . ": " . $mapping->getDN() . ", ";
1592  $txt .= $this->lng->txt('ldap_server_short') . " " . $mapping->getURL() . ", ";
1593  $txt .= $this->lng->txt('ldap_group_member_short') . " " . $mapping->getMemberAttribute();
1594 
1595  $c_gui->addItem("mappings[]", (string) $id, $txt);
1596  }
1597  $this->tpl->setContent($c_gui->getHTML());
1598  }
1599 
1600  public function addServerSettings(): void
1601  {
1602  $this->checkAccess("write");
1603 
1604  $this->ctrl->clearParameters($this);
1605 
1606  $this->initForm();
1607  $this->tpl->setContent($this->form_gui->getHTML());
1608  }
1609 
1610  public function editServerSettings(): void
1611  {
1612  $this->checkAccess("write");
1613 
1614  $this->setSubTabs();
1615  $this->tabs_gui->setTabActive('settings');
1616 
1617  $this->initForm();
1618  $this->setServerFormValues();
1619  $this->tpl->setContent($this->form_gui->getHTML());
1620  }
1621 
1622 
1626  public function confirmDeleteServerSettings(): void
1627  {
1628  $this->checkAccess("write");
1629 
1630  if (!$this->ldap_server_id) {
1631  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
1632  $this->serverList();
1633  return;
1634  }
1635 
1636  $c_gui = new ilConfirmationGUI();
1637 
1638  // set confirm/cancel commands
1639  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteServerSettings"));
1640  $c_gui->setHeaderText($this->lng->txt("ldap_confirm_del_server_settings"));
1641  $c_gui->setCancel($this->lng->txt("cancel"), "serverList");
1642  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteServerSettings");
1643 
1644  // add items to delete
1645  $setting = new ilLDAPServer($this->ldap_server_id);
1646  $c_gui->addItem('server_ids[]', (string) $setting->getServerId(), $setting->getName());
1647 
1648  $this->tpl->setContent($c_gui->getHTML());
1649  }
1650 
1654  public function deleteServerSettings(): void
1655  {
1656  if (!$this->server_ids) {
1657  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
1658  $this->serverList();
1659  return;
1660  }
1661 
1662  foreach ($this->server_ids as $server_id) {
1663  $setting = new ilLDAPServer($server_id);
1664  $setting->delete();
1665  }
1666  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('deleted'));
1667  $this->ctrl->redirect($this, "serverlist");
1668  }
1669 
1673  public function userMapping(): void
1674  {
1675  $this->initAttributeMapping();
1676 
1677  $this->setSubTabs();
1678  $this->tabs_gui->activateTab('user_mapping');
1679  $this->userMappingToolbar();
1680 
1681  $propertie_form = $this->initUserMappingForm();
1682 
1683  $this->tpl->setContent($propertie_form->getHTML());
1684  }
1685 
1686 
1687 
1688  public function activateServer(): void
1689  {
1690  $this->checkAccess("write");
1691 
1692  $this->server->toggleActive(true);
1693  $this->server->update();
1694  $this->serverList();
1695  }
1696 
1697  public function deactivateServer(): void
1698  {
1699  $this->checkAccess("write");
1700 
1701  $this->server->toggleActive(false);
1702  $this->server->update();
1703  $this->serverList();
1704  }
1705 
1706 
1707 
1708 
1713  private function initRoleMappingForm(string $command): ilPropertyFormGUI
1714  {
1715  $this->setSubTabs();
1716  $this->tabs_gui->activateTab('role_mapping');
1717 
1718  if ($this->mapping_id) {
1719  $this->ctrl->setParameter($this, 'mapping_id', $this->mapping_id);
1720  }
1721 
1722  $propertie_form = new ilPropertyFormGUI();
1723  $propertie_form->setTitle($this->lng->txt('ldap_mapping_table'));
1724  $propertie_form->setFormAction($this->ctrl->getFormAction($this, $command));
1725  $propertie_form->addCommandButton($command, $this->lng->txt('save'));
1726  $propertie_form->addCommandButton("roleMapping", $this->lng->txt('cancel'));
1727 
1728  $url = new ilTextInputGUI($this->lng->txt('ldap_server'));
1729  $url->setPostVar("url");
1730  $url->setSize(50);
1731  $url->setMaxLength(255);
1732  $url->setRequired(true);
1733 
1734  $group_dn = new ilTextInputGUI($this->lng->txt('ldap_group_dn'));
1735  $group_dn->setPostVar("dn");
1736  $group_dn->setSize(50);
1737  $group_dn->setMaxLength(255);
1738  $group_dn->setInfo($this->lng->txt('ldap_dn_info'));
1739  $group_dn->setRequired(true);
1740 
1741  $member = new ilTextInputGUI($this->lng->txt('ldap_group_member'));
1742  $member->setPostVar("member");
1743  $member->setSize(32);
1744  $member->setMaxLength(255);
1745  $member->setInfo($this->lng->txt('ldap_member_info'));
1746  $member->setRequired(true);
1747 
1748  $member_isdn = new ilCheckboxInputGUI("");
1749  $member_isdn->setPostVar("memberisdn");
1750  $member_isdn->setOptionTitle($this->lng->txt('ldap_memberisdn'));
1751 
1752  $role = new ilTextInputGUI($this->lng->txt('ldap_ilias_role'));
1753  $role->setPostVar("role");
1754  $role->setSize(32);
1755  $role->setMaxLength(255);
1756  $role->setInfo($this->lng->txt('ldap_role_info'));
1757  $role->setRequired(true);
1758 
1759  $info = new ilTextAreaInputGUI($this->lng->txt('ldap_info_text'));
1760  $info->setPostVar("info");
1761  $info->setCols(50);
1762  $info->setRows(3);
1763  $info->setInfo($this->lng->txt('ldap_info_text_info'));
1764 
1765  $info_type = new ilCheckboxInputGUI("");
1766  $info_type->setPostVar("info_type");
1767  $info_type->setOptionTitle($this->lng->txt('ldap_mapping_info_type'));
1768 
1769  $propertie_form->addItem($url);
1770  $propertie_form->addItem($group_dn);
1771  $propertie_form->addItem($member);
1772  $propertie_form->addItem($member_isdn);
1773  $propertie_form->addItem($role);
1774  $propertie_form->addItem($info);
1775  $propertie_form->addItem($info_type);
1776 
1777  return $propertie_form;
1778  }
1779 
1780 
1781 
1785  public function addRoleMapping(): void
1786  {
1787  $propertie_form = $this->initRoleMappingForm("createRoleMapping");
1788  if ($propertie_form->getItemByPostVar("url")) {
1789  $propertie_form->getItemByPostVar("url")->setValue($this->server->getUrl());
1790  }
1791  if ($this->mapping_id) {
1792  $mapping = new ilLDAPRoleGroupMappingSetting($this->mapping_id);
1793  $mapping->read();
1794  if ($propertie_form->getItemByPostVar("url")) {
1795  $propertie_form->getItemByPostVar("url")->setValue($mapping->getURL());
1796  }
1797  if ($propertie_form->getItemByPostVar("dn")) {
1798  $propertie_form->getItemByPostVar("dn")->setValue($mapping->getDN());
1799  }
1800  if ($propertie_form->getItemByPostVar("member")) {
1801  $propertie_form->getItemByPostVar("member")->setValue($mapping->getMemberAttribute());
1802  }
1803  if ($propertie_form->getItemByPostVar("memberisdn")) {
1804  $propertie_form->getItemByPostVar("memberisdn")->setChecked($mapping->getMemberISDN());
1805  }
1806  if ($propertie_form->getItemByPostVar("role")) {
1807  $propertie_form->getItemByPostVar("role")->setValue($mapping->getRoleName());
1808  }
1809  if ($propertie_form->getItemByPostVar("info")) {
1810  $propertie_form->getItemByPostVar("info")->setValue($mapping->getMappingInfo());
1811  }
1812  if ($propertie_form->getItemByPostVar("info_type")) {
1813  $propertie_form->getItemByPostVar("info_type")->setChecked($mapping->getMappingInfoType());
1814  }
1815  }
1816 
1817  $this->tpl->setContent($propertie_form->getHTML());
1818  }
1819 
1820 
1824  public function updateRoleMapping(): void
1825  {
1826  $propertie_form = $this->initRoleMappingForm("updateRoleMapping");
1827 
1828  if ($propertie_form->checkInput() && $this->rbacReview->roleExists($propertie_form->getInput("role"))) {
1829  $mapping = new ilLDAPRoleGroupMappingSetting($this->mapping_id);
1830  $mapping->setServerId($this->server->getServerId());
1831  $mapping->setURL($propertie_form->getInput("url"));
1832  $mapping->setDN($propertie_form->getInput("dn"));
1833  $mapping->setMemberAttribute($propertie_form->getInput("member"));
1834  $mapping->setMemberISDN((bool) $propertie_form->getInput("memberisdn"));
1835  $mapping->setRoleByName($propertie_form->getInput("role"));
1836  $mapping->setMappingInfo($propertie_form->getInput("info"));
1837  $mapping->setMappingInfoType((bool) $propertie_form->getInput("info_type"));
1838  $mapping->update();
1839 
1840  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
1841  $this->ctrl->redirect($this, "roleMapping");
1842  } else {
1843  if (!$this->rbacReview->roleExists($propertie_form->getInput("role"))) {
1844  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("ldap_role_not_exists") . " " .
1845  $propertie_form->getInput("role"));
1846  }
1847  $propertie_form->setValuesByPost();
1848  $this->tpl->setContent($propertie_form->getHTML());
1849  }
1850  }
1851 
1855  public function saveSyncronizationSettings(): void
1856  {
1857  $this->server->setRoleBindDN($this->role_bind_user);
1858  $this->server->setRoleBindPassword($this->role_bind_pass);
1859  $this->server->enableRoleSynchronization($this->role_sync_active);
1860 
1861  // Update or create
1862  if ($this->server->getServerId()) {
1863  $this->server->update();
1864  }
1865  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
1866  $this->ctrl->redirect($this, "roleMapping");
1867  }
1868 }
static checkLDAPLib()
Check if ldap module is installed.
confirmDeleteRules()
Confirm delete rules.
userMappingToolbar()
Create Toolbar.
static get(string $a_var)
checkRoleAssignmentInput(int $a_rule_id=0)
Check role assignment input.
This class represents an option in a radio group.
$res
Definition: ltiservices.php:66
Readable part of repository interface to ilComponentDataDB.
createRoleMapping()
Check add screen input and save to db.
loadRoleAssignmentRule(int $a_rule_id, bool $load_from_form=true)
Load input from form.
ilLDAPRoleGroupMappingSettings $role_mapping
__construct(int $a_auth_ref_id)
$version
Definition: plugin.php:24
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initFormRoleAssignments(string $a_mode)
Init form table for new role assignments.
saveSyncronizationSettings()
save Syncronization Settings on Role Mapping screen
static _getServerList()
Get list of all configured servers.
readonly ILIAS UI Factory $ui_factory
Additional user data fields definition.
setInfo(string $a_info)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static _getAllServer()
Get list of all configured servers.
readonly ILIAS Refinery Factory $refinery
prepareGlobalRoleSelection()
New implementation for InputForm.
getServer()
Get server settings.
updateRoleMapping()
Check edit screen input and save to db.
readonly ilObjectDataCache $object_data_cache
static formSelect( $selected, string $varname, array $options, bool $multiple=false, bool $direct_text=false, int $size=0, string $style_class="", array $attribs=[], bool $disabled=false)
Builds a select form field with options and shows the selected option first.
setSubTabs()
Set sub tabs for ldap section.
editRoleAssignment()
Edit role assignment.
static _getMappingRulesByClass(string $a_class)
Get mapping rule by objectClass.
$url
Definition: shib_logout.php:68
setOptions(array $a_options)
server()
description: > This example shows how a Progress Bar can be rendered and updated by the server...
Definition: server.php:43
setValuesByArray()
set values of form array
ilGlobalTemplateInterface $main_tpl
showRoleSelection()
show role selection
ilGlobalTemplateInterface $tpl
confirmDeleteRoleMapping()
confirm delete role mappings
static _getRules($a_server_id)
Get all rules.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setMinWordLength(int $a_length)
ilPropertyFormGUI $form_gui
checkAccess(string $a_permission)
addRoleMapping()
Add Assigments for role mapping.
ilComponentRepository $component_repository
confirmDeleteServerSettings()
Confirm delete rules.
static http()
Fetches the global http state from ILIAS.
This class represents a property in a property form.
readonly ILIAS HTTP GlobalHttpState $http
static echoAutoCompleteList()
Static asynchronous default auto complete function.
static _lookupTitle(int $obj_id)
deleteRules()
delete role assignment rule
ilLDAPAttributeMapping $mapping
This class represents a number property in a property form.
addRoleAutoCompleteObject()
Add Member for autoComplete.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addRoleAssignment()
add new role assignment
global $DIC
Definition: shib_login.php:26
static _lookupGlobalRole(int $a_server_id)
userMapping()
Ldap User Mapping.
ilUserDefinedFields $udf
This class represents a password property in a property form.
roleAssignments()
Edit role assignments.
roleMapping()
Role Mapping Tab.
Builds data types.
Definition: Factory.php:35
updateRoleAssignment()
update role assignment
$txt
Definition: error.php:31
setRequired(bool $a_required)
This class represents a role + autocomplete feature form input.
This class stores the settings that define the mapping between LDAP attribute and user profile fields...
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,7),&#39;usr_data&#39;,&#39;lastname&#39;,&#39;usr_id&#39;) => sorts by lastname.
$lang
Definition: xapiexit.php:25
initUserMappingForm()
Create Property Form GUI for User Mapping.
saveRoleSelection()
Save role selection.
static _getInstanceByRuleId(int $a_rule_id)
This class represents a number property in a property form.
form( $class_path, string $cmd, string $submit_caption="")
static _getInstanceByServerId(int $a_server_id)
Get instance of class.
readonly ILIAS UI Renderer $ui_renderer
read()
Read mapping settings from db.
getAttributeMappingKeys()
Get all possible attribute keys for mapping ldap attribute to ilias user attributes.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This class represents a text area property in a property form.
static addFieldsToForm(int $a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
$info
Definition: entry_point.php:21
save()
Save mapping rules to db.
ilLDAPRoleAssignmentRule $rule
initRoleMappingForm(string $command)
init propertyformgui for Assignment of LDAP Attributes to ILIAS User Profile
static set(string $a_var, $a_val)
Set a value.
static _getInstanceByServerId(int $a_server_id)
ilLDAPRoleAssignmentRule $role_mapping_rule
getRoleAssignmentTable()
Show active role assignments.
editRoleMapping()
Edit Assigments for role mapping.