From 11412ab540dc9aa1d54e6c8334dc3f08014cc46e Mon Sep 17 00:00:00 2001 From: Thijs Kinkhorst <thijs@kinkhorst.com> Date: Wed, 5 Jan 2022 13:06:47 +0000 Subject: [PATCH] Clean up contacts handling, passing of 'name' deprecated since 2014 --- lib/SimpleSAML/Metadata/SAMLBuilder.php | 18 +++-------- lib/SimpleSAML/Utils/Config/Metadata.php | 34 +-------------------- modules/admin/lib/Controller/Federation.php | 2 +- 3 files changed, 7 insertions(+), 47 deletions(-) diff --git a/lib/SimpleSAML/Metadata/SAMLBuilder.php b/lib/SimpleSAML/Metadata/SAMLBuilder.php index b14a26f30..5376fee24 100644 --- a/lib/SimpleSAML/Metadata/SAMLBuilder.php +++ b/lib/SimpleSAML/Metadata/SAMLBuilder.php @@ -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); diff --git a/lib/SimpleSAML/Utils/Config/Metadata.php b/lib/SimpleSAML/Utils/Config/Metadata.php index 938eacf1e..25e5f171d 100644 --- a/lib/SimpleSAML/Utils/Config/Metadata.php +++ b/lib/SimpleSAML/Utils/Config/Metadata.php @@ -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']) diff --git a/modules/admin/lib/Controller/Federation.php b/modules/admin/lib/Controller/Federation.php index ffb6568bb..81bb898ac 100644 --- a/modules/admin/lib/Controller/Federation.php +++ b/modules/admin/lib/Controller/Federation.php @@ -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)); } } -- GitLab