From 7993a48ccc68fb8d0637fc02bc0ec246a1724ed2 Mon Sep 17 00:00:00 2001
From: Thijs Kinkhorst <thijs@kinkhorst.com>
Date: Mon, 20 Jun 2022 17:30:07 +0000
Subject: [PATCH] Restore entityid in lower case, since almost all code depends
 on it.

Partially reverts b7c2caad0630f6f8a2cfa9263e7648edacbf045b
and fc1ffee7388ae65289537ec1348d8b234068e50d

Closes: #1660
---
 modules/saml/src/Auth/Source/SP.php                        | 3 +++
 src/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php | 2 +-
 src/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php      | 4 ++--
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/modules/saml/src/Auth/Source/SP.php b/modules/saml/src/Auth/Source/SP.php
index 9e0f5882d..f11afa9ba 100644
--- a/modules/saml/src/Auth/Source/SP.php
+++ b/modules/saml/src/Auth/Source/SP.php
@@ -81,6 +81,9 @@ class SP extends \SimpleSAML\Auth\Source
         // Call the parent constructor first, as required by the interface
         parent::__construct($info, $config);
 
+        /* For compatibility with code that assumes that $metadata->getString('entityid')
+         * gives the entity id. */
+        $config['entityid'] = $config['entityID'];
         $this->metadata = Configuration::loadFromArray(
             $config,
             'authsources[' . var_export($this->authId, true) . ']'
diff --git a/src/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php b/src/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
index 042dfa477..cac0b975d 100644
--- a/src/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
+++ b/src/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
@@ -124,7 +124,7 @@ class MetaDataStorageHandlerFlatFile extends MetaDataStorageSource
 
         // add the entity id of an entry to each entry in the metadata
         foreach ($metadataSet as $entityId => &$entry) {
-            $entry['entityID'] = $entityId;
+            $entry['entityid'] = $entityId;
         }
 
         $this->cachedMetadata[$set] = $metadataSet;
diff --git a/src/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php b/src/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
index c84408f25..bfd4b1a6d 100644
--- a/src/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
+++ b/src/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
@@ -96,7 +96,7 @@ class MetaDataStorageHandlerPdo extends MetaDataStorageSource
                     throw new Error\Exception("Cannot decode metadata for entity '${d['entity_id']}'");
                 }
                 if (!array_key_exists('entityid', $data)) {
-                    $data['entityID'] = $d['entity_id'];
+                    $data['entityid'] = $d['entity_id'];
                 }
                 $metadata[$d['entity_id']] = $data;
             }
@@ -129,7 +129,7 @@ class MetaDataStorageHandlerPdo extends MetaDataStorageSource
         }
 
         foreach ($metadataSet as $entityId => &$entry) {
-            $entry['entityID'] = $entityId;
+            $entry['entityid'] = $entityId;
         }
 
         $this->cachedMetadata[$set] = $metadataSet;
-- 
GitLab