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