|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SAML2\XML\md; |
|
4
|
|
|
|
|
5
|
|
|
use SAML2\Constants; |
|
6
|
|
|
use SAML2\Utils; |
|
7
|
|
|
use SAML2\XML\alg\Common as ALG; |
|
8
|
|
|
use SAML2\XML\alg\DigestMethod; |
|
9
|
|
|
use SAML2\XML\alg\SigningMethod; |
|
10
|
|
|
use SAML2\XML\Chunk; |
|
11
|
|
|
use SAML2\XML\mdattr\EntityAttributes; |
|
12
|
|
|
use SAML2\XML\mdrpi\Common as MDRPI; |
|
13
|
|
|
use SAML2\XML\mdrpi\PublicationInfo; |
|
14
|
|
|
use SAML2\XML\mdrpi\RegistrationInfo; |
|
15
|
|
|
use SAML2\XML\mdui\DiscoHints; |
|
16
|
|
|
use SAML2\XML\mdui\UIInfo; |
|
17
|
|
|
use SAML2\XML\shibmd\Scope; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class for handling SAML2 metadata extensions. |
|
21
|
|
|
* |
|
22
|
|
|
* @package SimpleSAMLphp |
|
23
|
|
|
*/ |
|
24
|
|
|
class Extensions |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Get a list of Extensions in the given element. |
|
28
|
|
|
* |
|
29
|
|
|
* @param \DOMElement $parent The element that may contain the md:Extensions element. |
|
30
|
|
|
* @return \SAML2\XML\Chunk[] Array of extensions. |
|
31
|
|
|
*/ |
|
32
|
|
|
public static function getList(\DOMElement $parent) |
|
33
|
|
|
{ |
|
34
|
|
|
$ret = array(); |
|
35
|
|
|
$supported = array( |
|
36
|
|
|
Scope::NS => array( |
|
37
|
|
|
'Scope' |
|
38
|
|
|
), |
|
39
|
|
|
EntityAttributes::NS => array( |
|
40
|
|
|
'EntityAttributes' |
|
41
|
|
|
), |
|
42
|
|
|
MDRPI::NS_MDRPI => array( |
|
43
|
|
|
'RegistrationInfo', |
|
44
|
|
|
'PublicationInfo', |
|
45
|
|
|
), |
|
46
|
|
|
UIInfo::NS => array( |
|
47
|
|
|
'UIInfo' |
|
48
|
|
|
), |
|
49
|
|
|
DiscoHints::NS => array( |
|
50
|
|
|
'DiscoHints' |
|
51
|
|
|
), |
|
52
|
|
|
ALG::NS => array( |
|
53
|
|
|
'DigestMethod', |
|
54
|
|
|
'SigningMethod', |
|
55
|
|
|
), |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
foreach (Utils::xpQuery($parent, './saml_metadata:Extensions/*') as $node) { |
|
59
|
|
|
if (in_array($node->namespaceURI, array_keys($supported)) && |
|
60
|
|
|
in_array($node->localName, $supported[$node->namespaceURI]) |
|
61
|
|
|
) { |
|
62
|
|
|
$ret[] = new $supported[$node->namespaceURI]($node); |
|
63
|
|
|
} else { |
|
64
|
|
|
$ret[] = new Chunk($node); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $ret; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Add a list of Extensions to the given element. |
|
73
|
|
|
* |
|
74
|
|
|
* @param \DOMElement $parent The element we should add the extensions to. |
|
75
|
|
|
* @param \SAML2\XML\Chunk[] $extensions List of extension objects. |
|
76
|
|
|
*/ |
|
77
|
|
View Code Duplication |
public static function addList(\DOMElement $parent, array $extensions) |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
if (empty($extensions)) { |
|
80
|
|
|
return; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$extElement = $parent->ownerDocument->createElementNS(Constants::NS_MD, 'md:Extensions'); |
|
84
|
|
|
$parent->appendChild($extElement); |
|
85
|
|
|
|
|
86
|
|
|
foreach ($extensions as $ext) { |
|
87
|
|
|
$ext->toXML($extElement); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.