Skip to content

Commit 761b4e7

Browse files
committed
AttributeConsumingService support with multi attributeValue
1 parent cd7ced0 commit 761b4e7

File tree

4 files changed

+114
-4
lines changed

4 files changed

+114
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ $settings = array (
297297
"isRequired" => false,
298298
"nameFormat" => "",
299299
"friendlyName" => "",
300-
"attributeValue" => ""
300+
"attributeValue" => array()
301301
)
302302
)
303303
),

lib/Saml2/Metadata.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,23 @@ public static function builder($sp, $authnsign = false, $wsign = false, $validUn
121121
if (isset($attribute['isRequired'])) {
122122
$requestedAttributeStr .= sprintf(' isRequired="%s"', $attribute['isRequired'] === true ? 'true' : 'false');
123123
}
124-
$requestedAttributeData[] = $requestedAttributeStr . '/>';
124+
$reqAttrAuxStr = " />";
125+
126+
if (isset($attribute['attributeValue']) && !empty($attribute['attributeValue'])) {
127+
$reqAttrAuxStr = '>';
128+
if (is_string($attribute['attributeValue'])) {
129+
$attribute['attributeValue'] = array($attribute['attributeValue']);
130+
}
131+
foreach($attribute['attributeValue'] as $attrValue) {
132+
$reqAttrAuxStr .=<<<ATTRIBUTEVALUE
133+
134+
<saml:AttributeValue xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">{$attrValue}</saml:AttributeValue>
135+
ATTRIBUTEVALUE;
136+
}
137+
$reqAttrAuxStr .= "\n </md:RequestedAttribute>";
138+
}
139+
140+
$requestedAttributeData[] = $requestedAttributeStr . $reqAttrAuxStr;
125141
}
126142

127143
$requestedAttributeStr = implode(PHP_EOL, $requestedAttributeData);

tests/settings/settings4.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
$settingsInfo = array (
3+
'strict' => false,
4+
'debug' => false,
5+
'sp' => array (
6+
'entityId' => 'http://stuff.com/endpoints/metadata.php',
7+
'assertionConsumerService' => array (
8+
'url' => 'http://stuff.com/endpoints/endpoints/acs.php',
9+
),
10+
'singleLogoutService' => array (
11+
'url' => 'http://stuff.com/endpoints/endpoints/sls.php',
12+
),
13+
'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
14+
'attributeConsumingService' => array (
15+
'serviceName' => 'Service Name',
16+
'serviceDescription' => 'Service Description',
17+
'requestedAttributes' => array (
18+
array (
19+
'nameFormat' => \OneLogin_Saml2_Constants::ATTRNAME_FORMAT_BASIC,
20+
'isRequired' => false,
21+
'name' => 'userType',
22+
'attributeValue' => array('userType', 'admin')
23+
),
24+
array (
25+
'nameFormat' => \OneLogin_Saml2_Constants::ATTRNAME_FORMAT_URI,
26+
'isRequired' => true,
27+
'name' => 'urn:oid:0.9.2342.19200300.100.1.1',
28+
'friendlyName' => 'uid'
29+
),
30+
)
31+
)
32+
),
33+
'idp' => array (
34+
'entityId' => 'http://idp.example.com/',
35+
'singleSignOnService' => array (
36+
'url' => 'http://idp.example.com/SSOService.php',
37+
),
38+
'singleLogoutService' => array (
39+
'url' => 'http://idp.example.com/SingleLogoutService.php',
40+
),
41+
'x509cert' => 'MIICgTCCAeoCCQCbOlrWDdX7FTANBgkqhkiG9w0BAQUFADCBhDELMAkGA1UEBhMCTk8xGDAWBgNVBAgTD0FuZHJlYXMgU29sYmVyZzEMMAoGA1UEBxMDRm9vMRAwDgYDVQQKEwdVTklORVRUMRgwFgYDVQQDEw9mZWlkZS5lcmxhbmcubm8xITAfBgkqhkiG9w0BCQEWEmFuZHJlYXNAdW5pbmV0dC5ubzAeFw0wNzA2MTUxMjAxMzVaFw0wNzA4MTQxMjAxMzVaMIGEMQswCQYDVQQGEwJOTzEYMBYGA1UECBMPQW5kcmVhcyBTb2xiZXJnMQwwCgYDVQQHEwNGb28xEDAOBgNVBAoTB1VOSU5FVFQxGDAWBgNVBAMTD2ZlaWRlLmVybGFuZy5ubzEhMB8GCSqGSIb3DQEJARYSYW5kcmVhc0B1bmluZXR0Lm5vMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDivbhR7P516x/S3BqKxupQe0LONoliupiBOesCO3SHbDrl3+q9IbfnfmE04rNuMcPsIxB161TdDpIesLCn7c8aPHISKOtPlAeTZSnb8QAu7aRjZq3+PbrP5uW3TcfCGPtKTytHOge/OlJbo078dVhXQ14d1EDwXJW1rRXuUt4C8QIDAQABMA0GCSqGSIb3DQEBBQUAA4GBACDVfp86HObqY+e8BUoWQ9+VMQx1ASDohBjwOsg2WykUqRXF+dLfcUH9dWR63CtZIKFDbStNomPnQz7nbK+onygwBspVEbnHuUihZq3ZUdmumQqCw4Uvs/1Uvq3orOo/WJVhTyvLgFVK2QarQ4/67OZfHd7R+POBXhophSMv1ZOo',
42+
),
43+
44+
'security' => array (
45+
'authnRequestsSigned' => false,
46+
'wantAssertionsSigned' => false,
47+
'signMetadata' => false,
48+
),
49+
'contactPerson' => array (
50+
'technical' => array (
51+
'givenName' => 'technical_name',
52+
'emailAddress' => '[email protected]',
53+
),
54+
'support' => array (
55+
'givenName' => 'support_name',
56+
'emailAddress' => '[email protected]',
57+
),
58+
),
59+
60+
'organization' => array (
61+
'en-US' => array(
62+
'name' => 'sp_test',
63+
'displayname' => 'SP test',
64+
'url' => 'http://sp.example.com',
65+
),
66+
),
67+
);

tests/src/OneLogin/Saml2/MetadataTest.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,35 @@ public function testBuilderWithAttributeConsumingService()
7676

7777
$this->assertContains('<md:ServiceName xml:lang="en">Service Name</md:ServiceName>', $metadata);
7878
$this->assertContains('<md:ServiceDescription xml:lang="en">Service Description</md:ServiceDescription>', $metadata);
79-
$this->assertContains('<md:RequestedAttribute Name="FirstName" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="true"/>', $metadata);
80-
$this->assertContains('<md:RequestedAttribute Name="LastName" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="true"/>', $metadata);
79+
$this->assertContains('<md:RequestedAttribute Name="FirstName" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="true" />', $metadata);
80+
$this->assertContains('<md:RequestedAttribute Name="LastName" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="true" />', $metadata);
81+
82+
$result = \OneLogin_Saml2_Utils::validateXML($metadata, 'saml-schema-metadata-2.0.xsd');
83+
$this->assertInstanceOf('DOMDocument', $result);
84+
}
85+
86+
/**
87+
* Tests the builder method of the OneLogin_Saml2_Metadata
88+
*
89+
* @covers OneLogin_Saml2_Metadata::builder
90+
*/
91+
public function testBuilderWithAttributeConsumingServiceWithMultipleAttributeValue()
92+
{
93+
$settingsDir = TEST_ROOT .'/settings/';
94+
include $settingsDir.'settings4.php';
95+
$settings = new OneLogin_Saml2_Settings($settingsInfo);
96+
$spData = $settings->getSPData();
97+
$security = $settings->getSecurityData();
98+
$organization = $settings->getOrganization();
99+
$contacts = $settings->getContacts();
100+
101+
$metadata = OneLogin_Saml2_Metadata::builder($spData, $security['authnRequestsSigned'], $security['wantAssertionsSigned'], null, null, $contacts, $organization);
102+
103+
$this->assertContains('<md:ServiceName xml:lang="en">Service Name</md:ServiceName>', $metadata);
104+
$this->assertContains('<md:ServiceDescription xml:lang="en">Service Description</md:ServiceDescription>', $metadata);
105+
$this->assertContains('<md:RequestedAttribute Name="urn:oid:0.9.2342.19200300.100.1.1" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" FriendlyName="uid" isRequired="true" />', $metadata);
106+
$this->assertContains('<saml:AttributeValue xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">userType</saml:AttributeValue>', $metadata);
107+
$this->assertContains('<saml:AttributeValue xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">admin</saml:AttributeValue>', $metadata);
81108

82109
$result = \OneLogin_Saml2_Utils::validateXML($metadata, 'saml-schema-metadata-2.0.xsd');
83110
$this->assertInstanceOf('DOMDocument', $result);

0 commit comments

Comments
 (0)