Beispiel #1
0
 /**
  * Test adding two random elements
  */
 public function testExtensionsAddSome()
 {
     $attribute = new Attribute();
     $attribute->Name = 'TheName';
     $scope = new Scope();
     $scope->scope = "scope";
     Extensions::addList($this->testElement, array($attribute, $scope));
     $list = Extensions::getList($this->testElement);
     $this->assertCount(4, $list);
     $this->assertEquals("urn:mynamespace", $list[0]->namespaceURI);
     $this->assertEquals("ExampleElement", $list[1]->localName);
     $this->assertEquals("Attribute", $list[2]->localName);
     $this->assertEquals("urn:mace:shibboleth:metadata:1.0", $list[3]->namespaceURI);
 }
Beispiel #2
0
 /**
  * Initialize a message.
  *
  * This constructor takes an optional parameter with a \DOMElement. If this
  * parameter is given, the message will be initialized with data from that
  * XML element.
  *
  * If no XML element is given, the message is initialized with suitable
  * default values.
  *
  * @param string          $tagName The tag name of the root element.
  * @param \DOMElement|null $xml     The input message.
  * @throws \Exception
  */
 protected function __construct($tagName, \DOMElement $xml = null)
 {
     assert('is_string($tagName)');
     $this->tagName = $tagName;
     $this->id = Utils::getContainer()->generateId();
     $this->issueInstant = Temporal::getTime();
     $this->certificates = array();
     $this->validators = array();
     if ($xml === null) {
         return;
     }
     if (!$xml->hasAttribute('ID')) {
         throw new \Exception('Missing ID attribute on SAML message.');
     }
     $this->id = $xml->getAttribute('ID');
     if ($xml->getAttribute('Version') !== '2.0') {
         /* Currently a very strict check. */
         throw new \Exception('Unsupported version: ' . $xml->getAttribute('Version'));
     }
     $this->issueInstant = Utils::xsDateTimeToTimestamp($xml->getAttribute('IssueInstant'));
     if ($xml->hasAttribute('Destination')) {
         $this->destination = $xml->getAttribute('Destination');
     }
     if ($xml->hasAttribute('Consent')) {
         $this->consent = $xml->getAttribute('Consent');
     }
     $issuer = Utils::xpQuery($xml, './saml_assertion:Issuer');
     if (!empty($issuer)) {
         $this->issuer = trim($issuer[0]->textContent);
     }
     /* Validate the signature element of the message. */
     try {
         $sig = Utils::validateElement($xml);
         if ($sig !== false) {
             $this->messageContainedSignatureUponConstruction = true;
             $this->certificates = $sig['Certificates'];
             $this->validators[] = array('Function' => array('\\SAML2\\Utils', 'validateSignature'), 'Data' => $sig);
         }
     } catch (\Exception $e) {
         /* Ignore signature validation errors. */
     }
     $this->extensions = Extensions::getList($xml);
 }
Beispiel #3
0
 /**
  * Initialize a message.
  *
  * This constructor takes an optional parameter with a \DOMElement. If this
  * parameter is given, the message will be initialized with data from that
  * XML element.
  *
  * If no XML element is given, the message is initialized with suitable
  * default values.
  *
  * @param string           $tagName The tag name of the root element
  * @param \DOMElement|null $xml     The input message
  *
  * @throws \Exception
  */
 protected function __construct($tagName, \DOMElement $xml = null)
 {
     assert('is_string($tagName)');
     $this->tagName = $tagName;
     $this->id = Utils::getContainer()->generateId();
     $this->issueInstant = Temporal::getTime();
     $this->certificates = array();
     $this->validators = array();
     if ($xml === null) {
         return;
     }
     if (!$xml->hasAttribute('ID')) {
         throw new \Exception('Missing ID attribute on SAML message.');
     }
     $this->id = $xml->getAttribute('ID');
     if ($xml->getAttribute('Version') !== '2.0') {
         /* Currently a very strict check. */
         throw new \Exception('Unsupported version: ' . $xml->getAttribute('Version'));
     }
     $this->issueInstant = Utils::xsDateTimeToTimestamp($xml->getAttribute('IssueInstant'));
     if ($xml->hasAttribute('Destination')) {
         $this->destination = $xml->getAttribute('Destination');
     }
     if ($xml->hasAttribute('Consent')) {
         $this->consent = $xml->getAttribute('Consent');
     }
     $issuer = Utils::xpQuery($xml, './saml_assertion:Issuer');
     if (!empty($issuer)) {
         $this->issuer = new XML\saml\Issuer($issuer[0]);
         if ($this->issuer->Format === Constants::NAMEID_ENTITY) {
             $this->issuer = $this->issuer->value;
         }
     }
     $this->validateSignature($xml);
     $this->extensions = Extensions::getList($xml);
 }