| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace SimpleSAML\SAML2\XML\md; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use DOMElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use SimpleSAML\XML\ExtendableAttributesTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use SimpleSAML\XML\ExtendableElementTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use function gmdate; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Class to represent a metadata document | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @package simplesamlphp/saml2 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  | abstract class AbstractMetadataDocument extends AbstractSignedMdElement | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     use ExtendableAttributesTrait; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     use ExtendableElementTrait; | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |      * The ID of this element. | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |      * @var string|null | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     protected ?string $Id; | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     /** @var \DOMElement $xml */ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     protected DOMElement $xml; | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      * How long this element is valid, as a unix timestamp. | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      * @var int|null | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     protected ?int $validUntil; | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |      * The length of time this element can be cached, as string. | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * @var string|null | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     protected ?string $cacheDuration; | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |      * Generic constructor for SAML metadata documents. | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |      * @param string|null $ID The ID for this document. Defaults to null. | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      * @param int|null    $validUntil Unix time of validity for this document. Defaults to null. | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * @param string|null $cacheDuration Maximum time this document can be cached. Defaults to null. | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions An array of extensions. Defaults to null. | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      * @param \DOMAttr[] $namespacedAttributes | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     public function __construct( | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         ?string $ID = null, | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         ?int $validUntil = null, | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         ?string $cacheDuration = null, | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |         ?Extensions $extensions = null, | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         $namespacedAttributes = [] | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |     ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         $this->setID($ID); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         $this->setValidUntil($validUntil); | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         $this->setCacheDuration($cacheDuration); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         $this->setExtensions($extensions); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         $this->setAttributesNS($namespacedAttributes); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |      * Collect the value of the ID property. | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |      * @return string|null | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |     public function getID(): ?string | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |         return $this->Id; | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |      * Set the value of the ID property. | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |      * @param string|null $id | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |     protected function setID(?string $id): void | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |         $this->Id = $id; | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |      * Collect the value of the validUntil property. | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |      * @return int|null | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     public function getValidUntil(): ?int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 99 |  |  |         return $this->validUntil; | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |      * Set the value of the validUntil-property | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |      * @param int|null $validUntil | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |     protected function setValidUntil(?int $validUntil): void | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |         $this->validUntil = $validUntil; | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |      * Collect the value of the cacheDuration property. | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |      * @return string|null | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |     public function getCacheDuration(): ?string | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |         return $this->cacheDuration; | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |      * Set the value of the cacheDuration-property | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |      * @param string|null $cacheDuration | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |     protected function setCacheDuration(?string $cacheDuration): void | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |         $this->cacheDuration = $cacheDuration; | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |      * @inheritDoc | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |     protected function getOriginalXML(): DOMElement | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |         return $this->xml; | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |      * @param \DOMElement|null $parent | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |      * @return \DOMElement | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     public function toXML(DOMElement $parent = null): DOMElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         $e = $this->instantiateParentElement($parent); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         foreach ($this->getAttributesNS() as $attr) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |             $e->setAttributeNS($attr['namespaceURI'], $attr['qualifiedName'], $attr['value']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         if ($this->Id !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             $e->setAttribute('ID', $this->Id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         if ($this->validUntil !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->validUntil)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         if ($this->cacheDuration !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |             $e->setAttribute('cacheDuration', $this->cacheDuration); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         if ($this->Extensions !== null && !$this->Extensions->isEmptyElement()) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |             $this->Extensions->toXML($e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 174 |  |  |         return $e; | 
            
                                                                        
                                                                
            
                                    
            
            
                | 175 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 176 |  |  | } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 177 |  |  |  |