Skip to content
Snippets Groups Projects
Commit 3a12e85d authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Avoid code duplication when checking if an entity should be hidden from discovery service.

parent b5757a05
No related branches found
No related tags found
No related merge requests found
...@@ -490,12 +490,8 @@ class SimpleSAML_Metadata_SAMLParser ...@@ -490,12 +490,8 @@ class SimpleSAML_Metadata_SAMLParser
$metadata['EntityAttributes'] = $this->entityAttributes; $metadata['EntityAttributes'] = $this->entityAttributes;
// check for entity categories // check for entity categories
$entity_category = 'http://macedir.org/entity-category'; if (SimpleSAML\Utils\Config\Metadata::isHiddenFromDiscovery($metadata)) {
$hide_from_discovery = 'http://refeds.org/category/hide-from-discovery'; $metadata['hide.from.discovery'] = true;
if (array_key_exists($entity_category, $metadata['EntityAttributes'])) {
if (in_array($hide_from_discovery, $metadata['EntityAttributes'][$entity_category])) {
$metadata['hide.from.discovery'] = true;
}
} }
} }
......
...@@ -10,6 +10,22 @@ namespace SimpleSAML\Utils\Config; ...@@ -10,6 +10,22 @@ namespace SimpleSAML\Utils\Config;
class Metadata class Metadata
{ {
/**
* The string that identities Entity Categories.
*
* @var string
*/
public static $ENTITY_CATEGORY = 'http://macedir.org/entity-category';
/**
* The string the identifies the REFEDS "Hide From Discovery" Entity Category.
*
* @var string
*/
public static $HIDE_FROM_DISCOVERY = 'http://refeds.org/category/hide-from-discovery';
/** /**
* @var array The valid configuration options for a contact configuration array. * @var array The valid configuration options for a contact configuration array.
* @see "Metadata for the OASIS Security Assertion Markup Language (SAML) V2.0", section 2.3.2.2. * @see "Metadata for the OASIS Security Assertion Markup Language (SAML) V2.0", section 2.3.2.2.
...@@ -157,7 +173,9 @@ class Metadata ...@@ -157,7 +173,9 @@ class Metadata
if (empty($contact['telephoneNumber']) || if (empty($contact['telephoneNumber']) ||
!(is_string($contact['telephoneNumber']) || is_array($contact['telephoneNumber'])) !(is_string($contact['telephoneNumber']) || is_array($contact['telephoneNumber']))
) { ) {
throw new \InvalidArgumentException('"telephoneNumber" must be a string or an array and cannot be empty.'); throw new \InvalidArgumentException(
'"telephoneNumber" must be a string or an array and cannot be empty.'
);
} }
if (is_array($contact['telephoneNumber'])) { if (is_array($contact['telephoneNumber'])) {
foreach ($contact['telephoneNumber'] as $address) { foreach ($contact['telephoneNumber'] as $address) {
...@@ -223,4 +241,27 @@ class Metadata ...@@ -223,4 +241,27 @@ class Metadata
*/ */
return $firstAllowed; return $firstAllowed;
} }
/**
* 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 https://refeds.org/category/hide-from-discovery
*
* @param array $metadata An associative array with the metadata representing an entity.
*
* @return boolean True if the entity should be hidden, false otherwise.
*/
public static function isHiddenFromDiscovery($metadata)
{
if (array_key_exists(self::$ENTITY_CATEGORY, $metadata['EntityAttributes'])) {
if (in_array(self::$HIDE_FROM_DISCOVERY, $metadata['EntityAttributes'][self::$ENTITY_CATEGORY])) {
return true;
}
}
return false;
}
} }
...@@ -147,12 +147,8 @@ try { ...@@ -147,12 +147,8 @@ try {
$metaArray['EntityAttributes'] = $idpmeta->getArray('EntityAttributes'); $metaArray['EntityAttributes'] = $idpmeta->getArray('EntityAttributes');
// check for entity categories // check for entity categories
$entity_category = 'http://macedir.org/entity-category'; if (SimpleSAML\Utils\Config\Metadata::isHiddenFromDiscovery($metaArray)) {
$hide_from_discovery = 'http://refeds.org/category/hide-from-discovery'; $metaArray['hide.from.discovery'] = true;
if (array_key_exists($entity_category, $metaArray['EntityAttributes'])) {
if (in_array($hide_from_discovery, $metaArray['EntityAttributes'][$entity_category])) {
$metaArray['hide.from.discovery'] = true;
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment