ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilShibbolethSettings.php
Go to the documentation of this file.
1 <?php
2 
20 
22 
29 {
30  private const PREFIX = 'shib_';
31  private const DEFAULT_IDP_LIST = "urn:mace:organization1:providerID, Example Organization 1\nurn:mace:organization2:providerID, Example Organization 2, /Shibboleth.sso/WAYF/SWITCHaai";
32  private const DEFAULT_LOGIN_BUTTON = "templates/default/images/auth/shib_login_button.svg";
33  private const DEFAULT_ORGANISATION_SELECTION = "external_wayf";
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 => strpos($key, self::PREFIX) === 0,
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 
98  public function getAll(): array
99  {
100  return $this->data;
101  }
102 
103  public function set(string $a_key, string $a_val): void
104  {
105  $a_key = str_replace(self::PREFIX, '', $a_key);
106  $this->data[$a_key] = $a_val;
107  }
108 
109  public function store(): void
110  {
111  foreach ($this->data as $key => $value) {
112  $this->settings->set(self::PREFIX . $key, (string) $value);
113  }
114  }
115 
116  public function getDefaultRole(): int
117  {
118  return $this->data['user_default_role'] ?? 4;
119  }
120 
121  public function setDefaultRole(int $role_id): void
122  {
123  $this->data['user_default_role'] = $role_id;
124  }
125 
126  public function getIdPList(): string
127  {
128  return $this->data['idp_list'] ?? self::DEFAULT_IDP_LIST;
129  }
130 
131  public function setIdPList(string $list): void
132  {
133  $this->data['idp_list'] = $list;
134  }
135 
136  public function getLoginButton(): string
137  {
138  return $this->data['login_button'] ?? self::DEFAULT_LOGIN_BUTTON;
139  }
140 
141  public function setLoginButton(string $login_button): void
142  {
143  $this->data['login_button'] = $login_button;
144  }
145 
146  public function getOrganisationSelectionType(): string
147  {
148  return $this->data['hos_type'] ?? self::DEFAULT_ORGANISATION_SELECTION;
149  }
150 
151  public function setOrganisationSelectionType(string $type): void
152  {
153  $this->data['hos_type'] = $type;
154  }
155 
156  public function isActive(): bool
157  {
158  return (bool) ($this->data['active'] ?? false);
159  }
160 
161  public function setActive(bool $status): void
162  {
163  $this->data['active'] = $status ? '1' : '0';
164  }
165 
166  public function isLocalAuthAllowed(): bool
167  {
168  return (bool) ($this->data['auth_allow_local'] ?? false);
169  }
170 
171  public function setAllowLocalAuth(bool $status): void
172  {
173  $this->data['auth_allow_local'] = $status ? '1' : '0';
174  }
175 
176  public function adminMustActivate(): bool
177  {
178  return (bool) ($this->data['activate_new'] ?? false);
179  }
180 
181  public function setAdminMustActivate(bool $status): void
182  {
183  $this->data['activate_new'] = $status ? '1' : '0';
184  }
185 
186  public function getFederationName(): string
187  {
188  return ($this->data['federation_name'] ?? '');
189  }
190 
191  public function setFederationName(string $federation): void
192  {
193  $this->data['federation_name'] = $federation;
194  }
195 }
global $DIC
Definition: feed.php:28
setFederationName(string $federation)
string $key
Consumer key/client ID value.
Definition: System.php:193
setLoginButton(string $login_button)
Class ilShibbolethSettings.