Skip to content

Commit

Permalink
Implement AuthenticationStatement
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Feb 27, 2024
1 parent c2a6838 commit 43ab97a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/SAML11/XML/saml/AbstractAuthenticationStatementType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ abstract class AbstractAuthenticationStatementType extends AbstractSubjectStatem
/**
* Initialize a saml:AuthenticationStatementType from scratch
*
* @param \SimpleSAML\SAML11\XML\saml\Subject $subject
* @param string $authenticationMethod
* @param \DateTimeImmutable $authenticationInstant
* @param \SimpleSAML\SAML11\XML\saml\Subject $subject
* @param \SimpleSAML\SAML11\XML\saml\SubjectLocality|null $subjectLocality
* @param array<\SimpleSAML\SAML11\XML\saml\AuthorityBinding> $authorityBinding
*/
public function __construct(
Subject $subject,
protected string $authenticationMethod,
protected DateTimeImmutable $authenticationInstant,
protected ?SubjectLocality $subjectLocality = null,
Expand Down Expand Up @@ -117,9 +118,9 @@ public static function fromXML(DOMElement $xml): static
Assert::maxCount($subject, 1, TooManyElementsException::class);

return new static(
array_pop($subject),
self::getAttribute($xml, 'AuthenticationMethod'),
$authenticationInstant,
array_pop($subject),
array_pop($subjectLocality),
$authorityBinding,
);
Expand Down
1 change: 1 addition & 0 deletions tests/resources/xml/saml_AuthenticationStatement.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<saml:AuthenticationStatement xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password" AuthenticationInstant="2023-01-24T09:42:26Z">
<saml:Subject>
<saml:NameIdentifier NameQualifier="TheNameQualifier" Format="urn:the:format">TheNameIDValue</saml:NameIdentifier>
<saml:SubjectConfirmation>
<saml:ConfirmationMethod>_Test1</saml:ConfirmationMethod>
<saml:ConfirmationMethod>_Test2</saml:ConfirmationMethod>
Expand Down
14 changes: 8 additions & 6 deletions tests/src/SAML11/XML/saml/AuthenticationStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use SimpleSAML\SAML11\Constants as C;
use SimpleSAML\SAML11\Utils\XPath;
use SimpleSAML\SAML11\XML\saml\AuthenticationStatement;
use SimpleSAML\SAML11\XML\saml\AuthorityBinding;
use SimpleSAML\SAML11\XML\saml\ConfirmationMethod;
Expand All @@ -19,7 +20,6 @@
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
use SimpleSAML\XML\Utils\XPath;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;
use SimpleSAML\XMLSecurity\XML\ds\KeyInfo;
use SimpleSAML\XMLSecurity\XML\ds\KeyName;
Expand Down Expand Up @@ -137,6 +137,7 @@ public function testMarshalling(): void
);

$authenticationStatement = new AuthenticationStatement(
$subject,
C::AC_PASSWORD,
new DateTimeImmutable('2023-01-24T09:42:26Z'),
$subjectLocality,
Expand All @@ -155,11 +156,11 @@ public function testMarshallingElementOrdering(): void
$authenticationStatement = AuthenticationStatement::fromXML(self::$xmlRepresentation->documentElement);
$authenticationStatementElement = $authenticationStatement->toXML();

// Test for a SubjectLocality
// Test for a Subject
$xpCache = XPath::getXPath($authenticationStatementElement);
$authenticationStatementElements = XPath::xpQuery(
$authenticationStatementElement,
'./saml_assertion:SubjectLocality',
'./saml_assertion:Subject',
$xpCache,
);
$this->assertCount(1, $authenticationStatementElements);
Expand All @@ -168,10 +169,11 @@ public function testMarshallingElementOrdering(): void
/** @psalm-var \DOMElement[] $authnStatementElements */
$authenticationStatementElements = XPath::xpQuery(
$authenticationStatementElement,
'./saml_assertion:SubjectLocality/following-sibling::*',
'./saml_assertion:Subject/following-sibling::*',
$xpCache,
);
$this->assertCount(1, $authenticationStatementElements);
$this->assertEquals('saml:AuthorityBinding', $authenticationStatementElements[0]->tagName);
$this->assertCount(2, $authenticationStatementElements);
$this->assertEquals('saml:SubjectLocality', $authenticationStatementElements[0]->tagName);
$this->assertEquals('saml:AuthorityBinding', $authenticationStatementElements[1]->tagName);
}
}

0 comments on commit 43ab97a

Please sign in to comment.