ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AttributeQuery.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SAML2;
4 
21 {
27  private $attributes;
28 
37  private $nameFormat;
38 
45  public function __construct(\DOMElement $xml = null)
46  {
47  parent::__construct('AttributeQuery', $xml);
48 
49  $this->attributes = array();
50  $this->nameFormat = Constants::NAMEFORMAT_UNSPECIFIED;
51 
52  if ($xml === null) {
53  return;
54  }
55 
56  $firstAttribute = true;
57  $attributes = Utils::xpQuery($xml, './saml_assertion:Attribute');
58  foreach ($attributes as $attribute) {
59  if (!$attribute->hasAttribute('Name')) {
60  throw new \Exception('Missing name on <saml:Attribute> element.');
61  }
62  $name = $attribute->getAttribute('Name');
63 
64  if ($attribute->hasAttribute('NameFormat')) {
65  $nameFormat = $attribute->getAttribute('NameFormat');
66  } else {
67  $nameFormat = Constants::NAMEFORMAT_UNSPECIFIED;
68  }
69 
70  if ($firstAttribute) {
71  $this->nameFormat = $nameFormat;
72  $firstAttribute = false;
73  } else {
74  if ($this->nameFormat !== $nameFormat) {
75  $this->nameFormat = Constants::NAMEFORMAT_UNSPECIFIED;
76  }
77  }
78 
79  if (!array_key_exists($name, $this->attributes)) {
80  $this->attributes[$name] = array();
81  }
82 
83  $values = Utils::xpQuery($attribute, './saml_assertion:AttributeValue');
84  foreach ($values as $value) {
85  $this->attributes[$name][] = trim($value->textContent);
86  }
87  }
88  }
89 
95  public function getAttributes()
96  {
97  return $this->attributes;
98  }
99 
105  public function setAttributes(array $attributes)
106  {
107  $this->attributes = $attributes;
108  }
109 
118  public function getAttributeNameFormat()
119  {
120  return $this->nameFormat;
121  }
122 
128  public function setAttributeNameFormat($nameFormat)
129  {
130  assert(is_string($nameFormat));
131 
132  $this->nameFormat = $nameFormat;
133  }
134 
140  public function toUnsignedXML()
141  {
142  $root = parent::toUnsignedXML();
143 
144  foreach ($this->attributes as $name => $values) {
145  $attribute = $root->ownerDocument->createElementNS(Constants::NS_SAML, 'saml:Attribute');
146  $root->appendChild($attribute);
147  $attribute->setAttribute('Name', $name);
148 
149  if ($this->nameFormat !== Constants::NAMEFORMAT_UNSPECIFIED) {
150  $attribute->setAttribute('NameFormat', $this->nameFormat);
151  }
152 
153  foreach ($values as $value) {
154  if (is_string($value)) {
155  $type = 'xs:string';
156  } elseif (is_int($value)) {
157  $type = 'xs:integer';
158  } else {
159  $type = null;
160  }
161 
162  $attributeValue = Utils::addString($attribute, Constants::NS_SAML, 'saml:AttributeValue', $value);
163  if ($type !== null) {
164  $attributeValue->setAttributeNS(Constants::NS_XSI, 'xsi:type', $type);
165  }
166  }
167  }
168 
169  return $root;
170  }
171 }
getAttributeNameFormat()
Retrieve the NameFormat used on all attributes.
__construct(\DOMElement $xml=null)
Constructor for SAML 2 attribute query messages.
$type
setAttributeNameFormat($nameFormat)
Set the NameFormat used on all attributes.
setAttributes(array $attributes)
Set all requested attributes.
toUnsignedXML()
Convert the attribute query message to an XML element.
$values
$root
Definition: sabredav.php:45
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
getAttributes()
Retrieve all requested attributes.