| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace SimpleSAML\SAML2\XML\md; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use DOMElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use SimpleSAML\Assert\Assert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use SimpleSAML\XML\Chunk; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use SimpleSAML\XML\Exception\InvalidDOMElementException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use SimpleSAML\XML\Exception\TooManyElementsException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use SimpleSAML\XML\Utils as XMLUtils; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use function preg_split; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * Class representing unknown RoleDescriptors. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @package simplesamlphp/saml2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | final class UnknownRoleDescriptor extends AbstractRoleDescriptor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * This RoleDescriptor as XML | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @var \SimpleSAML\XML\Chunk | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @psalm-suppress PropertyNotSetInConstructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     protected Chunk $elt; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * Initialize an unknown RoleDescriptor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @param \DOMElement $xml The XML element we should load. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @return \SimpleSAML\SAML2\XML\md\UnknownRoleDescriptor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException if the qualified name of the supplied element is wrong | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @throws \SimpleSAML\XML\Exception\MissingAttributeException if the supplied element is missing one of the mandatory attributes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @throws \SimpleSAML\XML\Exception\TooManyElementsException if too many child-elements of a type are specified | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     public static function fromXML(DOMElement $xml): object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $protocols = self::getAttribute($xml, 'protocolSupportEnumeration'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $validUntil = self::getAttribute($xml, 'validUntil', null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $orgs = Organization::getChildrenOfClass($xml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         Assert::maxCount($orgs, 1, 'More than one Organization found in this descriptor', TooManyElementsException::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $extensions = Extensions::getChildrenOfClass($xml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         Assert::maxCount($extensions, 1, 'Only one md:Extensions element is allowed.', TooManyElementsException::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $object = new self( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             preg_split('/[\s]+/', trim($protocols)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             self::getAttribute($xml, 'ID', null), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             $validUntil !== null ? XMLUtils::xsDateTimeToTimestamp($validUntil) : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             self::getAttribute($xml, 'cacheDuration', null), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             !empty($extensions) ? $extensions[0] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             self::getAttribute($xml, 'errorURL', null), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             KeyDescriptor::getChildrenOfClass($xml), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             !empty($orgs) ? $orgs[0] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             ContactPerson::getChildrenOfClass($xml) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $object->elt = new Chunk($xml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $object->setXML($xml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         return $object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * Get the original XML of this descriptor as a Chunk object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @return \SimpleSAML\XML\Chunk | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 76 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |     public function getElement(): Chunk | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |         return $this->elt; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * Convert this descriptor to an unsigned XML document. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * This method does not sign the resulting XML document. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @param \DOMElement|null $parent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @return \DOMElement The root element of the DOM tree | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     protected function toUnsignedXML(DOMElement $parent = null): DOMElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         return $this->elt->toXML($parent); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 94 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 95 |  |  |  |