Skip to content
Snippets Groups Projects
Commit 11412ab5 authored by Thijs Kinkhorst's avatar Thijs Kinkhorst
Browse files

Clean up contacts handling, passing of 'name' deprecated since 2014

parent e7e8eceb
No related branches found
No related tags found
No related merge requests found
......@@ -535,7 +535,7 @@ class SAMLBuilder
foreach ($metadata->getArray('contacts', []) as $contact) {
if (array_key_exists('contactType', $contact) && array_key_exists('emailAddress', $contact)) {
$this->addContact($contact['contactType'], Utils\Config\Metadata::getContact($contact));
$this->addContact(Utils\Config\Metadata::getContact($contact));
}
}
}
......@@ -583,7 +583,7 @@ class SAMLBuilder
foreach ($metadata->getArray('contacts', []) as $contact) {
if (array_key_exists('contactType', $contact) && array_key_exists('emailAddress', $contact)) {
$this->addContact($contact['contactType'], Utils\Config\Metadata::getContact($contact));
$this->addContact(Utils\Config\Metadata::getContact($contact));
}
}
}
......@@ -623,23 +623,15 @@ class SAMLBuilder
/**
* Add contact information.
*
* Accepts a contact type, and a contact array that must be previously sanitized.
* Accepts a contact type, and a contact array that must be previously sanitized
* by calling Utils\Config\Metadata::getContact().
*
* WARNING: This function will change its signature and no longer parse a 'name' element.
*
* @param string $type The type of contact. Deprecated.
* @param array $details The details about the contact.
*
* @todo Change the signature to remove $type.
* @todo Remove the capability to pass a name and parse it inside the method.
*/
public function addContact(string $type, array $details): void
public function addContact(array $details): void
{
Assert::oneOf($type, ['technical', 'support', 'administrative', 'billing', 'other']);
// TODO: remove this check as soon as getContact() is called always before calling this function
$details = Utils\Config\Metadata::getContact($details);
$e = new \SAML2\XML\md\ContactPerson();
$e->setContactType($type);
......
......@@ -72,7 +72,6 @@ class Metadata
* - contactType The type of the contact (as string). Mandatory.
* - emailAddress Email address (as string), or array of email addresses. Optional.
* - telephoneNumber Telephone number of contact (as string), or array of telephone numbers. Optional.
* - name Full name of contact, either as <GivenName> <SurName>, or as <SurName>, <GivenName>. Optional.
* - surName Surname of contact (as string). Optional.
* - givenName Given name of contact (as string). Optional.
* - company Company name of contact (as string). Optional.
......@@ -84,22 +83,11 @@ class Metadata
* - billing
* - other
*
* If given a "name" it will try to decompose it into its given name and surname, only if neither givenName nor
* surName are present. It works as follows:
* - "surname1 surname2, given_name1 given_name2"
* givenName: "given_name1 given_name2"
* surname: "surname1 surname2"
* - "given_name surname"
* givenName: "given_name"
* surname: "surname"
*
* otherwise it will just return the name as "givenName" in the resulting array.
*
* @param array|null $contact The contact to parse and sanitize.
*
* @return array An array holding valid contact configuration options. If a key 'name' was part of the input array,
* it will try to decompose the name into its parts, and place the parts into givenName and surName, if those are
* missing.
* @return array An array holding valid contact configuration options.
* @throws \InvalidArgumentException If $contact is neither an array nor null, or the contact does not conform to
* valid configuration rules for contacts.
*/
......@@ -131,26 +119,6 @@ class Metadata
}
}
// try to fill in givenName and surName from name
if (isset($contact['name']) && !isset($contact['givenName']) && !isset($contact['surName'])) {
// first check if it's comma separated
$names = explode(',', $contact['name'], 2);
if (count($names) === 2) {
$contact['surName'] = preg_replace('/\s+/', ' ', trim($names[0]));
$contact['givenName'] = preg_replace('/\s+/', ' ', trim($names[1]));
} else {
// check if it's in "given name surname" format
$names = explode(' ', preg_replace('/\s+/', ' ', trim($contact['name'])));
if (count($names) === 2) {
$contact['givenName'] = preg_replace('/\s+/', ' ', trim($names[0]));
$contact['surName'] = preg_replace('/\s+/', ' ', trim($names[1]));
} else {
// nothing works, return it as given name
$contact['givenName'] = preg_replace('/\s+/', ' ', trim($contact['name']));
}
}
}
// check givenName
if (
isset($contact['givenName'])
......
......@@ -255,7 +255,7 @@ class Federation
$builder->addOrganizationInfo($entity['metadata_array']);
if (isset($entity['metadata_array']['contacts'])) {
foreach ($entity['metadata_array']['contacts'] as $contact) {
$builder->addContact($contact['contactType'], $contact);
$builder->addContact(Utils\Config\Metadata::getContact($contact));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment