Patrick Radtke <
pra...@gmail.com> wrote:
> Your evaluation looks correct, though I think the method you want to
> override is getMetaData since lookupIndexFromEntityId is private.
Here is a patch that implements the missing method. Any chance it gets merged?
Also: is there any merit to implement an efficient getEntityIdFromHostPath()?
--- lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php.orig
+++ lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
@@ -141,8 +141,50 @@
$this->cachedMetadata[$set] = $metadataSet;
return $metadataSet;
}
+ /**
+ * Retrieve a metadata entry.
+ *
+ * @param string $entityId The entityId we are looking up.
+ * @param string $set The set we are looking for metadata in.
+ *
+ * @return array An associative array with metadata for the given entity, or NULL if we are unable to
+ * locate the entity.
+ */
+ public function getMetaData($entityId, $set)
+ {
+ assert('is_string($entityId)');
+ assert('is_string($set)');
+
+ $tableName = $this->getTableName($set);
+
+ if (!in_array($set, $this->supportedSets, true)) {
+ return null;
+ }
+
+ $stmt = $this->db->read("SELECT entity_id, entity_data FROM $tableName WHERE entity_id=:entityId", array('entityId' => $entityId));
+ if ($stmt->execute()) {
+ $rowCount = 0;
+
+ while ($d = $stmt->fetch()) {
+ if (++$rowCount > 1) {
+ SimpleSAML\Logger::warning("Dulicate match for $entityId in set $set");
+ break;
+ }
+ $data = json_decode($d['entity_data'], true);
+ if ($data === null) {
+ throw new SimpleSAML_Error_Exception("Cannot decode metadata for entity '${d['entity_id']}'");
+ }
+ if (!array_key_exists('entityid', $data)) {
+ $data['entityid'] = $d['entity_id'];
+ }
+ }
+ return $data;
+ } else {
+ throw new Exception('PDO metadata handler: Database error: '.var_export($this->db->getLastError(), true));
+ }
+ }
private function generateDynamicHostedEntityID($set)
{
assert('is_string($set)');
--
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
ma...@netbsd.org