Skip to content

Commit 394520d

Browse files
tvdijenmonkeyiq
authored andcommitted
Add possibility to provide connection context to XML storage-handler (#2332)
* Add possibility to pass a connection context to the MetaDataStorageHandlerXML * Add configuration example
1 parent f1a5568 commit 394520d

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

config/config.php.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,21 @@ $config = [
11341134
* ['type' => 'xml', 'file' => 'idp.example.org-idpMeta.xml'],
11351135
* ],
11361136
*
1137+
* This example defines a remote xml-file with optional connection context.
1138+
* See PHP documentation for possible context options: https://www.php.net/manual/en/context.php
1139+
*
1140+
* 'metadata.sources' => [
1141+
* [
1142+
* 'type' => 'xml',
1143+
* 'url' => 'https://example.org/idp.example.org-idpMeta.xml',
1144+
* 'context' => [
1145+
* 'ssl' => [
1146+
* 'verify_peer' => true,
1147+
* ],
1148+
* ],
1149+
* ],
1150+
* ],
1151+
*
11371152
* This example defines an mdq source.
11381153
* 'metadata.sources' => [
11391154
* [

src/SimpleSAML/Metadata/MetaDataStorageHandlerXML.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ protected function __construct(Configuration $globalConfig, array $config)
4343
parent::__construct();
4444

4545
$src = $srcXml = null;
46+
$context = [];
4647
if (array_key_exists('file', $config)) {
4748
// get the configuration
4849
$src = $globalConfig->resolvePath($config['file']);
4950
} elseif (array_key_exists('url', $config)) {
5051
$src = $config['url'];
52+
if (array_key_exists('context', $config)) {
53+
Assert::isArray($config['context']);
54+
$context = $config['context'];
55+
}
5156
} elseif (array_key_exists('xml', $config)) {
5257
$srcXml = $config['xml'];
5358
} else {
@@ -60,7 +65,7 @@ protected function __construct(Configuration $globalConfig, array $config)
6065
$AAD = [];
6166

6267
if (isset($src)) {
63-
$entities = SAMLParser::parseDescriptorsFile($src);
68+
$entities = SAMLParser::parseDescriptorsFile($src, $context);
6469
} elseif (isset($srcXml)) {
6570
$entities = SAMLParser::parseDescriptorsString($srcXml);
6671
} else {

src/SimpleSAML/Metadata/SAMLParser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,19 +289,20 @@ public static function parseElement(EntityDescriptor $entityElement): SAMLParser
289289
* instance.
290290
*
291291
* @param string $file The path to the file which contains the EntityDescriptor or EntitiesDescriptor element.
292+
* @param array $context The connection context to pass to file_get_contents()
292293
*
293294
* @return SAMLParser[] An array of SAMLParser instances.
294295
* @throws \Exception If the file does not parse as XML.
295296
*/
296-
public static function parseDescriptorsFile(string $file): array
297+
public static function parseDescriptorsFile(string $file, array $context = []): array
297298
{
298299
if (empty($file)) {
299300
throw new Exception('Cannot open file; file name not specified.');
300301
}
301302

302303
/** @var string $data */
303304
$httpUtils = new Utils\HTTP();
304-
$data = $httpUtils->fetch($file);
305+
$data = $httpUtils->fetch($file, $context);
305306

306307
try {
307308
$doc = DOMDocumentFactory::fromString($data);

0 commit comments

Comments
 (0)