19 declare(strict_types=1);
65 self::CMD_SHOW_SETTINGS,
66 self::CMD_SAVE_SETTINGS,
87 'hide_own_online_status',
96 'interests_help_offered',
97 'interests_help_looking',
98 'bs_allow_to_contact_me',
99 'chat_osc_accept_msg',
100 'chat_broadcast_typing',
123 $this->
ctrl = $DIC->ctrl();
124 $this->tpl = $DIC->ui()->mainTemplate();
125 $this->
lng = $DIC->language();
126 $this->
rbac = $DIC->rbac();
127 $this->error_handler = $DIC[
'ilErr'];
128 $this->
tabs = $DIC->tabs();
129 $this->
toolbar = $DIC[
'ilToolbar'];
130 $this->
help = $DIC[
'ilHelp'];
131 $this->httpState = $DIC->http();
133 $this->ui_factory = $DIC->ui()->factory();
134 $this->ui_renderer = $DIC->ui()->renderer();
136 $this->
lng->loadLanguageModule(
'auth');
141 if (!$this->
rbac->system()->checkAccess($operation, $this->ref_id)) {
142 $this->error_handler->raiseError($this->
lng->txt(
'msg_no_perm_read'), $this->error_handler->WARNING);
164 if ($this->httpState->wrapper()->query()->has(self::REQUEST_PARAM_SAML_IDP_ID)) {
165 $idpId = $this->httpState->wrapper()->query()->retrieve(
166 self::REQUEST_PARAM_SAML_IDP_ID,
169 } elseif ($this->httpState->wrapper()->post()->has(self::REQUEST_PARAM_SAML_IDP_ID)) {
170 $idpId = $this->httpState->wrapper()->post()->retrieve(
171 self::REQUEST_PARAM_SAML_IDP_ID,
176 if ($this->httpState->wrapper()->query()->has(
'saml_idps_table_action')) {
177 if ($this->httpState->wrapper()->query()->has(
'saml_idps_idp_id')) {
178 $idpIds = $this->httpState->wrapper()->query()->retrieve(
182 if (count($idpIds) === 1) {
183 $idpId = current($idpIds);
188 if ($this->httpState->wrapper()->post()->has(self::REQUEST_PARAM_SAML_IDP_IDS)) {
189 $idpIds = $this->httpState->wrapper()->post()->retrieve(
190 self::REQUEST_PARAM_SAML_IDP_IDS,
193 if (count($idpIds) === 1) {
194 $idpId = current($idpIds);
206 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_FAILURE, $this->
lng->txt(
'auth_saml_unknow_idp'),
true);
207 $this->
ctrl->setParameter($this, self::REQUEST_PARAM_SAML_IDP_ID,
null);
208 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
218 $this->samlAuth = $factory->auth();
220 if (
'Database error: could not find driver' === $e->getMessage()) {
221 $this->tpl->setOnScreenMessage(
222 self::MESSAGE_TYPE_FAILURE,
223 $this->
lng->txt(
'auth_saml_err_sqlite_driver')
226 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_FAILURE, $e->getMessage());
230 $this->
help->setScreenIdComponent(
'auth');
231 $cmd = $this->
ctrl->getCmd();
232 if ($cmd ===
null || $cmd ===
'' || !method_exists($this, $cmd)) {
233 $cmd = self::DEFAULT_CMD;
237 $this->
ctrl->saveParameter($this, self::REQUEST_PARAM_SAML_IDP_ID);
239 if (!in_array(strtolower($cmd),
array_map(
'strtolower', self::GLOBAL_COMMANDS),
true)) {
241 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
248 in_array(strtolower($cmd),
array_map(
'strtolower', self::GLOBAL_COMMANDS),
true) ||
249 in_array(strtolower($cmd),
array_map(
'strtolower', self::GLOBAL_ENTITY_COMMANDS),
true)
260 if ($this->samlAuth && $this->
rbac->system()->checkAccess(self::PERMISSION_WRITE, $this->ref_id)) {
262 $this->ui_factory->button()->standard(
263 $this->
lng->txt(
'auth_saml_add_idp_btn'),
264 $this->
ctrl->getLinkTarget($this,
'showNewIdpForm')
269 $federationMdUrl = rtrim(
272 ) .
'/metadata.php?client_id=' .
CLIENT_ID;
273 $info = $this->ui_factory->messageBox()->info(
275 $this->
lng->txt(
'auth_saml_idps_info'),
276 'auth/saml/config/config.php',
277 'auth/saml/config/authsources.php',
278 $this->ui_renderer->render(
279 $this->ui_factory->link()->standard(
280 'https://simplesamlphp.org/docs/stable/simplesamlphp-sp',
281 'https://simplesamlphp.org/docs/stable/simplesamlphp-sp' 284 $this->ui_renderer->render($this->ui_factory->link()->standard($federationMdUrl, $federationMdUrl))
294 $this->httpState->request(),
296 'handleTableActions',
297 $this->
rbac->system()->checkAccess(self::PERMISSION_WRITE, $this->ref_id)
299 $this->tpl->setContent($this->ui_renderer->render([$info, $table->get()]));
304 $action = $this->httpState->wrapper()->query()->retrieve(
305 'saml_idps_table_action',
307 $this->refinery->kindlyTo()->string(),
316 default => $this->
ctrl->redirect($this, self::DEFAULT_CMD),
324 $this->idp->setActive(
false);
325 $this->idp->persist();
327 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY),
true);
328 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
335 $this->idp->setActive(
true);
336 $this->idp->persist();
338 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY),
true);
339 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
344 switch ($a_view_mode) {
345 case self::VIEW_MODE_GLOBAL:
346 $this->
tabs->addSubTabTarget(
348 $this->
ctrl->getLinkTarget($this, self::DEFAULT_CMD),
350 self::GLOBAL_ENTITY_COMMANDS,
351 [self::DEFAULT_CMD,
'showNewIdpForm', self::CMD_SAVE_NEW_IDP]
356 $this->
tabs->addSubTabTarget(
358 $this->
ctrl->getLinkTarget($this, self::CMD_SHOW_SETTINGS),
359 [self::CMD_SHOW_SETTINGS, self::CMD_SAVE_SETTINGS],
364 case self::VIEW_MODE_SINGLE:
365 $this->
tabs->clearTargets();
366 $this->
tabs->setBackTarget(
367 $this->
lng->txt(
'back'),
368 $this->
ctrl->getLinkTarget($this, self::DEFAULT_CMD)
371 $this->
tabs->addSubTabTarget(
372 'auth_saml_idp_settings',
373 $this->
ctrl->getLinkTarget($this, self::CMD_SHOW_IDP_SETTINGS),
374 [self::CMD_SHOW_IDP_SETTINGS, self::CMT_SAVE_IDP_SETTINGS],
378 $this->
tabs->addSubTabTarget(
379 self::LNG_AUTH_SAML_USER_MAPPING,
380 $this->
ctrl->getLinkTarget($this,
'showUserAttributeMappingForm'),
381 [
'showUserAttributeMappingForm', self::CMD_SAVE_USER_ATTRIBUTE_MAPPING],
396 $form->setFormAction($this->
ctrl->getFormAction($this, self::CMD_SAVE_USER_ATTRIBUTE_MAPPING));
397 $form->setTitle($this->
lng->txt(self::LNG_AUTH_SAML_USER_MAPPING));
400 foreach (array_keys($usr_profile->getStandardFields()) as
$id) {
401 if (in_array($id, self::IGNORED_USER_FIELDS,
true)) {
412 if (!$this->
rbac->system()->checkAccess(self::PERMISSION_WRITE, $this->ref_id)) {
413 foreach ($form->getItems() as $item) {
414 $item->setDisabled(
true);
417 $form->addCommandButton(self::CMD_SAVE_USER_ATTRIBUTE_MAPPING, $this->
lng->txt(self::CMD_SAVE));
431 $update_automatically =
new ilCheckboxInputGUI(
'', $field_name . self::PROP_UPDATE_SUFFIX);
432 $update_automatically->setOptionTitle($this->
lng->txt(
'auth_saml_update_field_info'));
433 $update_automatically->setValue(
'1');
434 $form->
addItem($update_automatically);
442 if ($form->checkInput()) {
443 $this->mapping->delete();
446 foreach (array_keys($usr_profile->getStandardFields()) as
$id) {
447 if (in_array($id, self::IGNORED_USER_FIELDS,
true)) {
451 $rule = $this->mapping->getEmptyRule();
452 $rule->setAttribute($id);
453 $rule->setExternalAttribute((
string) $form->getInput($rule->getAttribute()));
454 $rule->updateAutomatically((
bool) $form->getInput($rule->getAttribute() . self::PROP_UPDATE_SUFFIX));
455 $this->mapping[$rule->getAttribute()] = $rule;
459 $rule = $this->mapping->getEmptyRule();
460 $rule->setAttribute(
'udf_' . $definition[
'field_id']);
461 $rule->setExternalAttribute((
string) $form->getInput($rule->getAttribute()));
462 $rule->updateAutomatically((
bool) $form->getInput($rule->getAttribute() . self::PROP_UPDATE_SUFFIX));
463 $this->mapping[$rule->getAttribute()] = $rule;
466 $this->mapping->save();
468 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY));
471 $form->setValuesByPost();
478 $this->
tabs->setSubTabActive(self::LNG_AUTH_SAML_USER_MAPPING);
483 foreach ($this->mapping as $rule) {
484 $data[$rule->getAttribute()] = $rule->getExternalAttribute();
485 $data[$rule->getAttribute() . self::PROP_UPDATE_SUFFIX] = $rule->isAutomaticallyUpdated();
487 $form->setValuesByArray(
$data);
490 $this->tpl->setContent($form->getHTML());
498 $access = $this->
rbac->system()->checkAccess(self::PERMISSION_WRITE, $this->ref_id);
499 $form = $this->ui_factory->input()->container()->form()->standard(
500 $this->
ctrl->getFormAction($this, $access ? self::CMD_SAVE_SETTINGS : self::CMD_SHOW_SETTINGS),
502 self::LNG_LOGIN_FORM => $this->ui_factory->input()->field()->checkbox(
503 $this->
lng->txt(
'auth_saml_login_form'),
504 $this->
lng->txt(
'auth_saml_login_form_info')
506 ->
withValue((
bool) ($values[self::LNG_LOGIN_FORM] ??
true))
507 ->withDisabled(!$access),
512 $form = $form->withSubmitLabel($this->
lng->txt(
'refresh'));
527 $this->
rbac->review()->getGlobalRoles(),
534 $select[0] = $this->
lng->txt(
'links_select_one');
535 foreach ($global_roles as $role_id) {
546 $form = $this->
getSettingsForm()->withRequest($this->httpState->request());
547 if (!$form->getError()) {
548 $data = $form->getData();
550 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY));
564 $title = $this->ui_factory->item()->standard($this->
lng->txt(
'auth_saml_configure'));
565 $this->tpl->setContent($this->ui_renderer->render([
574 $form->setFormAction($this->
ctrl->getFormAction($this, self::CMT_SAVE_IDP_SETTINGS));
575 $form->setTitle(sprintf($this->
lng->txt(
'auth_saml_configure_idp'), $this->idp->getEntityId()));
578 $idp->setDisabled(
true);
579 $form->addItem($idp);
584 $local->setValue(
'1');
585 $local->setInfo($this->
lng->txt(
'auth_allow_local_info'));
586 $form->addItem($local);
588 $uid_claim =
new ilTextInputGUI($this->
lng->txt(
'auth_saml_uid_claim'),
'uid_claim');
589 $uid_claim->setInfo($this->
lng->txt(
'auth_saml_uid_claim_info'));
590 $uid_claim->setRequired(
true);
591 $form->addItem($uid_claim);
594 $sync->setInfo($this->
lng->txt(
'auth_saml_sync_info'));
595 $sync->setValue(
'1');
597 $username_claim =
new ilTextInputGUI($this->
lng->txt(
'auth_saml_username_claim'),
'login_claim');
598 $username_claim->setInfo($this->
lng->txt(
'auth_saml_username_claim_info'));
599 $username_claim->setRequired(
true);
600 $sync->addSubItem($username_claim);
604 $role->setRequired(
true);
605 $sync->addSubItem($role);
608 $migr->setInfo($this->
lng->txt(
'auth_saml_migration_info'));
609 $migr->setValue(
'1');
610 $sync->addSubItem($migr);
611 $form->addItem($sync);
613 if (!$this->
rbac->system()->checkAccess(self::PERMISSION_WRITE, $this->ref_id)) {
614 foreach ($form->getItems() as $item) {
615 $item->setDisabled(
true);
618 $form->addCommandButton(self::CMT_SAVE_IDP_SETTINGS, $this->
lng->txt(self::CMD_SAVE));
620 $form->addCommandButton(self::DEFAULT_CMD, $this->
lng->txt(self::LNG_CANCEL));
627 $this->
tabs->setSubTabActive(
'auth_saml_idp_settings');
629 if (
null === $form) {
631 $data = $this->idp->toArray();
633 $form->setValuesByArray(
$data);
635 $form->setValuesByPost();
638 $this->
help->setSubScreenId(
'edit_idp');
640 $this->tpl->setContent($form->getHTML());
648 if ($form->checkInput()) {
649 $this->idp->bindForm($form);
650 $this->idp->persist();
651 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY));
653 $this->
storeMetadata($this->idp, $form->getInput(self::METADATA_STORAGE_KEY));
662 $form->setFormAction($this->
ctrl->getFormAction($this, self::CMD_SAVE_NEW_IDP));
663 $form->setTitle($this->
lng->txt(
'auth_saml_add_idp_btn'));
667 $form->addCommandButton(self::CMD_SAVE_NEW_IDP, $this->
lng->txt(self::CMD_SAVE));
668 $form->addCommandButton(
'listIdps', $this->
lng->txt(self::LNG_CANCEL));
678 if ($form->checkInput()) {
680 $idp->bindForm($form);
683 $this->
storeMetadata($idp, $form->getInput(self::METADATA_STORAGE_KEY));
685 $this->tpl->setOnScreenMessage(
686 self::MESSAGE_TYPE_SUCCESS,
687 $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY),
690 $this->
ctrl->setParameter($this, self::REQUEST_PARAM_SAML_IDP_ID, $idp->
getIdpId());
691 $this->
ctrl->redirect($this, self::CMD_SHOW_IDP_SETTINGS);
701 if (
null === $form) {
704 $form->setValuesByPost();
707 $this->
help->setSubScreenId(
'create_idp');
709 $this->tpl->setContent($form->getHTML());
715 $this->
lng->txt(
'auth_saml_add_idp_md_label'),
716 self::METADATA_STORAGE_KEY,
722 $metadata->
setInfo($this->
lng->txt(
'auth_saml_add_idp_md_info'));
723 $metadata->setRows(20);
724 $metadata->setRequired(
true);
729 $metadata->setPurifier($purifier);
730 $metadata->usePurifier(
true);
736 $idpDisco = $this->samlAuth->getIdpDiscovery();
738 $data[self::METADATA_STORAGE_KEY] = $idpDisco->fetchIdpMetadata($idp->
getIdpId());
743 $idpDisco = $this->samlAuth->getIdpDiscovery();
744 $idpDisco->storeIdpMetadata($idp->
getIdpId(), $metadata);
752 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'deleteIdp'));
753 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'deleteIdp');
754 $confirmation->setCancel($this->
lng->txt(self::LNG_CANCEL), self::DEFAULT_CMD);
755 $confirmation->setHeaderText($this->
lng->txt(
'auth_saml_sure_delete_idp'));
756 $confirmation->addItem(self::REQUEST_PARAM_SAML_IDP_IDS, (
string) $this->idp->getIdpId(), $this->idp->getEntityId());
758 $this->tpl->setContent($confirmation->getHTML());
765 $idpDisco = $this->samlAuth->getIdpDiscovery();
766 $idpDisco->deleteIdpMetadata($this->idp->getIdpId());
768 $this->idp->delete();
770 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'auth_saml_deleted_idp'),
true);
772 $this->
ctrl->setParameter($this, self::REQUEST_PARAM_SAML_IDP_ID,
null);
773 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
const MESSAGE_TYPE_SUCCESS
storeMetadata(ilSamlIdp $idp, string $metadata)
const CMT_SAVE_IDP_SETTINGS
readonly ilErrorHandling $error_handler
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readonly GlobalHttpState $httpState
const METADATA_STORAGE_KEY
setSubTabs(int $a_view_mode)
const GLOBAL_ENTITY_COMMANDS
showSettings(?StandardForm $form=null)
Composite for nesting multiple purifiers.
const REQUEST_PARAM_SAML_IDP_ID
populateWithMetadata(ilSamlIdp $idp, array &$data)
static getInstanceByIdpId(int $a_idp_id)
getUserAttributeMappingForm()
const LNG_AUTH_SAML_USER_MAPPING
const IGNORED_USER_FIELDS
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Class ilExternalAuthUserAttributeMapping.
readonly RBACServices $rbac
static _lookupTitle(int $obj_id)
readonly ilGlobalTemplateInterface $tpl
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
const CMD_SHOW_IDP_SETTINGS
const LNG_SAVED_SUCCESSFULLY
Provides fluid interface to RBAC services.
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
showIdpSettings(?ilPropertyFormGUI $form=null)
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
showNewIdpForm(?ilPropertyFormGUI $form=null)
showUserAttributeMappingForm(?ilPropertyFormGUI $form=null)
const MESSAGE_TYPE_FAILURE
const REQUEST_PARAM_SAML_IDP_IDS
const CMD_SAVE_USER_ATTRIBUTE_MAPPING
addMetadataElement(ilPropertyFormGUI $form)