private function parseSubject(\DOMElement $xml)
{
$subject = Utils::xpQuery($xml, './saml_assertion:Subject');
if (empty($subject)) {
/* No Subject node. */
return;
} elseif (count($subject) > 1) {
throw new \Exception('More than one <saml:Subject> in <saml:Assertion>.');
}
$subject = $subject[0];
$nameId = Utils::xpQuery($subject, './saml_assertion:NameID | ./saml_assertion:EncryptedID/xenc:EncryptedData');
if (count($nameId) > 1) {
throw new \Exception('More than one <saml:NameID> or <saml:EncryptedID> in <saml:Subject>.');
} elseif (!empty($nameId)) {
$nameId = $nameId[0];
if ($nameId->localName === 'EncryptedData') {
/* The NameID element is encrypted. */
$this->encryptedNameId = $nameId;
} else {
$this->nameId = Utils::parseNameId($nameId);
}
}
$subjectConfirmation = Utils::xpQuery($subject, './saml_assertion:SubjectConfirmation');
if (empty($subjectConfirmation) && empty($nameId)) {
throw new \Exception('Missing <saml:SubjectConfirmation> in <saml:Subject>.');
}
foreach ($subjectConfirmation as $sc) {
$this->SubjectConfirmation[] = new SubjectConfirmation($sc);
}
}