ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilShibbolethSettingsForm.php
Go to the documentation of this file.
1<?php
2
20use ILIAS\UI\Factory as UIFactory;
23use Psr\Http\Message\RequestInterface;
24use ILIAS\Refinery\Factory as Refinery;
25
32{
33 protected ilCtrl $ctrl;
34 protected ?StandardForm $form = null;
35 protected ilLanguage $lng;
37 protected Refinery $refinery;
39 protected RequestInterface $request;
40 protected UIFactory $ui;
42
43 public function __construct(
44 private readonly int $ref_id,
45 private readonly object $parentObject,
46 protected ilShibbolethSettings $settings,
47 protected readonly string $action,
48 protected readonly string $show_command = ''
49 ) {
50 global $DIC;
51 $this->ctrl = $DIC->ctrl();
52 $this->lng = $DIC->language();
53 $this->rbac_review = $DIC->rbac()->review();
54 $this->refinery = $DIC->refinery();
55 $this->renderer = $DIC->ui()->renderer();
56 $this->request = $DIC->http()->request();
57 $this->ui = $DIC->ui()->factory();
58 $this->rbac_system = $DIC->rbac()->system();
59
60 $this->initForm();
61 }
62
63 protected function txt(string $var): string
64 {
65 return $this->lng->txt($var);
66 }
67
68 protected function infoTxt(string $var): string
69 {
70 return $this->txt($var . '_info');
71 }
72
73 public function getHTML(): string
74 {
75 return $this->renderer->render($this->form);
76 }
77
78 public function initForm(): void
79 {
80 $field = $this->ui->input()->field();
81 $custom_trafo = fn(callable $c): Transformation => $this->refinery->custom()->transformation($c);
83 $active = $field->checkbox($this->txt('shib_active'), $this->lng->txt("auth_shib_instructions"))
84 ->withValue($this->settings->isActive())
85 ->withAdditionalTransformation($custom_trafo(function ($v): void {
86 $this->settings->setActive((bool) $v);
87 }));
88
89 $auth_allow_local = $field->checkbox($this->txt('auth_allow_local'))
90 ->withValue($this->settings->isLocalAuthAllowed())
91 ->withAdditionalTransformation($custom_trafo(function ($v): void {
92 $this->settings->setAllowLocalAuth((bool) $v);
93 }));
94
95 $account_creation = $field->switchableGroup(
96 [
98 [],
99 $this->lng->txt("shib_account_creation_enabled"),
100 $this->lng->txt("shib_account_creation_enabled_info")
101 ),
103 [],
104 $this->lng->txt("shib_account_creation_with_approval"),
105 $this->lng->txt("shib_account_creation_with_approval_info")
106 ),
108 [],
109 $this->lng->txt("shib_account_creation_disabled"),
110 $this->lng->txt("shib_account_creation_disabled_info")
111 )
112 ],
113 $this->lng->txt("shib_account_creation"),
114 $this->lng->txt("shib_account_creation_info")
115 )->withValue(
116 $this->settings->getAccountCreation()
117 )->withRequired(
118 true
119 )->withAdditionalTransformation($custom_trafo(function ($v): void {
120 $this->settings->setAccountCreation((string) $v[0]);
121 }));
122
123 $default_user_role = $field->select($this->txt('shib_user_default_role'), $this->getRoles())
124 ->withRequired(true)
125 ->withValue($this->settings->getDefaultRole())
126 ->withAdditionalTransformation($custom_trafo(function ($v): void {
127 $this->settings->setDefaultRole((int) $v);
128 }));
129
130 $basic_section = $field->section([
131 $active,
132 $auth_allow_local,
133 $account_creation,
134 $default_user_role,
135 ], $this->txt('shib'));
136
137 // Federation
138 $federation_name = $field->text($this->txt('shib_federation_name'))
139 ->withRequired(true)
140 ->withValue($this->settings->getFederationName())
141 ->withAdditionalTransformation($custom_trafo(function ($v): void {
142 $this->settings->setFederationName((string) $v);
143 }));
144
145 $login_type = $field->switchableGroup([
146 'internal_wayf' => $field->group([
147 $field->textarea('', $this->txt('shib_idp_list'))
148 ->withValue($this->settings->getIdPList())
149 ->withAdditionalTransformation($custom_trafo(function ($v): void {
150 $this->settings->setIdPList((string) $v);
151 }))
152 ], $this->txt('shib_login_internal_wayf')),
153 'external_wayf' => $field->group([
154 $field->text('', $this->txt('shib_login_button'))
155 ->withValue($this->settings->getLoginButton())
156 ->withAdditionalTransformation($custom_trafo(function ($v): void {
157 $this->settings->setLoginButton((string) $v);
158 }))
159 ], $this->txt('shib_login_external_wayf')),
160 'embedded_wayf' => $field->group([], $this->txt('shib_login_embedded_wayf'))
161 ->withByline($this->txt('shib_login_embedded_wayf_description')),
162 ], $this->txt('shib_login_type'))
163 ->withRequired(true)
164 ->withValue($this->settings->getOrganisationSelectionType())
165 ->withAdditionalTransformation($custom_trafo(function ($v): void {
166 $this->settings->setOrganisationSelectionType($v[0]);
167 }));
168
169 $instructions = $field->textarea($this->txt('auth_login_instructions'))
170 ->withValue($this->settings->get('login_instructions', ''))
171 ->withAdditionalTransformation($custom_trafo(function ($v): void {
172 $this->settings->set('login_instructions', htmlspecialchars_decode($v));
173 }));
174
175 $data_manipulation = $field->text($this->txt('shib_data_conv'))
176 ->withValue($this->settings->get('data_conv'))
177 ->withAdditionalTransformation($custom_trafo(function ($v): void {
178 $this->settings->set('data_conv', (string) $v);
179 }));
180
181 $federation_section = $field->section([
182 $federation_name,
183 $login_type,
184 $instructions,
185 $data_manipulation
186 ], '');
187
188 // User Fields
189 $fields = [];
190 $fields[] = $field->text($this->txt('shib_login'))
191 ->withValue($this->settings->get('shib_login'))
192 ->withRequired(true)
193 ->withAdditionalTransformation($custom_trafo(function ($v): void {
194 $this->settings->set('shib_login', (string) $v);
195 }));
196 foreach ($this->settings->getUserFields() as $field_name => $required) {
197 $fields[] = $field->text($this->txt($field_name))
198 ->withValue($this->settings->get($field_name))
199 ->withRequired($required)
200 ->withAdditionalTransformation($custom_trafo(function ($v) use ($field_name): void {
201 $this->settings->set($field_name, (string) $v);
202 }));
203 $fields[] = $field->checkbox($this->txt('shib_update'))
204 ->withValue((bool) $this->settings->get('update_' . $field_name))
205 ->withAdditionalTransformation($custom_trafo(function ($v) use ($field_name): void {
206 $this->settings->set('update_' . $field_name, (string) $v);
207 }));
208 }
209
210 $user_fields = $field->section(
211 $fields,
212 ''
213 );
214
215 // COMPLETE FORM
216 $access = $this->rbac_system->checkAccess('write', $this->ref_id);
217 if (!$access) {
218 $basic_section = $basic_section->withDisabled(true);
219 $federation_section = $federation_section->withDisabled(true);
220 $user_fields = $user_fields->withDisabled(true);
221 }
222
223 $this->form = $this->ui->input()->container()->form()->standard(
224 $this->ctrl->getFormAction($this->parentObject, $access ? $this->action : $this->show_command),
225 [
226 $basic_section,
227 $federation_section,
228 $user_fields
229 ]
230 );
231
232 if (!$access) {
233 $this->form = $this->form->withSubmitLabel($this->lng->txt('refresh'));
234 }
235 }
236
237 public function setValuesByPost(): void
238 {
239 $request = $this->request->withParsedBody(array_map('htmlspecialchars', $this->request->getParsedBody()));
240 $this->form = $this->form->withRequest($request);
241 }
242
243 protected function fillObject(): bool
244 {
245 return $this->form->getData() !== null;
246 }
247
248 public function saveObject(): bool
249 {
250 if (!$this->fillObject()) {
251 return false;
252 }
253 $this->settings->store();
254 return true;
255 }
256
260 protected function getRoles(int $filter = ilRbacReview::FILTER_ALL_GLOBAL): array
261 {
262 $opt = [];
263 foreach ($this->rbac_review->getRolesByFilter($filter) as $role) {
264 $opt[$role['obj_id']] = $role['title'] . ' (' . $role['obj_id'] . ')';
265 }
266
267 return $opt;
268 }
269}
renderer()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class ilCtrl provides processing control methods.
language handling
class ilRbacReview Contains Review functions of core Rbac.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
Class ilShibbolethSettingsForm.
getRoles(int $filter=ilRbacReview::FILTER_ALL_GLOBAL)
__construct(private readonly int $ref_id, private readonly object $parentObject, protected ilShibbolethSettings $settings, protected readonly string $action, protected readonly string $show_command='')
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: deliver.php:25
A transformation is a function from one datatype to another.
This describes a standard form.
Definition: Standard.php:30
An entity that renders components to a string output.
Definition: Renderer.php:31
$ref_id
Definition: ltiauth.php:66
form(?array $class_path, string $cmd, string $submit_caption="")
global $DIC
Definition: shib_login.php:26