ILIAS  release_8 Revision v8.24
class.ilShibbolethSettingsForm.php
Go to the documentation of this file.
1<?php
2
22
29{
30 private $refinery;
31
32 protected ilCtrl $ctrl;
33 protected \ILIAS\UI\Factory $ui;
34 protected \ILIAS\UI\Renderer $renderer;
36 protected string $action;
37 protected \Psr\Http\Message\RequestInterface $request;
38 protected ilLanguage $lng;
40
41 public function __construct(ilShibbolethSettings $settings, string $action)
42 {
46 global $DIC;
47 $this->ui = $DIC->ui()->factory();
48 $this->renderer = $DIC->ui()->renderer();
49 $this->request = $DIC->http()->request();
50 $this->ctrl = $DIC->ctrl();
51 $this->lng = $DIC->language();
52 $this->settings = $settings;
53 $this->action = $action;
54 $this->refinery = $DIC->refinery();
55 $this->initForm();
56 }
57
58 protected function txt(string $var): string
59 {
60 return $this->lng->txt($var);
61 }
62
63 protected function infoTxt(string $var): string
64 {
65 return $this->txt($var . '_info');
66 }
67
68 public function getHTML(): string
69 {
70 return $this->renderer->render($this->form);
71 }
72
73 public function initForm(): void
74 {
75 $field = $this->ui->input()->field();
76 $custom_trafo = fn (callable $c) => $this->refinery->custom()->transformation($c);
78 $read_me_link = "./Services/AuthShibboleth/README.SHIBBOLETH.txt";
79 $active = $field->checkbox($this->txt('shib_active'), $this->lng->txt("auth_shib_instructions"))
80 ->withValue($this->settings->isActive())
81 ->withAdditionalTransformation($custom_trafo(function ($v): void {
82 $this->settings->setActive((bool) $v);
83 }));
84
85 $auth_allow_local = $field->checkbox($this->txt('auth_allow_local'))
86 ->withValue($this->settings->isLocalAuthAllowed())
87 ->withAdditionalTransformation($custom_trafo(function ($v): void {
88 $this->settings->setAllowLocalAuth((bool) $v);
89 }));
90
91 $admin_must_activate = $field->checkbox(
92 $this->txt('shib_activate_new'),
93 $this->lng->txt("shib_activate_new_info")
94 )->withValue($this->settings->adminMustActivate())
95 ->withAdditionalTransformation(
96 $custom_trafo(function ($v): void {
97 $this->settings->setAdminMustActivate((bool) $v);
98 })
99 );
100
101 $default_user_role = $field->select($this->txt('shib_user_default_role'), $this->getRoles())
102 ->withRequired(true)
103 ->withValue($this->settings->getDefaultRole())
104 ->withAdditionalTransformation($custom_trafo(function ($v): void {
105 $this->settings->setDefaultRole((int) $v);
106 }));
107
108 $basic_section = $field->section([
109 $active,
110 $auth_allow_local,
111 $admin_must_activate,
112 $default_user_role,
113 ], $this->txt('shib'));
114
115 // Federation
116 $federation_name = $field->text($this->txt('shib_federation_name'))
117 ->withRequired(true)
118 ->withValue($this->settings->getFederationName())
119 ->withAdditionalTransformation($custom_trafo(function ($v): void {
120 $this->settings->setFederationName((string) $v);
121 }));
122
123 $login_type = $field->switchableGroup([
124 'internal_wayf' => $field->group([
125 $field->textarea('', $this->txt('shib_idp_list'))
126 ->withValue($this->settings->getIdPList())
127 ->withAdditionalTransformation($custom_trafo(function ($v): void {
128 $this->settings->setIdPList((string) $v);
129 }))
130 ], $this->txt('shib_login_internal_wayf')),
131 'external_wayf' => $field->group([
132 $field->text('', $this->txt('shib_login_button'))
133 ->withValue($this->settings->getLoginButton())
134 ->withAdditionalTransformation($custom_trafo(function ($v): void {
135 $this->settings->setLoginButton((string) $v);
136 }))
137 ], $this->txt('shib_login_external_wayf')),
138 'embedded_wayf' => $field->group([], $this->txt('shib_login_embedded_wayf'))
139 ->withByline($this->txt('shib_login_embedded_wayf_description')),
140 ], $this->txt('shib_login_type'))
141 ->withRequired(true)
142 ->withValue($this->settings->getOrganisationSelectionType())
143 ->withAdditionalTransformation($custom_trafo(function ($v): void {
144 $this->settings->setOrganisationSelectionType($v[0]);
145 }));
146
147 $instructions = $field->textarea($this->txt('auth_login_instructions'))
148 ->withValue($this->settings->get('login_instructions', ''))
149 ->withAdditionalTransformation($custom_trafo(function ($v): void {
150 $this->settings->set('login_instructions', (string) $v);
151 }));
152
153 $data_manipulation = $field->text($this->txt('shib_data_conv'))
154 ->withValue($this->settings->get('data_conv'))
155 ->withAdditionalTransformation($custom_trafo(function ($v): void {
156 $this->settings->set('data_conv', (string) $v);
157 }));
158
159 $federation_section = $field->section([
160 $federation_name,
161 $login_type,
162 $instructions,
163 $data_manipulation
164 ], '');
165
166 // User Fields
167 $fields = [];
168 $fields[] = $field->text($this->txt('shib_login'))
169 ->withValue($this->settings->get('shib_login'))
170 ->withRequired(true)
171 ->withAdditionalTransformation($custom_trafo(function ($v): void {
172 $this->settings->set('shib_login', (string) $v);
173 }));
174 foreach ($this->settings->getUserFields() as $field_name => $required) {
175 $fields[] = $field->text($this->txt($field_name))
176 ->withValue($this->settings->get($field_name))
177 ->withRequired($required)
178 ->withAdditionalTransformation($custom_trafo(function ($v) use ($field_name): void {
179 $this->settings->set($field_name, (string) $v);
180 }));
181 $fields[] = $field->checkbox($this->txt('shib_update'))
182 ->withValue((bool) $this->settings->get('update_' . $field_name))
183 ->withAdditionalTransformation($custom_trafo(function ($v) use ($field_name): void {
184 $this->settings->set('update_' . $field_name, (string) $v);
185 }));
186 }
187
188 $user_fields = $field->section(
189 $fields,
190 ''
191 );
192
193 // COMPLETE FORM
194
195 $this->form = $this->ui->input()->container()->form()->standard(
196 $this->action,
197 [
198 $basic_section,
199 $federation_section,
200 $user_fields
201 ]
202 )->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) {
203 return true;
204 }));
205 }
206
207 public function setValuesByPost(): void
208 {
209 $this->form = $this->form->withRequest($this->request);
210 }
211
212 protected function fillObject(): bool
213 {
214 return $this->form->getData() === true;
215 }
216
217 public function saveObject(): bool
218 {
219 if (!$this->fillObject()) {
220 return false;
221 }
222 $this->settings->store();
223 return true;
224 }
225
229 protected function getRoles(int $filter = ilRbacReview::FILTER_ALL_GLOBAL): array
230 {
231 global $DIC;
232 $opt = [];
233 foreach ($DIC->rbac()->review()->getRolesByFilter($filter) as $role) {
234 $opt[$role['obj_id']] = $role['title'] . ' (' . $role['obj_id'] . ')';
235 }
236
237 return $opt;
238 }
239}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
Class ilCtrl provides processing control methods.
language handling
Class ilShibbolethSettingsForm.
Psr Http Message RequestInterface $request
getRoles(int $filter=ilRbacReview::FILTER_ALL_GLOBAL)
ILIAS UI Component Input Container Form Standard $form
Class ilShibbolethSettings.
$c
Definition: cli.php:38
global $DIC
Definition: feed.php:28
This describes a standard form.
Definition: Standard.php:27
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form( $class_path, string $cmd)