19 declare(strict_types=1);
89 'hide_own_online_status',
98 'interests_help_offered',
99 'interests_help_looking',
100 'bs_allow_to_contact_me',
101 'chat_osc_accept_msg',
102 'chat_broadcast_typing',
126 $this->
ctrl = $DIC->ctrl();
127 $this->tpl = $DIC->ui()->mainTemplate();
128 $this->
lng = $DIC->language();
129 $this->
access = $DIC->access();
130 $this->
rbac = $DIC->rbac();
131 $this->error_handler = $DIC[
'ilErr'];
132 $this->
tabs = $DIC->tabs();
133 $this->
toolbar = $DIC[
'ilToolbar'];
134 $this->
help = $DIC[
'ilHelp'];
135 $this->httpState = $DIC->http();
137 $this->ui_factory = $DIC->ui()->factory();
138 $this->ui_renderer = $DIC->ui()->renderer();
140 $this->
lng->loadLanguageModule(
'auth');
145 if (!$this->
rbac->system()->checkAccess($operation, $this->ref_id)) {
146 $this->error_handler->raiseError($this->
lng->txt(
'msg_no_perm_read'), $this->error_handler->WARNING);
180 if ($this->httpState->wrapper()->query()->has(self::REQUEST_PARAM_SAML_IDP_ID)) {
181 $idpId = $this->httpState->wrapper()->query()->retrieve(
182 self::REQUEST_PARAM_SAML_IDP_ID,
185 } elseif ($this->httpState->wrapper()->post()->has(self::REQUEST_PARAM_SAML_IDP_ID)) {
186 $idpId = $this->httpState->wrapper()->post()->retrieve(
187 self::REQUEST_PARAM_SAML_IDP_ID,
192 if ($this->httpState->wrapper()->query()->has(
'saml_idps_table_action')) {
193 if ($this->httpState->wrapper()->query()->has(
'saml_idps_idp_id')) {
194 $idpIds = $this->httpState->wrapper()->query()->retrieve(
198 if (count($idpIds) === 1) {
199 $idpId = current($idpIds);
204 if ($this->httpState->wrapper()->post()->has(self::REQUEST_PARAM_SAML_IDP_IDS)) {
205 $idpIds = $this->httpState->wrapper()->post()->retrieve(
206 self::REQUEST_PARAM_SAML_IDP_IDS,
209 if (count($idpIds) === 1) {
210 $idpId = current($idpIds);
222 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_FAILURE, $this->
lng->txt(
'auth_saml_unknow_idp'),
true);
223 $this->
ctrl->setParameter($this, self::REQUEST_PARAM_SAML_IDP_ID, null);
224 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
234 $this->samlAuth = $factory->auth();
236 if (
'Database error: could not find driver' === $e->getMessage()) {
237 $this->tpl->setOnScreenMessage(
238 self::MESSAGE_TYPE_FAILURE,
239 $this->
lng->txt(
'auth_saml_err_sqlite_driver')
242 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_FAILURE, $e->getMessage());
246 $this->
help->setScreenIdComponent(
'auth');
247 $cmd = $this->
ctrl->getCmd();
248 if ($cmd === null || $cmd ===
'' || !method_exists($this, $cmd)) {
249 $cmd = self::DEFAULT_CMD;
253 $this->
ctrl->setParameter($this, self::REQUEST_PARAM_SAML_IDP_ID, $ipdId);
255 if (!in_array(strtolower($cmd),
array_map(
'strtolower', self::GLOBAL_COMMANDS),
true)) {
257 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
264 in_array(strtolower($cmd),
array_map(
'strtolower', self::GLOBAL_COMMANDS),
true) ||
265 in_array(strtolower($cmd),
array_map(
'strtolower', self::GLOBAL_ENTITY_COMMANDS),
true)
276 if ($this->samlAuth && $this->
rbac->system()->checkAccess(self::PERMISSION_WRITE, $this->ref_id)) {
278 $this->ui_factory->button()->standard(
279 $this->
lng->txt(
'auth_saml_add_idp_btn'),
280 $this->
ctrl->getLinkTarget($this,
'showNewIdpForm')
285 $federationMdUrl = rtrim(
288 ) .
'/metadata.php?client_id=' .
CLIENT_ID;
289 $info = $this->ui_factory->messageBox()->info(
291 $this->
lng->txt(
'auth_saml_idps_info'),
292 'auth/saml/config/config.php',
293 'auth/saml/config/authsources.php',
294 $this->ui_renderer->render(
295 $this->ui_factory->link()->standard(
296 'https://simplesamlphp.org/docs/stable/simplesamlphp-sp',
297 'https://simplesamlphp.org/docs/stable/simplesamlphp-sp' 300 $this->ui_renderer->render($this->ui_factory->link()->standard($federationMdUrl, $federationMdUrl))
310 $this->httpState->request(),
312 'handleTableActions',
313 $this->
rbac->system()->checkAccess(self::PERMISSION_WRITE, $this->ref_id)
315 $this->tpl->setContent($this->ui_renderer->render([$info, $table->get()]));
320 $action = $this->httpState->wrapper()->query()->retrieve(
321 'saml_idps_table_action',
323 $this->refinery->kindlyTo()->string(),
332 default => $this->
ctrl->redirect($this, self::DEFAULT_CMD),
340 $this->idp->setActive(
false);
341 $this->idp->persist();
343 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY),
true);
344 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
351 $this->idp->setActive(
true);
352 $this->idp->persist();
354 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY),
true);
355 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
360 switch ($a_view_mode) {
361 case self::VIEW_MODE_GLOBAL:
362 $this->
tabs->addSubTabTarget(
364 $this->
ctrl->getLinkTarget($this, self::DEFAULT_CMD),
366 self::GLOBAL_ENTITY_COMMANDS,
367 [self::DEFAULT_CMD,
'showNewIdpForm', self::CMD_SAVE_NEW_IDP]
372 $this->
tabs->addSubTabTarget(
374 $this->
ctrl->getLinkTarget($this,
'showSettings'),
375 [
'showSettings', self::CMD_SAVE_SETTINGS],
380 case self::VIEW_MODE_SINGLE:
381 $this->
tabs->clearTargets();
382 $this->
tabs->setBackTarget(
383 $this->
lng->txt(
'back'),
384 $this->
ctrl->getLinkTarget($this, self::DEFAULT_CMD)
387 $this->
tabs->addSubTabTarget(
388 'auth_saml_idp_settings',
389 $this->
ctrl->getLinkTarget($this, self::CMD_SHOW_IDP_SETTINGS),
390 [self::CMD_SHOW_IDP_SETTINGS, self::CMT_SAVE_IDP_SETTINGS],
394 $this->
tabs->addSubTabTarget(
395 self::LNG_AUTH_SAML_USER_MAPPING,
396 $this->
ctrl->getLinkTarget($this,
'showUserAttributeMappingForm'),
397 [
'showUserAttributeMappingForm', self::CMD_SAVE_USER_ATTRIBUTE_MAPPING],
412 $form->setFormAction($this->
ctrl->getFormAction($this, self::CMD_SAVE_USER_ATTRIBUTE_MAPPING));
413 $form->setTitle($this->
lng->txt(self::LNG_AUTH_SAML_USER_MAPPING));
416 foreach (array_keys($usr_profile->getStandardFields()) as
$id) {
417 if (in_array($id, self::IGNORED_USER_FIELDS,
true)) {
428 if (!$this->
access->checkAccess(self::PERMISSION_WRITE,
'', $this->ref_id)) {
429 foreach ($form->getItems() as $item) {
430 $item->setDisabled(
true);
433 $form->addCommandButton(self::CMD_SAVE_USER_ATTRIBUTE_MAPPING, $this->
lng->txt(self::CMD_SAVE));
447 $update_automatically =
new ilCheckboxInputGUI(
'', $field_name . self::PROP_UPDATE_SUFFIX);
448 $update_automatically->setOptionTitle($this->
lng->txt(
'auth_saml_update_field_info'));
449 $update_automatically->setValue(
'1');
450 $form->
addItem($update_automatically);
458 if ($form->checkInput()) {
459 $this->mapping->delete();
462 foreach (array_keys($usr_profile->getStandardFields()) as
$id) {
463 if (in_array($id, self::IGNORED_USER_FIELDS,
true)) {
467 $rule = $this->mapping->getEmptyRule();
468 $rule->setAttribute($id);
469 $rule->setExternalAttribute((
string) $form->getInput($rule->getAttribute()));
470 $rule->updateAutomatically((
bool) $form->getInput($rule->getAttribute() . self::PROP_UPDATE_SUFFIX));
471 $this->mapping[$rule->getAttribute()] = $rule;
475 $rule = $this->mapping->getEmptyRule();
476 $rule->setAttribute(
'udf_' . $definition[
'field_id']);
477 $rule->setExternalAttribute((
string) $form->getInput($rule->getAttribute()));
478 $rule->updateAutomatically((
bool) $form->getInput($rule->getAttribute() . self::PROP_UPDATE_SUFFIX));
479 $this->mapping[$rule->getAttribute()] = $rule;
482 $this->mapping->save();
484 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY));
487 $form->setValuesByPost();
494 $this->
tabs->setSubTabActive(self::LNG_AUTH_SAML_USER_MAPPING);
499 foreach ($this->mapping as $rule) {
500 $data[$rule->getAttribute()] = $rule->getExternalAttribute();
501 $data[$rule->getAttribute() . self::PROP_UPDATE_SUFFIX] = $rule->isAutomaticallyUpdated();
503 $form->setValuesByArray(
$data);
506 $this->tpl->setContent($form->getHTML());
512 $form->setFormAction($this->
ctrl->getFormAction($this, self::CMD_SAVE_SETTINGS));
513 $form->setTitle($this->
lng->txt(
'auth_saml_configure'));
515 $show_login_form =
new ilCheckboxInputGUI($this->
lng->txt(
'auth_saml_login_form'), self::LNG_LOGIN_FORM);
516 $show_login_form->setInfo($this->
lng->txt(
'auth_saml_login_form_info'));
517 $show_login_form->setValue(
'1');
518 $form->addItem($show_login_form);
520 if (!$this->
access->checkAccess(self::PERMISSION_WRITE,
'', $this->ref_id)) {
521 foreach ($form->getItems() as $item) {
522 $item->setDisabled(
true);
525 $form->addCommandButton(self::CMD_SAVE_SETTINGS, $this->
lng->txt(self::CMD_SAVE));
540 $this->
rbac->review()->getGlobalRoles(),
547 $select[0] = $this->
lng->txt(
'links_select_one');
548 foreach ($global_roles as $role_id) {
560 if ($form->checkInput()) {
562 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY));
565 $form->setValuesByPost();
574 $form->setValuesByArray([
579 $this->tpl->setContent($form->getHTML());
585 $form->setFormAction($this->
ctrl->getFormAction($this, self::CMT_SAVE_IDP_SETTINGS));
586 $form->setTitle(sprintf($this->
lng->txt(
'auth_saml_configure_idp'), $this->idp->getEntityId()));
589 $idp->setDisabled(
true);
590 $form->addItem($idp);
595 $local->setValue(
'1');
596 $local->setInfo($this->
lng->txt(
'auth_allow_local_info'));
597 $form->addItem($local);
599 $uid_claim =
new ilTextInputGUI($this->
lng->txt(
'auth_saml_uid_claim'),
'uid_claim');
600 $uid_claim->setInfo($this->
lng->txt(
'auth_saml_uid_claim_info'));
601 $uid_claim->setRequired(
true);
602 $form->addItem($uid_claim);
605 $sync->setInfo($this->
lng->txt(
'auth_saml_sync_info'));
606 $sync->setValue(
'1');
608 $username_claim =
new ilTextInputGUI($this->
lng->txt(
'auth_saml_username_claim'),
'login_claim');
609 $username_claim->setInfo($this->
lng->txt(
'auth_saml_username_claim_info'));
610 $username_claim->setRequired(
true);
611 $sync->addSubItem($username_claim);
615 $role->setRequired(
true);
616 $sync->addSubItem($role);
619 $migr->setInfo($this->
lng->txt(
'auth_saml_migration_info'));
620 $migr->setValue(
'1');
621 $sync->addSubItem($migr);
622 $form->addItem($sync);
624 if (!$this->
access->checkAccess(self::PERMISSION_WRITE,
'', $this->ref_id)) {
625 foreach ($form->getItems() as $item) {
626 $item->setDisabled(
true);
629 $form->addCommandButton(self::CMT_SAVE_IDP_SETTINGS, $this->
lng->txt(self::CMD_SAVE));
631 $form->addCommandButton(self::DEFAULT_CMD, $this->
lng->txt(self::LNG_CANCEL));
638 $this->
tabs->setSubTabActive(
'auth_saml_idp_settings');
640 if (null === $form) {
642 $data = $this->idp->toArray();
644 $form->setValuesByArray(
$data);
646 $form->setValuesByPost();
649 $this->
help->setSubScreenId(
'edit_idp');
651 $this->tpl->setContent($form->getHTML());
659 if ($form->checkInput()) {
660 $this->idp->bindForm($form);
661 $this->idp->persist();
662 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY));
664 $this->
storeMetadata($this->idp, $form->getInput(self::METADATA_STORAGE_KEY));
673 $form->setFormAction($this->
ctrl->getFormAction($this, self::CMD_SAVE_NEW_IDP));
674 $form->setTitle($this->
lng->txt(
'auth_saml_add_idp_btn'));
678 $form->addCommandButton(self::CMD_SAVE_NEW_IDP, $this->
lng->txt(self::CMD_SAVE));
679 $form->addCommandButton(
'listIdps', $this->
lng->txt(self::LNG_CANCEL));
689 if ($form->checkInput()) {
691 $idp->bindForm($form);
694 $this->
storeMetadata($idp, $form->getInput(self::METADATA_STORAGE_KEY));
696 $this->tpl->setOnScreenMessage(
697 self::MESSAGE_TYPE_SUCCESS,
698 $this->
lng->txt(self::LNG_SAVED_SUCCESSFULLY),
701 $this->
ctrl->setParameter($this, self::REQUEST_PARAM_SAML_IDP_ID, $idp->
getIdpId());
702 $this->
ctrl->redirect($this, self::CMD_SHOW_IDP_SETTINGS);
712 if (null === $form) {
715 $form->setValuesByPost();
718 $this->
help->setSubScreenId(
'create_idp');
720 $this->tpl->setContent($form->getHTML());
726 $this->
lng->txt(
'auth_saml_add_idp_md_label'),
727 self::METADATA_STORAGE_KEY,
733 $metadata->
setInfo($this->
lng->txt(
'auth_saml_add_idp_md_info'));
734 $metadata->setRows(20);
735 $metadata->setRequired(
true);
740 $metadata->setPurifier($purifier);
741 $metadata->usePurifier(
true);
747 $idpDisco = $this->samlAuth->getIdpDiscovery();
749 $data[self::METADATA_STORAGE_KEY] = $idpDisco->fetchIdpMetadata($idp->
getIdpId());
754 $idpDisco = $this->samlAuth->getIdpDiscovery();
755 $idpDisco->storeIdpMetadata($idp->
getIdpId(), $metadata);
763 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'deleteIdp'));
764 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'deleteIdp');
765 $confirmation->setCancel($this->
lng->txt(self::LNG_CANCEL), self::DEFAULT_CMD);
766 $confirmation->setHeaderText($this->
lng->txt(
'auth_saml_sure_delete_idp'));
767 $confirmation->addItem(self::REQUEST_PARAM_SAML_IDP_IDS, (
string) $this->idp->getIdpId(), $this->idp->getEntityId());
769 $this->tpl->setContent($confirmation->getHTML());
776 $idpDisco = $this->samlAuth->getIdpDiscovery();
777 $idpDisco->deleteIdpMetadata($this->idp->getIdpId());
779 $this->idp->delete();
781 $this->tpl->setOnScreenMessage(self::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'auth_saml_deleted_idp'),
true);
783 $this->
ctrl->setParameter($this, self::REQUEST_PARAM_SAML_IDP_ID, null);
784 $this->
ctrl->redirect($this, self::DEFAULT_CMD);
const MESSAGE_TYPE_SUCCESS
showNewIdpForm(ilPropertyFormGUI $form=null)
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
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
Composite for nesting multiple purifiers.
showSettings(ilPropertyFormGUI $form=null)
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
getSafePostCommands()
This method must return a list of safe POST commands.
Class ilExternalAuthUserAttributeMapping.
showIdpSettings(ilPropertyFormGUI $form=null)
readonly RBACServices $rbac
static _lookupTitle(int $obj_id)
readonly ilGlobalTemplateInterface $tpl
initUserAttributeMapping()
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
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
showUserAttributeMappingForm(ilPropertyFormGUI $form=null)
readonly ilAccessHandler $access
const MESSAGE_TYPE_FAILURE
Interface ilCtrlSecurityInterface provides ilCtrl security information.
const REQUEST_PARAM_SAML_IDP_IDS
const CMD_SAVE_USER_ATTRIBUTE_MAPPING
addMetadataElement(ilPropertyFormGUI $form)