ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilOpenIdConnectSettings.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  const FILE_STORAGE = 'openidconnect/login_form_image';
14  const STORAGE_ID = 'oidc';
15 
18 
19  const LOGIN_ENFORCE = 0;
20  const LOGIN_STANDARD = 1;
21 
23  const LOGOUT_SCOPE_LOCAL = 1;
24 
29  private static $instance = null;
30 
31 
35  private $storage = null;
36 
40  private $filesystem = null;
41 
42 
46  private $active = false;
47 
51  private $provider = '';
52 
56  private $client_id = '';
57 
61  private $secret = '';
62 
66  private $login_element_type = self::LOGIN_ELEMENT_TYPE_TXT;
67 
72 
77 
81  private $login_prompt_type = self::LOGIN_ENFORCE;
82 
83 
87  private $logout_scope;
88 
92  private $custom_session = false;
93 
97  private $session_duration = 60;
98 
102  private $allow_sync;
103 
107  private $role;
108 
112  private $uid = '';
113 
117  private $profile_map = [];
118 
122  private $profile_update_map = [];
123 
127  private $role_mappings = [];
128 
129 
133  private function __construct()
134  {
135  global $DIC;
136 
137  $this->storage = new ilSetting(self::STORAGE_ID);
138  $this->filesystem = $DIC->filesystem()->web();
139  $this->load();
140  }
141 
146  public static function getInstance() : \ilOpenIdConnectSettings
147  {
148  if (!self::$instance) {
149  self::$instance = new self();
150  }
151  return new self::$instance;
152  }
153 
157  public function setActive(bool $active)
158  {
159  $this->active = $active;
160  }
161 
165  public function getActive() : bool
166  {
167  return $this->active;
168  }
169 
173  public function setProvider(string $url)
174  {
175  $this->provider = $url;
176  }
177 
181  public function getProvider() : string
182  {
183  return $this->provider;
184  }
185 
189  public function setClientId(string $client_id)
190  {
191  $this->client_id = $client_id;
192  }
193 
197  public function getClientId() : string
198  {
199  return $this->client_id;
200  }
201 
205  public function setSecret(string $secret)
206  {
207  $this->secret = $secret;
208  }
209 
213  public function getSecret() : string
214  {
215  return $this->secret;
216  }
217 
221  public function setLoginElementType(int $type)
222  {
223  $this->login_element_type = $type;
224  }
225 
229  public function getLoginElementType() : int
230  {
232  }
233 
237  public function setLoginElementImage(string $a_img_name)
238  {
239  $this->login_element_img_name = $a_img_name;
240  }
241 
245  public function getLoginElementImage() : string
246  {
248  }
249 
250  public function setLoginElementText(string $text)
251  {
252  $this->login_element_text = $text;
253  }
254 
255 
256  public function getLoginElemenText() : string
257  {
259  }
260 
264  public function setLoginPromptType(int $a_type)
265  {
266  $this->login_prompt_type = $a_type;
267  }
268 
272  public function getLoginPromptType() : int
273  {
275  }
276 
280  public function setLogoutScope(int $a_scope)
281  {
282  $this->logout_scope = $a_scope;
283  }
284 
288  public function getLogoutScope() : int
289  {
290  return $this->logout_scope;
291  }
292 
296  public function useCustomSession(bool $a_stat)
297  {
298  $this->custom_session = $a_stat;
299  }
300 
304  public function isCustomSession() : bool
305  {
306  return $this->custom_session;
307  }
308 
312  public function setSessionDuration(int $a_duration)
313  {
314  $this->session_duration = $a_duration;
315  }
316 
320  public function getSessionDuration() : int
321  {
323  }
324 
328  public function isSyncAllowed() : bool
329  {
330  return $this->allow_sync;
331  }
332 
336  public function allowSync(bool $a_stat)
337  {
338  $this->allow_sync = $a_stat;
339  }
340 
344  public function setRole(int $role)
345  {
346  $this->role = $role;
347  }
348 
352  public function getRole() : int
353  {
354  return $this->role;
355  }
356 
360  public function setUidField(string $field)
361  {
362  $this->uid = $field;
363  }
364 
368  public function getUidField() : string
369  {
370  return $this->uid;
371  }
372 
379  public function deleteImageFile()
380  {
381  if ($this->filesystem->has(self::FILE_STORAGE . '/' . $this->getLoginElementImage())) {
382  $this->filesystem->delete(self::FILE_STORAGE . '/' . $this->getLoginElementImage());
383  }
384  }
385 
389  public function hasImageFile() : bool
390  {
391  return
392  strlen($this->getLoginElementImage()) &&
393  $this->filesystem->has(self::FILE_STORAGE . '/' . $this->getLoginElementImage());
394  }
395 
399  public function getImageFilePath() : string
400  {
401  return implode(
402  '/',
403  [
405  self::FILE_STORAGE . '/' . $this->getLoginElementImage()
406  ]
407  );
408  }
409 
413  public function setRoleMappings(array $a_role_mappings)
414  {
415  $this->role_mappings = $a_role_mappings;
416  }
417 
421  public function getRoleMappings() : array
422  {
423  return (array) $this->role_mappings;
424  }
425 
430  public function getRoleMappingValueForId($a_role_id) : string
431  {
432  if (
433  isset($this->role_mappings[$a_role_id]) &&
434  isset($this->role_mappings[$a_role_id]['value'])
435  ) {
436  return (string) $this->role_mappings[$a_role_id]['value'];
437  }
438  return '';
439  }
440 
445  public function getRoleMappingUpdateForId($a_role_id) : bool
446  {
447  if (
448  isset($this->role_mappings[$a_role_id]) &&
449  isset($this->role_mappings[$a_role_id]['update'])
450  ) {
451  return (bool) $this->role_mappings[$a_role_id]['update'];
452  }
453  return '';
454  }
455 
459  public function save()
460  {
461  $this->storage->set('active', (int) $this->getActive());
462  $this->storage->set('provider', $this->getProvider());
463  $this->storage->set('client_id', $this->getClientId());
464  $this->storage->set('secret', $this->getSecret());
465  $this->storage->set('le_img', $this->getLoginElementImage());
466  $this->storage->set('le_text', $this->getLoginElemenText());
467  $this->storage->set('le_type', $this->getLoginElementType());
468  $this->storage->set('prompt_type', $this->getLoginPromptType());
469  $this->storage->set('logout_scope', $this->getLogoutScope());
470  $this->storage->set('custom_session', (int) $this->isCustomSession());
471  $this->storage->set('session_duration', (int) $this->getSessionDuration());
472  $this->storage->set('allow_sync', (int) $this->isSyncAllowed());
473  $this->storage->set('role', (int) $this->getRole());
474  $this->storage->set('uid', (string) $this->getUidField());
475 
476  foreach ($this->getProfileMappingFields() as $field => $lang_key) {
477  $this->storage->set('pmap_' . $field, $this->getProfileMappingFieldValue($field));
478  $this->storage->set('pumap_' . $field, $this->getProfileMappingFieldUpdate($field));
479  }
480  $this->storage->set('role_mappings', (string) serialize($this->getRoleMappings()));
481  }
482 
486  protected function load()
487  {
488  foreach ($this->getProfileMappingFields() as $field => $lang_key) {
489  $this->profile_map[$field] = (string) $this->storage->get('pmap_' . $field, '');
490  $this->profile_update_map[$field] = (bool) $this->storage->get('pumap_' . $field, '');
491  }
492 
493  $this->setActive((bool) $this->storage->get('active', 0));
494  $this->setProvider($this->storage->get('provider', ''));
495  $this->setClientId($this->storage->get('client_id', ''));
496  $this->setSecret($this->storage->get('secret', ''));
497  $this->setLoginElementImage($this->storage->get('le_img', ''));
498  $this->setLoginElementText($this->storage->get('le_text'));
499  $this->setLoginElementType($this->storage->get('le_type'));
500  $this->setLoginPromptType((int) $this->storage->get('prompt_type', self::LOGIN_ENFORCE));
501  $this->setLogoutScope((int) $this->storage->get('logout_scope', self::LOGOUT_SCOPE_GLOBAL));
502  $this->useCustomSession((bool) $this->storage->get('custom_session'), false);
503  $this->setSessionDuration((int) $this->storage->get('session_duration', 60));
504  $this->allowSync((bool) $this->storage->get('allow_sync'), false);
505  $this->setRole((int) $this->storage->get('role'), 0);
506  $this->setUidField((string) $this->storage->get('uid'), '');
507  $this->setRoleMappings((array) unserialize($this->storage->get('role_mappings', serialize([]))));
508  }
509 
513  public function getProfileMappingFieldValue(string $field) : string
514  {
515  return (string) $this->profile_map[$field];
516  }
517 
522  public function setProfileMappingFieldValue(string $field, string $value)
523  {
524  $this->profile_map[$field] = $value;
525  }
526 
531  public function getProfileMappingFieldUpdate(string $field) : bool
532  {
533  return (bool) $this->profile_update_map[$field];
534  }
535 
540  public function setProfileMappingFieldUpdate(string $field, bool $value)
541  {
542  $this->profile_update_map[$field] = $value;
543  }
544 
545 
549  public function getProfileMappingFields() : array
550  {
551  return [
552  'firstname' => 'firstname',
553  'lastname' => 'lastname',
554  'email' => 'email',
555  'birthday' => 'birthday'
556  ];
557  }
558 }
$type
global $DIC
Definition: saml.php:7
setProfileMappingFieldValue(string $field, string $value)
static getInstance()
Get singleton instance.
setRoleMappings(array $a_role_mappings)
setLoginElementType(int $type)
Set login element type.
$a_type
Definition: workflow.php:92
$text
Definition: errorreport.php:18
Class ilOpenIdConnectSettingsGUI.
__construct()
ilOpenIdConnectSettings constructor.
setProfileMappingFieldUpdate(string $field, bool $value)
$url
static getWebspaceDir($mode="filesystem")
get webspace directory