From d0dab57c6879e8c4f53235b9e1893729a4c8fde7 Mon Sep 17 00:00:00 2001 From: ckbaker10 <56784875+ckbaker10@users.noreply.github.com> Date: Thu, 7 Dec 2023 12:48:29 +0100 Subject: [PATCH 1/3] Add parameter to exclude validUntil --- src/Saml2/Metadata.php | 10 ++++++++-- tests/src/OneLogin/Saml2/MetadataTest.php | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Saml2/Metadata.php b/src/Saml2/Metadata.php index bac761cf..b3dd3e57 100644 --- a/src/Saml2/Metadata.php +++ b/src/Saml2/Metadata.php @@ -38,10 +38,11 @@ class Metadata * @param array $contacts Contacts info * @param array $organization Organization ingo * @param array $attributes + * @param bool $ignoreValidUntil exclude the validUntil tag from metadata * * @return string SAML Metadata XML */ - public static function builder($sp, $authnsign = false, $wsign = false, $validUntil = null, $cacheDuration = null, $contacts = array(), $organization = array(), $attributes = array()) + public static function builder($sp, $authnsign = false, $wsign = false, $validUntil = null, $cacheDuration = null, $contacts = array(), $organization = array(), $attributes = array(), $ignoreValidUntil = false) { if (!isset($validUntil)) { @@ -173,7 +174,12 @@ public static function builder($sp, $authnsign = false, $wsign = false, $validUn $metadata = << diff --git a/tests/src/OneLogin/Saml2/MetadataTest.php b/tests/src/OneLogin/Saml2/MetadataTest.php index 290ff9ff..3849b10f 100644 --- a/tests/src/OneLogin/Saml2/MetadataTest.php +++ b/tests/src/OneLogin/Saml2/MetadataTest.php @@ -52,6 +52,7 @@ public function testBuilder() $this->assertStringContainsString('sp_test', $metadata); $this->assertStringContainsString('', $metadata); $this->assertStringContainsString('technical_name', $metadata); + $this->assertStringContainsString('validUntil', $metadata); $security['authnRequestsSigned'] = true; $security['wantAssertionsSigned'] = true; @@ -66,6 +67,9 @@ public function testBuilder() $this->assertStringNotContainsString('assertStringNotContainsString(' Location="http://stuff.com/endpoints/endpoints/sls.php"/>', $metadata2); + + $metadata3 = Metadata::builder($spData, $security['authnRequestsSigned'], $security['wantAssertionsSigned'], null, null, $contacts, $organization, array(), true); + $this->assertStringNotContainsString('validUntil=', $metadata3); } /** From 112fd0d1b0759e733d21be24222d5ff6cce89c61 Mon Sep 17 00:00:00 2001 From: Sixto Martin Date: Mon, 20 May 2024 01:30:59 +0200 Subject: [PATCH 2/3] Refactor --- src/Saml2/Metadata.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Saml2/Metadata.php b/src/Saml2/Metadata.php index b3dd3e57..19451a6f 100644 --- a/src/Saml2/Metadata.php +++ b/src/Saml2/Metadata.php @@ -162,32 +162,37 @@ public static function builder($sp, $authnsign = false, $wsign = false, $validUn $requestedAttributeStr = implode(PHP_EOL, $requestedAttributeData); $strAttributeConsumingService = << + + {$sp['attributeConsumingService']['serviceName']} {$attrCsDesc}{$requestedAttributeStr} METADATA_TEMPLATE; } + if ($ignoreValidUntil) { + $timeStr = << {$sls} {$sp['NameIDFormat']} - {$strAttributeConsumingService} + index="1" />{$strAttributeConsumingService} {$strOrganization}{$strContacts} METADATA_TEMPLATE; From 1bf1e88b86765171715cc72383a817da8600246d Mon Sep 17 00:00:00 2001 From: Sixto Martin Date: Mon, 20 May 2024 01:36:18 +0200 Subject: [PATCH 3/3] Fix indent --- src/Saml2/Metadata.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Saml2/Metadata.php b/src/Saml2/Metadata.php index 19451a6f..91cb0424 100644 --- a/src/Saml2/Metadata.php +++ b/src/Saml2/Metadata.php @@ -180,7 +180,7 @@ public static function builder($sp, $authnsign = false, $wsign = false, $validUn cacheDuration="PT{$cacheDuration}S" TIME_TEMPLATE; } - + $spEntityId = htmlspecialchars($sp['entityId'], ENT_QUOTES); $acsUrl = htmlspecialchars($sp['assertionConsumerService']['url'], ENT_QUOTES); $metadata = <<