ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SimpleSAML\Utils\Config\Metadata Class Reference
+ Collaboration diagram for SimpleSAML\Utils\Config\Metadata:

Static Public Member Functions

static getContact ($contact)
 Parse and sanitize a contact from an array. More...
 
static getDefaultEndpoint (array $endpoints, array $bindings=null)
 Find the default endpoint in an endpoint array. More...
 
static isHiddenFromDiscovery (array $metadata)
 Determine if an entity should be hidden in the discovery service. More...
 

Static Public Attributes

static $ENTITY_CATEGORY = 'http://macedir.org/entity-category'
 
static $HIDE_FROM_DISCOVERY = 'http://refeds.org/category/hide-from-discovery'
 
static $VALID_CONTACT_OPTIONS
 
static $VALID_CONTACT_TYPES
 

Detailed Description

Definition at line 10 of file Metadata.php.

Member Function Documentation

◆ getContact()

static SimpleSAML\Utils\Config\Metadata::getContact (   $contact)
static

Parse and sanitize a contact from an array.

Accepts an array with the following elements:

  • contactType The type of the contact (as string). Mandatory.
  • emailAddress Email address (as string), or array of email addresses. Optional.
  • telephoneNumber Telephone number of contact (as string), or array of telephone numbers. Optional.
  • name Full name of contact, either as <GivenName> <SurName>, or as <SurName>, <GivenName>. Optional.
  • surName Surname of contact (as string). Optional.
  • givenName Given name of contact (as string). Optional.
  • company Company name of contact (as string). Optional.

The following values are allowed as "contactType":

  • technical
  • support
  • administrative
  • billing
  • other

If given a "name" it will try to decompose it into its given name and surname, only if neither givenName nor surName are present. It works as follows:

  • "surname1 surname2, given_name1 given_name2" givenName: "given_name1 given_name2" surname: "surname1 surname2"
  • "given_name surname" givenName: "given_name" surname: "surname"

otherwise it will just return the name as "givenName" in the resulting array.

Parameters
array$contactThe contact to parse and sanitize.
Returns
array An array holding valid contact configuration options. If a key 'name' was part of the input array, it will try to decompose the name into its parts, and place the parts into givenName and surName, if those are missing.
Exceptions

Definition at line 101 of file Metadata.php.

References $names, and $t.

102  {
103  if (!(is_array($contact) || is_null($contact))) {
104  throw new \InvalidArgumentException('Invalid input parameters');
105  }
106 
107  // check the type
108  if (!isset($contact['contactType']) || !in_array($contact['contactType'], self::$VALID_CONTACT_TYPES, true)) {
109  $types = join(', ', array_map(
110  function ($t) {
111  return '"'.$t.'"';
112  },
113  self::$VALID_CONTACT_TYPES
114  ));
115  throw new \InvalidArgumentException('"contactType" is mandatory and must be one of '.$types.".");
116  }
117 
118  // check attributes is an associative array
119  if (isset($contact['attributes'])) {
120  if (empty($contact['attributes'])
121  || !is_array($contact['attributes'])
122  || count(array_filter(array_keys($contact['attributes']), 'is_string')) === 0
123  ) {
124  throw new \InvalidArgumentException('"attributes" must be an array and cannot be empty.');
125  }
126  }
127 
128  // try to fill in givenName and surName from name
129  if (isset($contact['name']) && !isset($contact['givenName']) && !isset($contact['surName'])) {
130  // first check if it's comma separated
131  $names = explode(',', $contact['name'], 2);
132  if (count($names) === 2) {
133  $contact['surName'] = preg_replace('/\s+/', ' ', trim($names[0]));
134  $contact['givenName'] = preg_replace('/\s+/', ' ', trim($names[1]));
135  } else {
136  // check if it's in "given name surname" format
137  $names = explode(' ', preg_replace('/\s+/', ' ', trim($contact['name'])));
138  if (count($names) === 2) {
139  $contact['givenName'] = preg_replace('/\s+/', ' ', trim($names[0]));
140  $contact['surName'] = preg_replace('/\s+/', ' ', trim($names[1]));
141  } else {
142  // nothing works, return it as given name
143  $contact['givenName'] = preg_replace('/\s+/', ' ', trim($contact['name']));
144  }
145  }
146  }
147 
148  // check givenName
149  if (isset($contact['givenName']) && (
150  empty($contact['givenName']) || !is_string($contact['givenName'])
151  )
152  ) {
153  throw new \InvalidArgumentException('"givenName" must be a string and cannot be empty.');
154  }
155 
156  // check surName
157  if (isset($contact['surName']) && (
158  empty($contact['surName']) || !is_string($contact['surName'])
159  )
160  ) {
161  throw new \InvalidArgumentException('"surName" must be a string and cannot be empty.');
162  }
163 
164  // check company
165  if (isset($contact['company']) && (
166  empty($contact['company']) || !is_string($contact['company'])
167  )
168  ) {
169  throw new \InvalidArgumentException('"company" must be a string and cannot be empty.');
170  }
171 
172  // check emailAddress
173  if (isset($contact['emailAddress'])) {
174  if (empty($contact['emailAddress']) ||
175  !(is_string($contact['emailAddress']) || is_array($contact['emailAddress']))
176  ) {
177  throw new \InvalidArgumentException('"emailAddress" must be a string or an array and cannot be empty.');
178  }
179  if (is_array($contact['emailAddress'])) {
180  foreach ($contact['emailAddress'] as $address) {
181  if (!is_string($address) || empty($address)) {
182  throw new \InvalidArgumentException('Email addresses must be a string and cannot be empty.');
183  }
184  }
185  }
186  }
187 
188  // check telephoneNumber
189  if (isset($contact['telephoneNumber'])) {
190  if (empty($contact['telephoneNumber']) ||
191  !(is_string($contact['telephoneNumber']) || is_array($contact['telephoneNumber']))
192  ) {
193  throw new \InvalidArgumentException(
194  '"telephoneNumber" must be a string or an array and cannot be empty.'
195  );
196  }
197  if (is_array($contact['telephoneNumber'])) {
198  foreach ($contact['telephoneNumber'] as $address) {
199  if (!is_string($address) || empty($address)) {
200  throw new \InvalidArgumentException('Telephone numbers must be a string and cannot be empty.');
201  }
202  }
203  }
204  }
205 
206  // make sure only valid options are outputted
207  return array_intersect_key($contact, array_flip(self::$VALID_CONTACT_OPTIONS));
208  }

◆ getDefaultEndpoint()

static SimpleSAML\Utils\Config\Metadata::getDefaultEndpoint ( array  $endpoints,
array  $bindings = null 
)
static

Find the default endpoint in an endpoint array.

Parameters
array$endpointsAn array with endpoints.
array$bindingsAn array with acceptable bindings. Can be null if any binding is allowed.
Returns
array|NULL The default endpoint, or null if no acceptable endpoints are used.
Author
Olav Morken, UNINETT AS olav..nosp@m.mork.nosp@m.en@un.nosp@m.inet.nosp@m.t.no

Definition at line 221 of file Metadata.php.

References $bindings.

222  {
223  $firstNotFalse = null;
224  $firstAllowed = null;
225 
226  // look through the endpoint list for acceptable endpoints
227  foreach ($endpoints as $ep) {
228  if ($bindings !== null && !in_array($ep['Binding'], $bindings, true)) {
229  // unsupported binding, skip it
230  continue;
231  }
232 
233  if (array_key_exists('isDefault', $ep)) {
234  if ($ep['isDefault'] === true) {
235  // this is the first endpoint with isDefault set to true
236  return $ep;
237  }
238  // isDefault is set to false, but the endpoint is still usable as a last resort
239  if ($firstAllowed === null) {
240  // this is the first endpoint that we can use
241  $firstAllowed = $ep;
242  }
243  } else {
244  if ($firstNotFalse === null) {
245  // this is the first endpoint without isDefault set
246  $firstNotFalse = $ep;
247  }
248  }
249  }
250 
251  if ($firstNotFalse !== null) {
252  // we have an endpoint without isDefault set to false
253  return $firstNotFalse;
254  }
255 
256  /* $firstAllowed either contains the first endpoint we can use, or it contains null if we cannot use any of the
257  * endpoints. Either way we return its value.
258  */
259  return $firstAllowed;
260  }
$bindings

◆ isHiddenFromDiscovery()

static SimpleSAML\Utils\Config\Metadata::isHiddenFromDiscovery ( array  $metadata)
static

Determine if an entity should be hidden in the discovery service.

This method searches for the "Hide From Discovery" REFEDS Entity Category, and tells if the entity should be hidden or not depending on it.

See also
https://refeds.org/category/hide-from-discovery
Parameters
array$metadataAn associative array with the metadata representing an entity.
Returns
boolean True if the entity should be hidden, false otherwise.

Definition at line 275 of file Metadata.php.

References SimpleSAML\Logger\maskErrors(), and SimpleSAML\Logger\popErrorMask().

276  {
278  $hidden = in_array(self::$HIDE_FROM_DISCOVERY, $metadata['EntityAttributes'][self::$ENTITY_CATEGORY], true);
280  return $hidden === true;
281  }
static popErrorMask()
Pop an error mask.
Definition: Logger.php:324
$metadata['__DYNAMIC:1__']
static maskErrors($mask)
Disable error reporting for the given log levels.
Definition: Logger.php:306
+ Here is the call graph for this function:

Field Documentation

◆ $ENTITY_CATEGORY

SimpleSAML\Utils\Config\Metadata::$ENTITY_CATEGORY = 'http://macedir.org/entity-category'
static

Definition at line 18 of file Metadata.php.

◆ $HIDE_FROM_DISCOVERY

SimpleSAML\Utils\Config\Metadata::$HIDE_FROM_DISCOVERY = 'http://refeds.org/category/hide-from-discovery'
static

Definition at line 26 of file Metadata.php.

◆ $VALID_CONTACT_OPTIONS

SimpleSAML\Utils\Config\Metadata::$VALID_CONTACT_OPTIONS
static
Initial value:
'contactType',
'emailAddress',
'givenName',
'surName',
'telephoneNumber',
'company',
'attributes',
)

Definition at line 39 of file Metadata.php.

◆ $VALID_CONTACT_TYPES

SimpleSAML\Utils\Config\Metadata::$VALID_CONTACT_TYPES
static
Initial value:
'technical',
'support',
'administrative',
'billing',
'other',
)

Definition at line 54 of file Metadata.php.


The documentation for this class was generated from the following file: