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