ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SubjectQuery.php
Go to the documentation of this file.
1<?php
2
3namespace SAML2;
4
16abstract class SubjectQuery extends Request
17{
23 private $nameId;
24
25
32 protected function __construct($tagName, \DOMElement $xml = null)
33 {
34 parent::__construct($tagName, $xml);
35
36 if ($xml === null) {
37 return;
38 }
39
40 $this->parseSubject($xml);
41 }
42
43
50 private function parseSubject(\DOMElement $xml)
51 {
52 $subject = Utils::xpQuery($xml, './saml_assertion:Subject');
53 if (empty($subject)) {
54 /* No Subject node. */
55 throw new \Exception('Missing subject in subject query.');
56 } elseif (count($subject) > 1) {
57 throw new \Exception('More than one <saml:Subject> in <saml:Assertion>.');
58 }
59 $subject = $subject[0];
60
61 $nameId = Utils::xpQuery($subject, './saml_assertion:NameID');
62 if (empty($nameId)) {
63 throw new \Exception('Missing <saml:NameID> in <saml:Subject>.');
64 } elseif (count($nameId) > 1) {
65 throw new \Exception('More than one <saml:NameID> in <saml:Subject>.');
66 }
67 $nameId = $nameId[0];
68 $this->nameId = new XML\saml\NameID($nameId);
69 }
70
71
77 public function getNameId()
78 {
79 return $this->nameId;
80 }
81
82
88 public function setNameId($nameId)
89 {
90 assert(is_array($nameId) || is_null($nameId) || $nameId instanceof XML\saml\NameID);
91
92 if (is_array($nameId)) {
93 $nameId = XML\saml\NameID::fromArray($nameId);
94 }
95 $this->nameId = $nameId;
96 }
97
98
104 public function toUnsignedXML()
105 {
106 $root = parent::toUnsignedXML();
107
108 $subject = $root->ownerDocument->createElementNS(Constants::NS_SAML, 'saml:Subject');
109 $root->appendChild($subject);
110
111 $this->nameId->toXML($subject);
112
113 return $root;
114 }
115}
An exception for terminatinating execution or to throw for unit testing.
__construct($tagName, \DOMElement $xml=null)
Constructor for SAML 2 subject query messages.
parseSubject(\DOMElement $xml)
Parse subject in query.
setNameId($nameId)
Set the NameId of the subject in the query.
getNameId()
Retrieve the NameId of the subject in the query.
toUnsignedXML()
Convert subject query message to an XML element.
$nameId
Definition: saml2-acs.php:138
$root
Definition: sabredav.php:45