parseSubject($xml); } /** * Parse subject in query. * * @param DOMElement $xml The SubjectQuery XML element. */ private function parseSubject(DOMElement $xml) { $subject = SAML2_Utils::xpQuery($xml, './saml_assertion:Subject'); if (empty($subject)) { /* No Subject node. */ throw new Exception('Missing subject in subject query.'); } elseif (count($subject) > 1) { throw new Exception('More than one in .'); } $subject = $subject[0]; $nameId = SAML2_Utils::xpQuery($subject, './saml_assertion:NameID'); if (empty($nameId)) { throw new Exception('Missing in .'); } elseif (count($nameId) > 1) { throw new Exception('More than one in .'); } $nameId = $nameId[0]; $this->nameId = SAML2_Utils::parseNameId($nameId); } /** * Retrieve the NameId of the subject in the query. * * The returned NameId is in the format used by SAML2_Utils::addNameId(). * * @see SAML2_Utils::addNameId() * @return array|NULL The name identifier of the assertion. */ public function getNameId() { return $this->nameId; } /** * Set the NameId of the subject in the query. * * The NameId must be in the format accepted by SAML2_Utils::addNameId(). * * @see SAML2_Utils::addNameId() * @param array|NULL $nameId The name identifier of the assertion. */ public function setNameId($nameId) { assert('is_array($nameId) || is_null($nameId)'); $this->nameId = $nameId; } /** * Convert subject query message to an XML element. * * @return DOMElement This subject query. */ public function toUnsignedXML() { $root = parent::toUnsignedXML(); $subject = $root->ownerDocument->createElementNS(SAML2_Const::NS_SAML, 'saml:Subject'); $root->appendChild($subject); SAML2_Utils::addNameId($subject, $this->nameId); return $root; } }