Debian Codegraph @

lib/modules/eduPerson.inc

raw
1 <?php
2 /*
3
4 This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
5 Copyright (C) 2009 - 2026 Roland Gruber
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 /**
23 * Manages the eduPerson extension for user accounts.
24 *
25 * @package modules
26 * @author Roland Gruber
27 */
28
29 use LAM\TYPES\ConfiguredType;
30
31 /**
32 * Manages the eduPerson extension for user accounts.
33 *
34 * @package modules
35 */
36 class eduPerson extends baseModule {
37
38 /**
39 * These attributes will be ignored by default if a new account is copied from an existing one.
40 */
41 private const ATTRIBUTES_TO_IGNORE_ON_COPY = ['eduPersonNickname', 'eduPersonPrincipalName'];
42
43 /** @var string[] $affiliationTypes possible affiliation types */
44 private array $affiliationTypes = ['faculty', 'student', 'staff', 'alum',
45 'member', 'affiliate', 'employee', 'library-walk-in'];
46
47 /**
48 * Creates a new eduPerson object.
49 *
50 * @param string $scope account type (user, group, host)
51 */
52 public function __construct($scope) {
53 parent::__construct($scope);
54 $this->autoAddObjectClasses = false;
55 }
56
57 /**
58 * {@inheritDoc}
59 */
60 public function can_manage(): bool {
61 return $this->get_scope() === 'user';
62 }
63
64 /**
65 * {@inheritDoc}
66 */
67 public function get_metaData(): array {
68 $return = [];
69 // icon
70 $return['icon'] = 'eduPerson.png';
71 // alias name
72 $return["alias"] = _("EDU person");
73 // module dependencies
74 $return['dependencies'] = ['depends' => [], 'conflicts' => []];
75 // managed object classes
76 $return['objectClasses'] = ['eduPerson'];
77 // managed attributes
78 $return['attributes'] = ['eduPersonAffiliation', 'eduPersonNickname',
79 'eduPersonOrgDN', 'eduPersonOrgUnitDN',
80 'eduPersonPrimaryAffiliation', 'eduPersonPrincipalName',
81 'eduPersonEntitlement', 'eduPersonPrimaryOrgUnitDN',
82 'eduPersonScopedAffiliation', 'eduPersonAssurance'];
83 // RDN attribute
84 $return["RDN"] = ['eduPersonPrincipalName' => 'low'];
85 // help Entries
86 $return['help'] = [
87 'primaryAffiliation' => [
88 "Headline" => _("Primary affiliation"), 'attr' => 'eduPersonPrimaryAffiliation',
89 "Text" => _("Specifies the person's primary relationship to the institution in broad categories such as student, faculty, staff, alum, etc.")
90 ],
91 'scopedAffiliation' => [
92 "Headline" => _("Scoped affiliations"), 'attr' => 'eduPersonScopedAffiliation',
93 "Text" => _("Specifies the person's affiliation within a particular security domain in broad categories such as student, faculty, staff, alum, etc.")
94 ],
95 'scopedAffiliationUpload' => [
96 "Headline" => _("Scoped affiliations"), 'attr' => 'eduPersonScopedAffiliation',
97 "Text" => _("Specifies the person's affiliation within a particular security domain in broad categories such as student, faculty, staff, alum, etc.") . " " .
98 _('Multiple values are separated by comma.')
99 ],
100 'eduPersonNickname' => [
101 "Headline" => _("Nick names"), 'attr' => 'eduPersonNickname',
102 "Text" => _("This is a list of nick names for this user.")
103 ],
104 'affiliation' => [
105 "Headline" => _("Affiliations"), 'attr' => 'eduPersonAffiliation',
106 "Text" => _("Specifies the person's relationships to the institution in broad categories such as student, faculty, staff, alum, etc.")
107 ],
108 'affiliationUpload' => [
109 "Headline" => _("Affiliations"), 'attr' => 'eduPersonAffiliation',
110 "Text" => _("Specifies the person's relationships to the institution in broad categories such as student, faculty, staff, alum, etc.") . " " .
111 _('Multiple values are separated by comma.')
112 ],
113 'eduPersonPrincipalName' => [
114 "Headline" => _("Principal name"), 'attr' => 'eduPersonPrincipalName',
115 "Text" => _("The \"NetID\" of the person for the purposes of inter-institutional authentication. It should be represented in the form \"user@scope\" where scope defines a local security domain.")
116 ],
117 'eduPersonEntitlement' => [
118 "Headline" => _("Entitlements"), 'attr' => 'eduPersonEntitlement',
119 "Text" => _("URI (either URN or URL) that indicates a set of rights to specific resources.")
120 ],
121 'entitlementUpload' => [
122 "Headline" => _("Entitlements"), 'attr' => 'eduPersonEntitlement',
123 "Text" => _("URI (either URN or URL) that indicates a set of rights to specific resources.") . " " . _('Multiple values are separated by comma.')
124 ],
125 'eduPersonOrgDN' => [
126 "Headline" => _("Organisation"), 'attr' => 'eduPersonOrgDN',
127 "Text" => _("The DN of the directory entry representing the institution with which the person is associated.")
128 ],
129 'eduPersonPrimaryOrgUnitDN' => [
130 "Headline" => _("Primary organisational unit"), 'attr' => 'eduPersonPrimaryOrgUnitDN',
131 "Text" => _("The DN of the directory entry representing the person's primary organisational unit.")
132 ],
133 'eduPersonOrgUnitDN' => [
134 "Headline" => _("Organisational units"), 'attr' => 'eduPersonOrgUnitDN',
135 "Text" => _("The DNs of the directory entries representing the person's organisational units.")
136 ],
137 'orgUnitDNUpload' => [
138 "Headline" => _("Organisational units"), 'attr' => 'eduPersonOrgUnitDN',
139 "Text" => _("The DNs of the directory entries representing the person's organisational units.") . ' ' . _('Multiple values are separated by comma.')
140 ],
141 'eduPersonAssurance' => [
142 "Headline" => _('Assurance profiles'), 'attr' => 'eduPersonAssurance',
143 "Text" => _('Assurance profiles are the set of standards that are met by an identity assertion.')
144 ],
145 'eduPersonAssuranceUpload' => [
146 "Headline" => _('Assurance profiles'), 'attr' => 'eduPersonAssurance',
147 "Text" => _('Assurance profiles are the set of standards that are met by an identity assertion.') . " " . _('Multiple values are separated by comma.')
148 ],
149 'autoAdd' => [
150 "Headline" => _("Automatically add this extension"),
151 "Text" => _("This will enable the extension automatically if this profile is loaded.")
152 ]];
153 // profile options
154 $profileContainer = new htmlResponsiveRow();
155 $profileContainer->add(new htmlResponsiveInputCheckbox('eduPerson_addExt', false, _('Automatically add this extension'), 'autoAdd'));
156 $return['profile_options'] = $profileContainer;
157 // upload fields
158 $return['upload_columns'] = [
159 [
160 'name' => 'eduPerson_principalName',
161 'description' => _('Principal name'),
162 'help' => 'eduPersonPrincipalName',
163 'example' => _('[email protected]'),
164 'unique' => true
165 ],
166 [
167 'name' => 'eduPerson_primaryAffiliation',
168 'description' => _('Primary affiliation'),
169 'help' => 'primaryAffiliation',
170 'example' => 'student',
171 'values' => implode(", ", $this->affiliationTypes)
172 ],
173 [
174 'name' => 'eduPerson_scopedAffiliation',
175 'description' => _('Scoped affiliations'),
176 'help' => 'scopedAffiliationUpload',
177 'example' => 'student@domain, student@domain2'
178 ],
179 [
180 'name' => 'eduPerson_affiliation',
181 'description' => _('Affiliations'),
182 'help' => 'affiliationUpload',
183 'example' => 'student, employee',
184 'values' => implode(", ", $this->affiliationTypes)
185 ],
186 [
187 'name' => 'eduPerson_nickname',
188 'description' => _('Nick names'),
189 'help' => 'eduPersonNickname',
190 'example' => _('Steve, Stevo')
191 ],
192 [
193 'name' => 'eduPerson_entitlement',
194 'description' => _('Entitlements'),
195 'help' => 'entitlementUpload',
196 'example' => 'https://wiki.refeds.org/display/STAN/eduPerson+2020-01#eduPerson202001-eduPersonEntitlement'
197 ],
198 [
199 'name' => 'eduPerson_orgDN',
200 'description' => _('Organisation'),
201 'help' => 'eduPersonOrgDN',
202 'example' => _('ou=accounts,dc=yourdomain,dc=org')
203 ],
204 [
205 'name' => 'eduPerson_primaryOrgUnitDN',
206 'description' => _('Primary organisational unit'),
207 'help' => 'eduPersonPrimaryOrgUnitDN',
208 'example' => _('ou=accounts,dc=yourdomain,dc=org')
209 ],
210 [
211 'name' => 'eduPerson_orgUnitDN',
212 'description' => _('Organisational units'),
213 'help' => 'orgUnitDNUpload',
214 'example' => _('ou=accounts,dc=yourdomain,dc=org')
215 ],
216 [
217 'name' => 'eduPerson_assurance',
218 'description' => _('Assurance profiles'),
219 'help' => 'eduPersonAssuranceUpload',
220 'example' => 'urn:mace:incommon:IAQ:sample, https://idm.example.org/LOA#sample'
221 ],
222 ];
223 // available PDF fields
224 $return['PDF_fields'] = [
225 'affiliation' => _('Affiliations'),
226 'nickname' => _('Nick names'),
227 'orgDN' => _('Organisation'),
228 'orgUnitDN' => _('Organisational units'),
229 'primaryAffiliation' => _('Primary affiliation'),
230 'principalName' => _('Principal name'),
231 'entitlement' => _('Entitlements'),
232 'primaryOrgUnitDN' => _('Primary organisational unit'),
233 'scopedAffiliation' => _('Scoped affiliations'),
234 'eduPersonAssurance' => _('Assurance profiles'),
235 ];
236 return $return;
237 }
238
239 /**
240 * {@inheritDoc}
241 */
242 protected function load_Messages(): void {
243 $this->messages['eduPersonPrincipalName'][0] = ['ERROR', _('Principal name is invalid!')];
244 $this->messages['eduPersonPrincipalName'][1] = ['ERROR', _('Account %s:') . ' eduPerson_principalName', _('Principal name is invalid!')];
245 $this->messages['eduPersonOrgDN'][0] = ['ERROR', _('Please enter a valid DN in the field:') . ' ' . _("Organisation")];
246 $this->messages['eduPersonOrgDN'][1] = ['ERROR', _('Account %s:') . ' eduPerson_orgDN', _('This is not a valid DN!')];
247 $this->messages['eduPersonPrimaryOrgUnitDN'][0] = ['ERROR', _('Please enter a valid DN in the field:') . ' ' . _("Primary organisational unit")];
248 $this->messages['eduPersonPrimaryOrgUnitDN'][1] = ['ERROR', _('Account %s:') . ' eduPerson_primaryOrgUnitDN', _('This is not a valid DN!')];
249 $this->messages['eduPersonOrgUnitDN'][0] = ['ERROR', _('Organisational units contains an invalid entry.')];
250 $this->messages['eduPersonOrgUnitDN'][1] = ['ERROR', _('Account %s:') . ' eduPerson_orgUnitDN', _('This is not a valid list of DNs!')];
251 $this->messages['primaryAffiliation'][0] = ['ERROR', _('Account %s:') . ' eduPerson_primaryAffiliation', _('Please enter a valid primary affiliation.')];
252 $this->messages['scopedAffiliation'][0] = ['ERROR', _('Account %s:') . ' eduPerson_scopedAffiliation', _('Please enter a valid scoped affiliation.')];
253 $this->messages['affiliation'][0] = ['ERROR', _('Account %s:') . ' eduPerson_affiliation', _('Please enter a valid list of affiliations.')];
254 }
255
256 /**
257 * {@inheritDoc}
258 */
259 public function loadAttributesFromAccountCopy(array $ldapAttributes, array $attributesToIgnore = []): void {
260 parent::loadAttributesFromAccountCopy($ldapAttributes, array_merge(baseModule::ATTRIBUTES_TO_IGNORE_ON_COPY_DEFAULT, self::ATTRIBUTES_TO_IGNORE_ON_COPY));
261 }
262
263 /**
264 * {@inheritDoc}
265 */
266 public function module_complete(): bool {
267 return ($this->getAccountContainer()->rdn !== 'eduPersonPrincipalName') || isset($this->attributes['eduPersonPrincipalName'][0]);
268 }
269
270 /**
271 * {@inheritDoc}
272 */
273 public function display_html_attributes(): htmlElement|array {
274 $return = new htmlResponsiveRow();
275 if (in_array('eduPerson', $this->attributes['objectClass'])) {
276 // principal name
277 $this->addSimpleInputTextField($return, 'eduPersonPrincipalName', _('Principal name'));
278 // primary affiliation
279 $primaryAffiliation = [];
280 if (isset($this->attributes['eduPersonPrimaryAffiliation'][0])) {
281 $primaryAffiliation = [$this->attributes['eduPersonPrimaryAffiliation'][0]];
282 }
283 $return->add(new htmlResponsiveSelect('primaryAffiliation', $this->affiliationTypes, $primaryAffiliation, _('Primary affiliation'), 'primaryAffiliation'));
284 // scoped affiliations
285 $scopedAffiliationLabel = new htmlOutputText(_('Scoped affiliations'));
286 $scopedAffiliationLabel->alignment = htmlElement::ALIGN_TOP;
287 $return->addLabel($scopedAffiliationLabel);
288 $scopedAffiliations = new htmlTable();
289 if (isset($this->attributes['eduPersonScopedAffiliation'][0])) {
290 for ($i = 0; $i < count($this->attributes['eduPersonScopedAffiliation']); $i++) {
291 $parts = explode('@', $this->attributes['eduPersonScopedAffiliation'][$i]);
292 $scopedAffiliationPrefix = [$parts[0]];
293 $scopedAffiliation = substr($this->attributes['eduPersonScopedAffiliation'][$i], strlen($parts[0]) + 1);
294 $scopedAffiliationContainer = new htmlTable();
295 $scopedAffiliationContainer->addElement(new htmlSelect('scopedAffiliationPrefix' . $i, $this->affiliationTypes, $scopedAffiliationPrefix));
296 $scopedAffiliationContainer->addElement(new htmlOutputText('@'));
297 $scopedAffiliationContainer->addElement(new htmlInputField('scopedAffiliation' . $i, $scopedAffiliation));
298 $scopedAffiliationContainer->addElement(new htmlButton('deleduPersonScopedAffiliation' . $i, 'del.svg', true));
299 if ($i === count($this->attributes['eduPersonScopedAffiliation']) - 1) {
300 $scopedAffiliationContainer->addElement(new htmlButton('addeduPersonScopedAffiliation', 'add.svg', true));
301 }
302 $scopedAffiliations->addElement($scopedAffiliationContainer, true);
303 }
304 }
305 else {
306 $scopedAffiliationContainer = new htmlGroup();
307 $scopedAffiliationContainer->addElement(new htmlOutputText('-'));
308 $scopedAffiliationContainer->addElement(new htmlSpacer('10px', null));
309 $scopedAffiliationContainer->addElement(new htmlButton('addeduPersonScopedAffiliation', 'add.svg', true));
310 $scopedAffiliationContainer->addElement(new htmlHelpLink('scopedAffiliation'));
311 $scopedAffiliations->addElement($scopedAffiliationContainer);
312 }
313 $return->addField($scopedAffiliations);
314 // affiliations
315 $affiliations = new htmlTable();
316 if (isset($this->attributes['eduPersonAffiliation'][0])) {
317 for ($i = 0; $i < count($this->attributes['eduPersonAffiliation']); $i++) {
318 $affiliations->addElement(new htmlSelect('affiliation' . $i, $this->affiliationTypes, [$this->attributes['eduPersonAffiliation'][$i]]));
319 $affiliationButton = new htmlButton('delAffiliation' . $i, 'del.svg', true);
320 $affiliations->addElement($affiliationButton);
321 if ($i === 0) {
322 $affiliations->addElement(new htmlHelpLink('affiliation'));
323 }
324 $affiliations->addNewLine();
325 }
326 }
327 else {
328 $affiliations->addElement(new htmlOutputText('-'));
329 $affiliations->addElement(new htmlHelpLink('affiliation'), true);
330 }
331 $affiliations->addElement(new htmlSelect('affiliation', $this->affiliationTypes));
332 $affiliations->addElement(new htmlButton('newAffiliation', 'add.svg', true));
333 $affiliationLabel = new htmlOutputText(_('Affiliations'));
334 $affiliationLabel->alignment = htmlElement::ALIGN_TOP;
335 $return->addLabel($affiliationLabel);
336 $return->addField($affiliations);
337 $return->addVerticalSpacer('0.5rem');
338 // nick names
339 $this->addMultiValueInputTextField($return, 'eduPersonNickname', _('Nick names'));
340 // entitlements
341 $this->addMultiValueInputTextField($return, 'eduPersonEntitlement', _('Entitlements'));
342 // org DN
343 $this->addSimpleInputTextField($return, 'eduPersonOrgDN', _('Organisation'));
344 // primary OU DN
345 $this->addSimpleInputTextField($return, 'eduPersonPrimaryOrgUnitDN', _('Primary organisational unit'));
346 // OUs
347 $this->addMultiValueInputTextField($return, 'eduPersonOrgUnitDN', _('Organisational units'));
348 // assurance profiles
349 $this->addMultiValueInputTextField($return, 'eduPersonAssurance', _('Assurance profiles'));
350 // remove button
351 $return->addVerticalSpacer('2rem');
352 $remButton = new htmlButton('remObjectClass', _('Remove EDU person extension'));
353 $remButton->setCSSClasses(['lam-danger']);
354 $return->add($remButton, 12, 12, 12, 'text-center');
355 }
356 else {
357 $return->add(new htmlButton('addObjectClass', _('Add EDU person extension')));
358 }
359 return $return;
360 }
361
362 /**
363 * {@inheritDoc}
364 */
365 public function process_attributes(): array {
366 if (isset($_POST['addObjectClass'])) {
367 $this->attributes['objectClass'][] = 'eduPerson';
368 return [];
369 }
370 elseif (isset($_POST['remObjectClass'])) {
371 $this->attributes['objectClass'] = array_delete(['eduPerson'], $this->attributes['objectClass']);
372 for ($i = 0; $i < count($this->meta['attributes']); $i++) {
373 if (isset($this->attributes[$this->meta['attributes'][$i]])) {
374 unset($this->attributes[$this->meta['attributes'][$i]]);
375 }
376 }
377 return [];
378 }
379 if (!in_array('eduPerson', $this->attributes['objectClass'])) {
380 return [];
381 }
382 $errors = [];
383 // primary affiliation
384 $this->attributes['eduPersonPrimaryAffiliation'][0] = $_POST['primaryAffiliation'];
385 // scoped affiliations
386 $scopedAffiliationCounter = 0;
387 while (isset($_POST['scopedAffiliation' . $scopedAffiliationCounter])) {
388 $this->attributes['eduPersonScopedAffiliation'][$scopedAffiliationCounter] = $_POST['scopedAffiliationPrefix' . $scopedAffiliationCounter] . '@' . $_POST['scopedAffiliation' . $scopedAffiliationCounter];
389 if (($_POST['scopedAffiliation' . $scopedAffiliationCounter] == '') || isset($_POST['deleduPersonScopedAffiliation' . $scopedAffiliationCounter])) {
390 unset($this->attributes['eduPersonScopedAffiliation'][$scopedAffiliationCounter]);
391 }
392 $scopedAffiliationCounter++;
393 }
394 if (isset($_POST['addeduPersonScopedAffiliation'])) {
395 $this->attributes['eduPersonScopedAffiliation'][] = '';
396 }
397 if (!empty($this->attributes['eduPersonScopedAffiliation'])) {
398 $this->attributes['eduPersonScopedAffiliation'] = array_values(array_unique($this->attributes['eduPersonScopedAffiliation']));
399 }
400 // principal name
401 $this->attributes['eduPersonPrincipalName'][0] = $_POST['eduPersonPrincipalName'];
402 if (($_POST['eduPersonPrincipalName'] != '') && !preg_match('/^[0-9a-z_\\.@-]+$/i', $_POST['eduPersonPrincipalName'])) {
403 $errors[] = $this->messages['eduPersonPrincipalName'][0];
404 }
405 // affiliations
406 $this->attributes['eduPersonAffiliation'] = [];
407 $i = 0;
408 while (isset($_POST['affiliation' . $i])) {
409 if (!isset($_POST['delAffiliation' . $i]) && ($_POST['affiliation' . $i] != '')) {
410 $this->attributes['eduPersonAffiliation'][] = $_POST['affiliation' . $i];
411 }
412 $i++;
413 }
414 if (isset($_POST['newAffiliation']) && ($_POST['affiliation'] != '')) {
415 $this->attributes['eduPersonAffiliation'][] = $_POST['affiliation'];
416 }
417 $this->attributes['eduPersonAffiliation'] = array_unique($this->attributes['eduPersonAffiliation']);
418 // nick names
419 $this->processMultiValueInputTextField('eduPersonNickname', $errors);
420 // entitlements
421 $this->processMultiValueInputTextField('eduPersonEntitlement', $errors);
422 // org DN
423 $this->attributes['eduPersonOrgDN'][0] = $_POST['eduPersonOrgDN'];
424 if (($_POST['eduPersonOrgDN'] != '') && !get_preg($_POST['eduPersonOrgDN'], 'dn')) {
425 $errors[] = $this->messages['eduPersonOrgDN'][0];
426 }
427 // primary OU
428 $this->attributes['eduPersonPrimaryOrgUnitDN'][0] = $_POST['eduPersonPrimaryOrgUnitDN'];
429 if (($_POST['eduPersonPrimaryOrgUnitDN'] != '') && !get_preg($_POST['eduPersonPrimaryOrgUnitDN'], 'dn')) {
430 $errors[] = $this->messages['eduPersonPrimaryOrgUnitDN'][0];
431 }
432 // OUs
433 $this->processMultiValueInputTextField('eduPersonOrgUnitDN', $errors, 'dn');
434 // assurance profiles
435 $this->processMultiValueInputTextField('eduPersonAssurance', $errors);
436 return $errors;
437 }
438
439 /**
440 * {@inheritDoc}
441 */
442 public function load_profile(array $profile): void {
443 parent::load_profile($profile);
444 // add extension
445 if (isset($profile['eduPerson_addExt'][0])
446 && ($profile['eduPerson_addExt'][0] == "true")
447 && !in_array('eduPerson', $this->attributes['objectClass'])) {
448 $this->attributes['objectClass'][] = 'eduPerson';
449 }
450 }
451
452 /**
453 * {@inheritDoc}
454 */
455 public function build_uploadAccounts(array $rawAccounts, array $ids, array &$partialAccounts, array $selectedModules, ConfiguredType &$type): array {
456 $messages = [];
457 for ($i = 0; $i < count($rawAccounts); $i++) {
458 // add object class
459 if (!in_array("eduPerson", $partialAccounts[$i]['objectClass'])) {
460 $partialAccounts[$i]['objectClass'][] = "eduPerson";
461 }
462 // principal name
463 if ($rawAccounts[$i][$ids['eduPerson_principalName']] != "") {
464 if (!preg_match('/^[0-9a-z_\\.@-]+$/i', $rawAccounts[$i][$ids['eduPerson_principalName']])) {
465 $error = $this->messages['eduPersonPrincipalName'][1];
466 $error[] = $i;
467 $messages[] = $error;
468 }
469 else {
470 $partialAccounts[$i]['eduPersonPrincipalName'] = $rawAccounts[$i][$ids['eduPerson_principalName']];
471 }
472 }
473 // primary affiliation
474 if ($rawAccounts[$i][$ids['eduPerson_primaryAffiliation']] != "") {
475 if (!in_array($rawAccounts[$i][$ids['eduPerson_primaryAffiliation']], $this->affiliationTypes)) {
476 $error = $this->messages['primaryAffiliation'][0];
477 $error[] = $i;
478 $messages[] = $error;
479 }
480 else {
481 $partialAccounts[$i]['eduPersonPrimaryAffiliation'] = $rawAccounts[$i][$ids['eduPerson_primaryAffiliation']];
482 }
483 }
484 // scoped affiliations
485 if ($rawAccounts[$i][$ids['eduPerson_scopedAffiliation']] != "") {
486 $parts = explode(', ', $rawAccounts[$i][$ids['eduPerson_scopedAffiliation']]);
487 for ($a = 0; $a < count($parts); $a++) {
488 $subparts = explode('@', $parts[$a]);
489 if (!in_array($subparts[0], $this->affiliationTypes)) {
490 $error = $this->messages['scopedAffiliation'][0];
491 $error[] = $i;
492 $messages[] = $error;
493 }
494 else {
495 $partialAccounts[$i]['eduPersonScopedAffiliation'] = $parts;
496 }
497 }
498 }
499 // affiliations
500 if ($rawAccounts[$i][$ids['eduPerson_affiliation']] != "") {
501 $parts = explode(', ', $rawAccounts[$i][$ids['eduPerson_affiliation']]);
502 $valid = true;
503 for ($a = 0; $a < count($parts); $a++) {
504 if (!in_array($parts[$a], $this->affiliationTypes)) {
505 $valid = false;
506 $error = $this->messages['affiliation'][0];
507 $error[] = $i;
508 $messages[] = $error;
509 break;
510 }
511 }
512 if ($valid) {
513 $partialAccounts[$i]['eduPersonAffiliation'] = $parts;
514 }
515 }
516 // nick names
517 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'eduPerson_nickname', 'eduPersonNickname', null, [], $messages, '/,[ ]*/');
518 // entitlements
519 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'eduPerson_entitlement', 'eduPersonEntitlement', null, [], $messages, '/,[ ]*/');
520 // organisation
521 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'eduPerson_orgDN', 'eduPersonOrgDN',
522 'dn', $this->messages['eduPersonOrgDN'][1], $messages);
523 // primary OU
524 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'eduPerson_primaryOrgUnitDN', 'eduPersonPrimaryOrgUnitDN',
525 'dn', $this->messages['eduPersonPrimaryOrgUnitDN'][1], $messages);
526 // OUs
527 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'eduPerson_orgUnitDN', 'eduPersonOrgUnitDN', 'dn', $this->messages['eduPersonOrgUnitDN'][1], $messages, '/;[ ]*/');
528 // assurance profiles
529 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'eduPerson_assurance', 'eduPersonAssurance', null, [], $messages, '/,[ ]*/');
530 }
531 return $messages;
532 }
533
534 /**
535 * {@inheritDoc}
536 */
537 public function get_pdfEntries(array $pdfKeys, string $typeId): array {
538 $return = [];
539 $this->addSimplePDFField($return, 'primaryAffiliation', _('Primary affiliation'), 'eduPersonPrimaryAffiliation');
540 $this->addSimplePDFField($return, 'scopedAffiliation', _('Scoped affiliations'), 'eduPersonScopedAffiliation');
541 $this->addSimplePDFField($return, 'principalName', _('Principal name'), 'eduPersonPrincipalName');
542 $this->addSimplePDFField($return, 'nickname', _('Nick names'), 'eduPersonNickname');
543 $this->addSimplePDFField($return, 'affiliation', _('Affiliations'), 'eduPersonAffiliation');
544 $this->addSimplePDFField($return, 'entitlement', _('Entitlements'), 'eduPersonEntitlement');
545 $this->addSimplePDFField($return, 'orgDN', _('Organisation'), 'eduPersonOrgDN');
546 $this->addSimplePDFField($return, 'primaryOrgUnitDN', _('Primary organisational unit'), 'eduPersonPrimaryOrgUnitDN');
547 $this->addSimplePDFField($return, 'orgUnitDN', _('Organisational units'), 'eduPersonOrgUnitDN');
548 $this->addSimplePDFField($return, 'eduPersonAssurance', _('Assurance profiles'), 'eduPersonAssurance');
549 return $return;
550 }
551
552 /**
553 * @inheritDoc
554 */
555 public function getListAttributeDescriptions(ConfiguredType $type): array {
556 return [
557 'edupersonaffiliation' => _('Affiliations'),
558 'edupersonnickname' => _('Nick names'),
559 'edupersonorgdn' => _('Organisation'),
560 'edupersonorgunitdn' => _('Organisational units'),
561 'edupersonprimaryaffiliation' => _('Primary affiliation'),
562 'edupersonprincipalname' => _('Principal name'),
563 'edupersonentitlement' => _('Entitlements'),
564 'edupersonprimaryorgunitdn' => _('Primary organisational unit'),
565 'edupersonscopedaffiliation' => _('Scoped affiliations'),
566 'edupersonassurance' => _('Assurance profiles'),
567 ];
568 }
569
570 }