Skip to content

Commit f4fc38c

Browse files
authored
Type the SecurityTokenService as fed:SecurityTokenServiceType (#52)
* Type the SecurityTokenService as fed:SecurityTokenServiceType * Require xml-ws-federation ^1.3
1 parent d669de1 commit f4fc38c

3 files changed

Lines changed: 84 additions & 5 deletions

File tree

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"simplesamlphp/xml-wsdl": "^2.2",
5151
"simplesamlphp/xml-wss-core": "^1.4",
5252
"simplesamlphp/xml-ws-addressing": "^1.3",
53-
"simplesamlphp/xml-ws-federation": "^1.2",
53+
"simplesamlphp/xml-ws-federation": "^1.3",
5454
"simplesamlphp/xml-ws-policy": "^1.3",
5555
"simplesamlphp/xml-ws-security-policy": "^1.2",
5656
"simplesamlphp/xml-ws-trust": "^1.1",

‎src/IdP/MetadataBuilder.php‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
use SimpleSAML\XMLSchema\Type\Base64BinaryValue;
4747
use SimpleSAML\XMLSchema\Type\BooleanValue;
4848
use SimpleSAML\XMLSchema\Type\IDValue;
49-
use SimpleSAML\XMLSchema\Type\NCNameValue;
5049
use SimpleSAML\XMLSchema\Type\QNameValue;
5150
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
5251
use SimpleSAML\XMLSecurity\Constants as C_XMLSEC;
@@ -219,10 +218,12 @@ public function getSecurityTokenService(): SecurityTokenServiceType
219218
$defaultEndpoint = Module::getModuleURL('adfs') . '/idp/prp.php';
220219

221220
return new SecurityTokenServiceType(
221+
// The first argument is the xsi:type, not the element's own name. getLocalName()/NS/NS_PREFIX
222+
// describe the element this serialises to — md:RoleDescriptor — so they yield the wrong QName.
222223
QNameValue::fromParts(
223-
NCNameValue::fromString(SecurityTokenServiceType::getLocalName()),
224-
AnyURIValue::fromString(SecurityTokenServiceType::NS),
225-
NCNameValue::fromString(SecurityTokenServiceType::NS_PREFIX),
224+
SecurityTokenServiceType::getXsiTypeName(),
225+
SecurityTokenServiceType::getXsiTypeNamespaceURI(),
226+
SecurityTokenServiceType::getXsiTypePrefix(),
226227
),
227228
protocolSupportEnumeration: SAMLAnyURIListValue::fromArray(
228229
[C_TRUST::NS_TRUST_200512, C_TRUST::NS_TRUST_200502, C_FED::NS_FED],
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Test\Module\adfs\IdP;
6+
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\TestCase;
9+
use SimpleSAML\Configuration;
10+
use SimpleSAML\Module\adfs\IdP\MetadataBuilder;
11+
use SimpleSAML\WebServices\Federation\Constants as C_FED;
12+
use SimpleSAML\WebServices\Federation\XML\fed\AbstractSecurityTokenServiceType;
13+
14+
use function dirname;
15+
use function strval;
16+
17+
/**
18+
*/
19+
#[CoversClass(MetadataBuilder::class)]
20+
final class MetadataBuilderTest extends TestCase
21+
{
22+
/** @var \SimpleSAML\Configuration */
23+
protected Configuration $config;
24+
25+
26+
/**
27+
* The setup method that is run before any tests in this class.
28+
*/
29+
protected function setup(): void
30+
{
31+
parent::setUp();
32+
33+
$this->config = Configuration::loadFromArray(
34+
[
35+
'enable.adfs-idp' => true,
36+
'module.enable' => ['adfs' => true],
37+
'metadata.sources' => [
38+
['type' => 'flatfile', 'directory' => dirname(__DIR__, 2) . '/metadata'],
39+
],
40+
],
41+
'[ARRAY]',
42+
'simplesaml',
43+
);
44+
45+
Configuration::setPreLoadedConfig($this->config, 'config.php');
46+
}
47+
48+
49+
/**
50+
* Test that the SecurityTokenService is typed as fed:SecurityTokenServiceType.
51+
*
52+
* The first constructor argument is the element's xsi:type, not its own name. Building it from
53+
* getLocalName()/NS/NS_PREFIX describes the element this serialises to — md:RoleDescriptor —
54+
* and so publishes a role descriptor that claims to be typed as itself.
55+
*/
56+
public function testSecurityTokenServiceCarriesItsXsiType(): void
57+
{
58+
$metadata = Configuration::loadFromArray(
59+
['entityid' => 'urn:example:adfs'],
60+
'adfs-idp-hosted',
61+
);
62+
63+
$xsiType = (new MetadataBuilder($this->config, $metadata))
64+
->getSecurityTokenService()
65+
->getXsiType();
66+
67+
$this->assertEquals('fed:SecurityTokenServiceType', strval($xsiType));
68+
$this->assertEquals(
69+
AbstractSecurityTokenServiceType::XSI_TYPE_NAME,
70+
$xsiType->getLocalName()->getValue(),
71+
);
72+
73+
// The prefix is lexical; what identifies the type is the namespace it resolves to.
74+
$namespaceURI = $xsiType->getNamespaceURI();
75+
$this->assertNotNull($namespaceURI);
76+
$this->assertEquals(C_FED::NS_FED, $namespaceURI->getValue());
77+
}
78+
}

0 commit comments

Comments
 (0)