19 declare(strict_types=1);
64 self::CMD_SHOW_SETTINGS,
65 self::CMD_SAVE_SETTINGS,
82 'hide_own_online_status',
91 'interests_help_offered',
92 'interests_help_looking',
93 'bs_allow_to_contact_me',
94 'chat_osc_accept_msg',
95 'chat_broadcast_typing',
118 $this->
ctrl = $DIC->ctrl();
119 $this->tpl = $DIC->ui()->mainTemplate();
120 $this->
lng = $DIC->language();
121 $this->
rbac = $DIC->rbac();
122 $this->error_handler = $DIC[
'ilErr'];
123 $this->
tabs = $DIC->tabs();
124 $this->
toolbar = $DIC[
'ilToolbar'];
125 $this->
help = $DIC[
'ilHelp'];
126 $this->http_state = $DIC->http();
128 $this->ui_factory = $DIC->ui()->factory();
129 $this->ui_renderer = $DIC->ui()->renderer();
131 $this->
lng->loadLanguageModule(
'auth');
136 if (!$this->
rbac->system()->checkAccess($operation, $this->ref_id)) {
137 $this->error_handler->raiseError($this->
lng->txt(
'msg_no_perm_read'), $this->error_handler->WARNING);
171 if ($this->http_state->wrapper()->query()->has(self::REQUEST_PARAM_SAML_IDP_ID)) {
172 $idpId = $this->http_state->wrapper()->query()->retrieve(
173 self::REQUEST_PARAM_SAML_IDP_ID,
176 } elseif ($this->http_state->wrapper()->post()->has(self::REQUEST_PARAM_SAML_IDP_ID)) {
177 $idpId = $this->http_state->wrapper()->post()->retrieve(
178 self::REQUEST_PARAM_SAML_IDP_ID,
183 if ($this->http_state->wrapper()->query()->has(
'saml_idps_table_action')) {
184 if ($this->http_state->wrapper()->query()->has(
'saml_idps_idp_id')) {
185 $idpIds = $this->http_state->wrapper()->query()->retrieve(
189 if (count($idpIds) === 1) {
190 $idpId = current($idpIds);
195 if ($this->http_state->wrapper()->post()->has(self::REQUEST_PARAM_SAML_IDP_IDS)) {
196 $idpIds = $this->http_state->wrapper()->post()->retrieve(
197 self::REQUEST_PARAM_SAML_IDP_IDS,
200 if (count($idpIds) === 1) {
201 $idpId = current($idpIds);
213 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_FAILURE, $this->
lng->txt(
'auth_saml_unknow_idp'),
true);
214 $this->
ctrl->setParameter($this, self::REQUEST_PARAM_SAML_IDP_ID,
null);
215 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
225 $this->saml_auth = $factory->auth();
227 if ($e->getMessage() ===
'Database error: could not find driver') {
228 $this->tpl->setOnScreenMessage(
229 self::MESSAGE_TYPE_FAILURE,
230 $this->
lng->txt(
'auth_saml_err_sqlite_driver')
233 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_FAILURE, $e->getMessage());
237 $this->
help->setScreenIdComponent(
'auth');
238 $cmd = $this->
ctrl->getCmd();
239 if ($cmd ===
null || $cmd ===
'' || !method_exists($this, $cmd)) {
240 $cmd = self::DEFAULT_CMD;
246 $this->
ctrl->setParameter($this, self::REQUEST_PARAM_SAML_IDP_ID, $idp_id);
249 if (!in_array(strtolower($cmd),
array_map(
'strtolower', self::GLOBAL_COMMANDS),
true)) {
251 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
258 if (in_array(strtolower($cmd),
array_map(
'strtolower', self::GLOBAL_COMMANDS),
true) ||
259 in_array(strtolower($cmd),
array_map(
'strtolower', self::GLOBAL_ENTITY_COMMANDS),
true)) {
270 if ($this->saml_auth && $this->
rbac->system()->checkAccess(self::PERMISSION_WRITE, $this->ref_id)) {
272 $this->ui_factory->button()->standard(
273 $this->
lng->txt(
'auth_saml_add_idp_btn'),
274 $this->
ctrl->getLinkTarget($this,
'showNewIdpForm')
279 $federation_md_url = rtrim(
282 ) .
'/metadata.php?client_id=' .
CLIENT_ID;
283 $info = $this->ui_factory->messageBox()->info(
285 $this->
lng->txt(
'auth_saml_idps_info'),
286 'auth/saml/config/config.php',
287 'auth/saml/config/authsources.php',
288 $this->ui_renderer->render(
289 $this->ui_factory->link()->standard(
290 'https://simplesamlphp.org/docs/stable/simplesamlphp-sp',
291 'https://simplesamlphp.org/docs/stable/simplesamlphp-sp' 294 $this->ui_renderer->render($this->ui_factory->link()->standard($federation_md_url, $federation_md_url))
304 $this->http_state->request(),
306 'handleTableActions',
307 $this->
rbac->system()->checkAccess(self::PERMISSION_WRITE, $this->ref_id)
309 $this->tpl->setContent($this->ui_renderer->render([
$info, $table->get()]));
314 $action = $this->http_state->wrapper()->query()->retrieve(
315 'saml_idps_table_action',
317 $this->refinery->kindlyTo()->string(),
326 default => $this->
ctrl->redirect($this, self::DEFAULT_CMD),
334 $this->idp->setActive(
false);
335 $this->idp->persist();
337 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY),
true);
338 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
345 $this->idp->setActive(
true);
346 $this->idp->persist();
348 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY),
true);
349 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
354 switch ($a_view_mode) {
355 case self::VIEW_MODE_GLOBAL:
356 $this->
tabs->addSubTabTarget(
358 $this->
ctrl->getLinkTarget($this, self::DEFAULT_CMD),
360 self::GLOBAL_ENTITY_COMMANDS,
361 [self::DEFAULT_CMD,
'showNewIdpForm', self::CMD_SAVE_NEW_IDP]
366 $this->
tabs->addSubTabTarget(
368 $this->
ctrl->getLinkTarget($this, self::CMD_SHOW_SETTINGS),
369 [self::CMD_SHOW_SETTINGS, self::CMD_SAVE_SETTINGS],
374 case self::VIEW_MODE_SINGLE:
375 $this->
tabs->clearTargets();
376 $this->
tabs->setBackTarget(
377 $this->
lng->txt(
'back'),
378 $this->
ctrl->getLinkTarget($this, self::DEFAULT_CMD)
381 $this->
tabs->addSubTabTarget(
382 'auth_saml_idp_settings',
383 $this->
ctrl->getLinkTarget($this, self::CMD_SHOW_IDP_SETTINGS),
384 [self::CMD_SHOW_IDP_SETTINGS, self::CMT_SAVE_IDP_SETTINGS],
388 $this->
tabs->addSubTabTarget(
389 self::LNG_AUTH_SAML_USER_MAPPING,
390 $this->
ctrl->getLinkTarget($this,
'showUserAttributeMappingForm'),
391 [
'showUserAttributeMappingForm', self::CMD_SAVE_USER_ATTRIBUTE_MAPPING],
406 $form->setFormAction($this->
ctrl->getFormAction($this, self::CMD_SAVE_USER_ATTRIBUTE_MAPPING));
407 $form->setTitle($this->
lng->txt(self::LNG_AUTH_SAML_USER_MAPPING));
410 foreach (array_keys($usr_profile->getStandardFields()) as
$id) {
411 if (in_array($id, self::IGNORED_USER_FIELDS,
true)) {
422 if ($this->
rbac->system()->checkAccess(self::PERMISSION_WRITE, $this->ref_id)) {
423 $form->addCommandButton(self::CMD_SAVE_USER_ATTRIBUTE_MAPPING, $this->
lng->txt(self::CMD_SAVE));
425 foreach ($form->getItems() as $item) {
426 $item->setDisabled(
true);
441 $update_automatically =
new ilCheckboxInputGUI(
'', $field_name . self::PROP_UPDATE_SUFFIX);
442 $update_automatically->setOptionTitle($this->
lng->txt(
'auth_saml_update_field_info'));
443 $update_automatically->setValue(
'1');
444 $form->
addItem($update_automatically);
452 if ($form->checkInput()) {
453 $this->mapping->delete();
456 foreach (array_keys($usr_profile->getStandardFields()) as
$id) {
457 if (in_array($id, self::IGNORED_USER_FIELDS,
true)) {
461 $rule = $this->mapping->getEmptyRule();
462 $rule->setAttribute($id);
463 $rule->setExternalAttribute((
string) $form->getInput($rule->getAttribute()));
464 $rule->updateAutomatically((
bool) $form->getInput($rule->getAttribute() . self::PROP_UPDATE_SUFFIX));
465 $this->mapping[$rule->getAttribute()] = $rule;
469 $rule = $this->mapping->getEmptyRule();
470 $rule->setAttribute(
'udf_' . $definition[
'field_id']);
471 $rule->setExternalAttribute((
string) $form->getInput($rule->getAttribute()));
472 $rule->updateAutomatically((
bool) $form->getInput($rule->getAttribute() . self::PROP_UPDATE_SUFFIX));
473 $this->mapping[$rule->getAttribute()] = $rule;
476 $this->mapping->save();
478 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY));
481 $form->setValuesByPost();
488 $this->
tabs->setSubTabActive(self::LNG_AUTH_SAML_USER_MAPPING);
493 foreach ($this->mapping as $rule) {
494 $data[$rule->getAttribute()] = $rule->getExternalAttribute();
495 $data[$rule->getAttribute() . self::PROP_UPDATE_SUFFIX] = $rule->isAutomaticallyUpdated();
497 $form->setValuesByArray(
$data);
500 $this->tpl->setContent($form->getHTML());
508 $access = $this->
rbac->system()->checkAccess(self::PERMISSION_WRITE, $this->ref_id);
509 $form = $this->ui_factory->input()->container()->form()->standard(
510 $this->
ctrl->getFormAction($this, $access ? self::CMD_SAVE_SETTINGS : self::CMD_SHOW_SETTINGS),
512 self::LNG_LOGIN_FORM => $this->ui_factory->input()->field()->checkbox(
513 $this->
lng->txt(
'auth_saml_login_form'),
514 $this->
lng->txt(
'auth_saml_login_form_info')
516 ->
withValue((
bool) ($values[self::LNG_LOGIN_FORM] ??
true))
517 ->withDisabled(!$access),
522 $form = $form->withSubmitLabel($this->
lng->txt(
'refresh'));
537 $this->
rbac->review()->getGlobalRoles(),
544 $select[0] = $this->
lng->txt(
'links_select_one');
545 foreach ($global_roles as $role_id) {
556 $form = $this->
getSettingsForm()->withRequest($this->http_state->request());
557 if (!$form->getError()) {
558 $data = $form->getData();
560 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY));
574 $title = $this->ui_factory->item()->standard($this->
lng->txt(
'auth_saml_configure'));
575 $this->tpl->setContent($this->ui_renderer->render([
581 private function getIdpSettingsForm(array $values = []):
StandardForm 583 $ui_field = $this->ui_factory->input()->field();
588 $this->
lng->txt(
'auth_saml_idp')
589 )->
withValue($values[
'entity_id'] ??
'')->withDisabled(
true),
590 self::METADATA_STORAGE_KEY => $ui_field
592 $this->
lng->txt(
'auth_saml_add_idp_md_label'),
593 $this->
lng->txt(
'auth_saml_add_idp_md_info')
596 ->withValue($values[self::METADATA_STORAGE_KEY] ??
'')
598 ->withDedicatedName(self::METADATA_STORAGE_KEY),
599 'allow_local_auth' => $ui_field->checkbox(
600 $this->
lng->txt(
'auth_allow_local'),
601 $this->
lng->txt(
'auth_allow_local_info')
602 )->
withValue((
bool) ($values[
'allow_local_auth'] ??
true)),
603 'uid_claim' => $ui_field->text(
604 $this->
lng->txt(
'auth_saml_uid_claim'),
605 $this->
lng->txt(
'auth_saml_uid_claim_info')
606 )->
withValue($values[
'uid_claim'] ??
'')->withRequired(
true),
607 'sync_status' => $ui_field->optionalGroup(
609 'login_claim' => $ui_field->text(
610 $this->lng->txt(
'auth_saml_username_claim'),
611 $this->
lng->txt(
'auth_saml_username_claim_info')
612 )->withRequired(
true),
613 'default_role_id' => $ui_field->select(
614 $this->
lng->txt(
'auth_saml_role_select'),
616 )->withRequired(
true),
617 'account_migr_status' => $ui_field->checkbox(
618 $this->
lng->txt(
'auth_saml_migration'),
619 $this->
lng->txt(
'auth_saml_migration_info')
622 $this->
lng->txt(
'auth_saml_sync'),
623 $this->
lng->txt(
'auth_saml_sync_info')
625 (isset($values[
'sync_status']) && $values[
'sync_status'])
627 'login_claim' => $values[
'login_claim'] ??
'',
628 'default_role_id' => $values[
'default_role_id'] ?? array_key_first($this->
prepareRoleSelection()),
629 'account_migr_status' => (bool) ($values[
'account_migr_status'] ??
true)
635 $write_access = $this->
rbac->system()->checkAccess(self::PERMISSION_WRITE, $this->ref_id);
637 if (!$write_access) {
643 $this->
ctrl->setParameter($this, self::REQUEST_PARAM_SAML_IDP_ID, $this->idp->getIdpId());
644 return $this->ui_factory->input()->container()->form()->standard(
645 $this->
ctrl->getFormAction($this, self::CMT_SAVE_IDP_SETTINGS),
652 $this->
tabs->setSubTabActive(
'auth_saml_idp_settings');
655 $data = $this->idp->toArray();
657 $form = $this->getIdpSettingsForm(
$data);
660 $this->
help->setSubScreenId(
'edit_idp');
662 $title = $this->ui_factory->item()->standard(
663 sprintf($this->
lng->txt(
'auth_saml_configure_idp'), $this->idp->getEntityId())
666 $this->tpl->setContent($this->ui_renderer->render([
676 $form = $this->getIdpSettingsForm()->withRequest($this->http_state->request());
678 if (!$form->getError()) {
679 $this->idp->bindForm($form);
680 $this->idp->persist();
682 $this->
storeMetadata($this->idp, $form->getData()[self::METADATA_STORAGE_KEY] ??
'');
683 $this->tpl->setOnScreenMessage(
684 self::MESSAGE_TYPE_SUCCESS,
685 $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY),
690 $this->
ctrl->redirect($this, self::CMD_SHOW_IDP_SETTINGS);
696 return $this->ui_factory->input()->container()->form()->standard(
697 $this->
ctrl->getFormAction($this, self::CMD_SAVE_NEW_IDP),
699 self::METADATA_STORAGE_KEY => $this->ui_factory
703 $this->
lng->txt(
'auth_saml_add_idp_md_label'),
704 $this->
lng->txt(
'auth_saml_add_idp_md_info')
706 ->
withValue($values[self::METADATA_STORAGE_KEY] ??
'')
708 ->withDedicatedName(self::METADATA_STORAGE_KEY),
718 if (!$form->getError()) {
722 $this->
storeMetadata($this->idp, $form->getData()[self::METADATA_STORAGE_KEY] ??
'');
724 $this->tpl->setOnScreenMessage(
725 self::MESSAGE_TYPE_SUCCESS,
726 $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY),
729 $this->
ctrl->setParameter($this, self::REQUEST_PARAM_SAML_IDP_ID, $idp->
getIdpId());
730 $this->
ctrl->redirect($this, self::CMD_SHOW_IDP_SETTINGS);
740 if ($form ===
null) {
743 $form = $form->withRequest($this->http_state->request());
746 $this->
help->setSubScreenId(
'create_idp');
748 $title = $this->ui_factory->item()->standard($this->
lng->txt(
'auth_saml_add_idp_btn'));
749 $this->tpl->setContent($this->ui_renderer->render([
757 $idp_disco = $this->saml_auth->getIdpDiscovery();
759 $data[self::METADATA_STORAGE_KEY] = $idp_disco->fetchIdpMetadata($idp->
getIdpId());
764 $idp_disco = $this->saml_auth->getIdpDiscovery();
765 $idp_disco->storeIdpMetadata($idp->
getIdpId(), $metadata);
773 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'deleteIdp'));
774 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'deleteIdp');
775 $confirmation->setCancel($this->
lng->txt(self::LNG_CANCEL), self::DEFAULT_CMD);
776 $confirmation->setHeaderText($this->
lng->txt(
'auth_saml_sure_delete_idp'));
777 $confirmation->addItem(
778 self::REQUEST_PARAM_SAML_IDP_IDS,
779 (
string) $this->idp->getIdpId(),
780 $this->idp->getEntityId()
783 $this->tpl->setContent($confirmation->getHTML());
790 $idp_disco = $this->saml_auth->getIdpDiscovery();
791 $idp_disco->deleteIdpMetadata($this->idp->getIdpId());
793 $this->idp->delete();
795 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'auth_saml_deleted_idp'),
true);
797 $this->
ctrl->setParameter($this, self::REQUEST_PARAM_SAML_IDP_ID,
null);
798 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
const array GLOBAL_COMMANDS
const int VIEW_MODE_GLOBAL
const string LNG_AUTH_SAML_USER_MAPPING
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
storeMetadata(ilSamlIdp $idp, string $metadata)
const string CMD_SHOW_SETTINGS
readonly ilErrorHandling $error_handler
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const array GLOBAL_ENTITY_COMMANDS
setSubTabs(int $a_view_mode)
bindForm(StandardForm $form)
const string CMD_SAVE_SETTINGS
showSettings(?StandardForm $form=null)
readonly GlobalHttpState $http_state
const string PROP_UPDATE_SUFFIX
populateWithMetadata(ilSamlIdp $idp, array &$data)
static getInstanceByIdpId(int $a_idp_id)
const string CMT_SAVE_IDP_SETTINGS
getUserAttributeMappingForm()
const string REQUEST_PARAM_SAML_IDP_ID
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
const string LNG_LOGIN_FORM
const string PERMISSION_WRITE
showIdpSettings(?StandardForm $form=null)
const string CMD_SAVE_NEW_IDP
getSafePostCommands()
This method must return a list of safe POST commands.
const string REQUEST_PARAM_SAML_IDP_IDS
const string CMD_SAVE_USER_ATTRIBUTE_MAPPING
readonly RBACServices $rbac
static _lookupTitle(int $obj_id)
readonly ilGlobalTemplateInterface $tpl
const string METADATA_STORAGE_KEY
initUserAttributeMapping()
getSettingsForm(array $values=[])
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readonly ilToolbarGUI $toolbar
Provides fluid interface to RBAC services.
showNewIdpForm(?StandardForm $form=null)
readonly ILIAS UI Renderer $ui_renderer
saveUserAttributeMapping()
ilExternalAuthUserAttributeMapping $mapping
ensureAccess(string $operation)
__construct(private readonly int $ref_id)
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),'usr_data','lastname','usr_id') => sorts by lastname.
readonly ilCtrlInterface $ctrl
readonly Refinery $refinery
readonly ILIAS UI Factory $ui_factory
const array IGNORED_USER_FIELDS
const int VIEW_MODE_SINGLE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addAttributeRuleFieldToForm(ilPropertyFormGUI $form, string $field_label, string $field_name)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
const string LNG_SAVED_SUCCESSFULLY
const string CMD_SHOW_IDP_SETTINGS
showUserAttributeMappingForm(?ilPropertyFormGUI $form=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const string MESSAGE_TYPE_SUCCESS
const string MESSAGE_TYPE_FAILURE