Skip to content

Commit

Permalink
Issue #775: Fully use getOptionalx methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahjcotton committed Oct 6, 2023
1 parent 19a9088 commit 9e3e3c8
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,57 +146,57 @@ function auth_saml2_get_sp_metadata($baseurl = '') {
$metaArray20['NameIDFormat'] = $format;
}

$name = $spconfig->getLocalizedString('name', NULL);
$attributes = $spconfig->getArray('attributes', array());
$name = $spconfig->getOptionalLocalizedString('name', NULL);
$attributes = $spconfig->getOptionalArray('attributes', array());

if ($name !== NULL && !empty($attributes)) {
$metaArray20['name'] = $name;
$metaArray20['attributes'] = $attributes;
$metaArray20['attributes.required'] = $spconfig->getArray('attributes.required', array());
$metaArray20['attributes.required'] = $spconfig->getOptionalArray('attributes.required', array());

if (empty($metaArray20['attributes.required'])) {
unset($metaArray20['attributes.required']);
}

$description = $spconfig->getArray('description', NULL);
$description = $spconfig->getOptionalArray('description', NULL);
if ($description !== NULL) {
$metaArray20['description'] = $description;
}

$nameFormat = $spconfig->getString('attributes.NameFormat', NULL);
$nameFormat = $spconfig->getOptionalString('attributes.NameFormat', NULL);
if ($nameFormat !== NULL) {
$metaArray20['attributes.NameFormat'] = $nameFormat;
}
}

// add organization info
$orgName = $spconfig->getLocalizedString('OrganizationName', NULL);
$orgName = $spconfig->getOptionalLocalizedString('OrganizationName', NULL);
if ($orgName !== NULL) {
$metaArray20['OrganizationName'] = $orgName;

$metaArray20['OrganizationDisplayName'] = $spconfig->getLocalizedString('OrganizationDisplayName', NULL);
$metaArray20['OrganizationDisplayName'] = $spconfig->getOptionalLocalizedString('OrganizationDisplayName', NULL);
if ($metaArray20['OrganizationDisplayName'] === NULL) {
$metaArray20['OrganizationDisplayName'] = $orgName;
}

$metaArray20['OrganizationURL'] = $spconfig->getLocalizedString('OrganizationURL', NULL);
$metaArray20['OrganizationURL'] = $spconfig->getOptionalLocalizedString('OrganizationURL', NULL);
if ($metaArray20['OrganizationURL'] === NULL) {
throw new SimpleSAML_Error_Exception('If OrganizationName is set, OrganizationURL must also be set.');
}
}

if ($spconfig->hasValue('contacts')) {
$contacts = $spconfig->getArray('contacts');
$contacts = $spconfig->getOptionalArray('contacts');
foreach ($contacts as $contact) {
$metaArray20['contacts'][] = \SimpleSAML\Utils\Config\Metadata::getContact($contact);
}
}

// add technical contact
$email = $config->getString('technicalcontact_email', 'na@example.org', FALSE);
$email = $config->getOptionalString('technicalcontact_email', 'na@example.org');
if ($email && $email !== 'na@example.org') {
$techcontact['emailAddress'] = $email;
$techcontact['name'] = $config->getString('technicalcontact_name', NULL);
$techcontact['name'] = $config->getOptionalString('technicalcontact_name', NULL);
$techcontact['contactType'] = 'technical';
$metaArray20['contacts'][] = \SimpleSAML\Utils\Config\Metadata::getContact($techcontact);
}
Expand All @@ -210,27 +210,27 @@ function auth_saml2_get_sp_metadata($baseurl = '') {

// add EntityAttributes extension
if ($spconfig->hasValue('EntityAttributes')) {
$metaArray20['EntityAttributes'] = $spconfig->getArray('EntityAttributes');
$metaArray20['EntityAttributes'] = $spconfig->getOptionalArray('EntityAttributes');
}

// add UIInfo extension
if ($spconfig->hasValue('UIInfo')) {
$metaArray20['UIInfo'] = $spconfig->getArray('UIInfo');
$metaArray20['UIInfo'] = $spconfig->getOptionalArray('UIInfo');
}

// add RegistrationInfo extension
if ($spconfig->hasValue('RegistrationInfo')) {
$metaArray20['RegistrationInfo'] = $spconfig->getArray('RegistrationInfo');
$metaArray20['RegistrationInfo'] = $spconfig->getOptionalArray('RegistrationInfo');
}

// add signature options
if ($spconfig->hasValue('WantAssertionsSigned')) {
$metaArray20['saml20.sign.assertion'] = $spconfig->getBoolean('WantAssertionsSigned');
$metaArray20['saml20.sign.assertion'] = $spconfig->getOptionalBoolean('WantAssertionsSigned');
}
if ($spconfig->hasValue('redirect.sign')) {
$metaArray20['redirect.validate'] = $spconfig->getBoolean('redirect.sign');
$metaArray20['redirect.validate'] = $spconfig->getOptionalBoolean('redirect.sign');
} elseif ($spconfig->hasValue('sign.authnrequest')) {
$metaArray20['validate.authnrequest'] = $spconfig->getBoolean('sign.authnrequest');
$metaArray20['validate.authnrequest'] = $spconfig->getOptionalBoolean('sign.authnrequest');
}

$supported_protocols = array(SAML2\Constants::NS_SAMLP);
Expand Down

0 comments on commit 9e3e3c8

Please sign in to comment.