Skip to content

Commit

Permalink
Add parameter to exclude validUntil (#569)
Browse files Browse the repository at this point in the history
Add parameter to exclude validUntil
  • Loading branch information
ckbaker10 authored May 26, 2024
1 parent 92a9e2d commit 4bf537c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/Saml2/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -161,27 +162,37 @@ public static function builder($sp, $authnsign = false, $wsign = false, $validUn

$requestedAttributeStr = implode(PHP_EOL, $requestedAttributeData);
$strAttributeConsumingService = <<<METADATA_TEMPLATE
<md:AttributeConsumingService index="1">
<md:AttributeConsumingService index="1">
<md:ServiceName xml:lang="en">{$sp['attributeConsumingService']['serviceName']}</md:ServiceName>
{$attrCsDesc}{$requestedAttributeStr}
</md:AttributeConsumingService>
METADATA_TEMPLATE;
}

if ($ignoreValidUntil) {
$timeStr = <<<TIME_TEMPLATE
cacheDuration="PT{$cacheDuration}S";
TIME_TEMPLATE;
} else {
$timeStr = <<<TIME_TEMPLATE
validUntil="{$validUntilTime}"
cacheDuration="PT{$cacheDuration}S"
TIME_TEMPLATE;
}

$spEntityId = htmlspecialchars($sp['entityId'], ENT_QUOTES);
$acsUrl = htmlspecialchars($sp['assertionConsumerService']['url'], ENT_QUOTES);
$metadata = <<<METADATA_TEMPLATE
<?xml version="1.0"?>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
validUntil="{$validUntilTime}"
cacheDuration="PT{$cacheDuration}S"
{$timeStr}
entityID="{$spEntityId}">
<md:SPSSODescriptor AuthnRequestsSigned="{$strAuthnsign}" WantAssertionsSigned="{$strWsign}" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
{$sls} <md:NameIDFormat>{$sp['NameIDFormat']}</md:NameIDFormat>
<md:AssertionConsumerService Binding="{$sp['assertionConsumerService']['binding']}"
Location="{$acsUrl}"
index="1" />
{$strAttributeConsumingService}
index="1" />{$strAttributeConsumingService}
</md:SPSSODescriptor>{$strOrganization}{$strContacts}
</md:EntityDescriptor>
METADATA_TEMPLATE;
Expand Down
4 changes: 4 additions & 0 deletions tests/src/OneLogin/Saml2/MetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function testBuilder()
$this->assertStringContainsString('<md:OrganizationName xml:lang="en-US">sp_test</md:OrganizationName>', $metadata);
$this->assertStringContainsString('<md:ContactPerson contactType="technical">', $metadata);
$this->assertStringContainsString('<md:GivenName>technical_name</md:GivenName>', $metadata);
$this->assertStringContainsString('validUntil', $metadata);

$security['authnRequestsSigned'] = true;
$security['wantAssertionsSigned'] = true;
Expand All @@ -66,6 +67,9 @@ public function testBuilder()

$this->assertStringNotContainsString('<md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"', $metadata2);
$this->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);
}

/**
Expand Down

0 comments on commit 4bf537c

Please sign in to comment.