ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilShibbolethSettings.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  private const PREFIX = 'shib_';
27  private const DEFAULT_IDP_LIST = "urn:mace:organization1:providerID, Example Organization 1\nurn:mace:organization2:providerID, Example Organization 2, /Shibboleth.sso/WAYF/SWITCHaai";
28  private const DEFAULT_LOGIN_BUTTON = "assets/images/auth/shib_login_button.svg";
29  private const DEFAULT_ORGANISATION_SELECTION = "external_wayf";
30 
31  public const ACCOUNT_CREATION_ENABLED = "enabled";
32  public const ACCOUNT_CREATION_WITH_APPROVAL = "with_approval";
33  public const ACCOUNT_CREATION_DISABLED = "disabled";
34 
35  protected ilSetting $settings;
36  protected array $data = [];
37 
39  protected array $user_fields = [
40  'firstname' => true,
41  'lastname' => true,
42  'email' => true,
43  'title' => false,
44  'gender' => false,
45  'institution' => false,
46  'department' => false,
47  'zipcode' => false,
48  'city' => false,
49  'country' => false,
50  'street' => false,
51  'phone_office' => false,
52  'phone_home' => false,
53  'phone_mobile' => false,
54  'language' => false,
55  'matriculation' => false,
56  ];
57 
58  public function __construct()
59  {
60  global $DIC;
61 
62  $this->settings = $DIC->settings();
63  $this->read();
64  }
65 
69  public function getUserFields(): array
70  {
71  return $this->user_fields;
72  }
73 
74  public function read(): void
75  {
76  $filtered_data = array_filter(
77  $this->settings->getAll(),
78  static fn($value, string $key): bool => str_starts_with($key, self::PREFIX),
79  ARRAY_FILTER_USE_BOTH
80  );
81 
82  array_walk($filtered_data, function ($v, string $k): void {
83  $this->data[str_replace(self::PREFIX, '', $k)] = $v === '' ? null : $v;
84  });
85  }
86 
87  public function get(string $a_keyword, ?string $a_default_value = null): string
88  {
89  $a_keyword = str_replace(self::PREFIX, '', $a_keyword);
90 
91  return (string) ($this->data[$a_keyword] ?? $a_default_value);
92  }
93 
94  public function getAll(): array
95  {
96  return $this->data;
97  }
98 
99  public function set(string $a_key, string $a_val): void
100  {
101  $a_key = str_replace(self::PREFIX, '', $a_key);
102  $this->data[$a_key] = $a_val;
103  }
104 
105  public function store(): void
106  {
107  foreach ($this->data as $key => $value) {
108  $this->settings->set(self::PREFIX . $key, (string) $value);
109  }
110  }
111 
112  public function getDefaultRole(): int
113  {
114  return $this->data['user_default_role'] ?? 4;
115  }
116 
117  public function setDefaultRole(int $role_id): void
118  {
119  $this->data['user_default_role'] = $role_id;
120  }
121 
122  public function getIdPList(): string
123  {
124  return $this->data['idp_list'] ?? self::DEFAULT_IDP_LIST;
125  }
126 
127  public function setIdPList(string $list): void
128  {
129  $this->data['idp_list'] = $list;
130  }
131 
132  public function getLoginButton(): string
133  {
134  return $this->data['login_button'] ?? self::DEFAULT_LOGIN_BUTTON;
135  }
136 
137  public function setLoginButton(string $login_button): void
138  {
139  $this->data['login_button'] = $login_button;
140  }
141 
142  public function getOrganisationSelectionType(): string
143  {
144  return $this->data['hos_type'] ?? self::DEFAULT_ORGANISATION_SELECTION;
145  }
146 
147  public function setOrganisationSelectionType(string $type): void
148  {
149  $this->data['hos_type'] = $type;
150  }
151 
152  public function isActive(): bool
153  {
154  return (bool) ($this->data['active'] ?? false);
155  }
156 
157  public function setActive(bool $status): void
158  {
159  $this->data['active'] = $status;
160  }
161 
162  public function isLocalAuthAllowed(): bool
163  {
164  return (bool) ($this->data['auth_allow_local'] ?? false);
165  }
166 
167  public function setAllowLocalAuth(bool $status): void
168  {
169  $this->data['auth_allow_local'] = $status;
170  }
171 
172  public function getAccountCreation(): string
173  {
174  return $this->data['account_creation'] ?? self::ACCOUNT_CREATION_ENABLED;
175  }
176 
177  public function setAccountCreation(string $value): void
178  {
179  $this->data['account_creation'] = $value;
180  }
181 
182  public function getFederationName(): string
183  {
184  return ($this->data['federation_name'] ?? '');
185  }
186 
187  public function setFederationName(string $federation): void
188  {
189  $this->data['federation_name'] = $federation;
190  }
191 }
setFederationName(string $federation)
global $DIC
Definition: shib_login.php:25
setLoginButton(string $login_button)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...