ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SimpleSAML_Metadata_MetaDataStorageHandlerPdo Class Reference
+ Inheritance diagram for SimpleSAML_Metadata_MetaDataStorageHandlerPdo:
+ Collaboration diagram for SimpleSAML_Metadata_MetaDataStorageHandlerPdo:

Public Member Functions

 __construct ($config)
 This constructor initializes the PDO metadata storage handler with the specified configuration. More...
 
 getMetadataSet ($set)
 Retrieve a list of all available metadata for a given set. More...
 
 getMetaData ($entityId, $set)
 Retrieve a metadata entry. More...
 
 addEntry ($index, $set, $entityData)
 Add metadata to the configured database. More...
 
 initDatabase ()
 Initialize the configured database. More...
 

Data Fields

 $supportedSets
 All the metadata sets supported by this MetaDataStorageHandler. More...
 

Private Member Functions

 load ($set)
 This function loads the given set of metadata from a file to a configured database. More...
 
 generateDynamicHostedEntityID ($set)
 
 getTableName ($table)
 Replace the -'s to an _ in table names for Metadata sets since SQL does not allow a - in a table name. More...
 

Private Attributes

 $db
 The PDO object. More...
 
 $tablePrefix
 Prefix to apply to the metadata table. More...
 
 $cachedMetadata = array()
 This is an associative array which stores the different metadata sets we have loaded. More...
 

Additional Inherited Members

Detailed Description

Definition at line 13 of file MetaDataStorageHandlerPdo.php.

Constructor & Destructor Documentation

◆ __construct()

SimpleSAML_Metadata_MetaDataStorageHandlerPdo::__construct (   $config)

This constructor initializes the PDO metadata storage handler with the specified configuration.

The configuration is an associative array with the following possible elements (set in config.php):

  • 'usePersistentConnection': TRUE/FALSE if database connection should be persistent.
  • 'dsn': The database connection string.
  • 'username': Database user name
  • 'password': Password for the database user.
Parameters
array$configAn associative array with the configuration for this handler.

Definition at line 60 of file MetaDataStorageHandlerPdo.php.

61 {
62 assert(is_array($config));
63
65 }
static getInstance($altConfig=null)
Retrieves the current database instance.
Definition: Database.php:55
$config
Definition: bootstrap.php:15

References $config, and SimpleSAML\Database\getInstance().

+ Here is the call graph for this function:

Member Function Documentation

◆ addEntry()

SimpleSAML_Metadata_MetaDataStorageHandlerPdo::addEntry (   $index,
  $set,
  $entityData 
)

Add metadata to the configured database.

Parameters
string$indexEntity ID
string$setThe set to add the metadata to
array$entityDataMetadata
Returns
bool True/False if entry was successfully added

Definition at line 222 of file MetaDataStorageHandlerPdo.php.

223 {
224 assert(is_string($index));
225 assert(is_string($set));
226 assert(is_array($entityData));
227
228 if (!in_array($set, $this->supportedSets, true)) {
229 return false;
230 }
231
232 $tableName = $this->getTableName($set);
233
234 $metadata = $this->db->read(
235 "SELECT entity_id, entity_data FROM $tableName WHERE entity_id = :entity_id",
236 array(
237 'entity_id' => $index,
238 )
239 );
240
241 $retrivedEntityIDs = $metadata->fetch();
242
243 $params = array(
244 'entity_id' => $index,
245 'entity_data' => json_encode($entityData),
246 );
247
248 if ($retrivedEntityIDs !== false && count($retrivedEntityIDs) > 0) {
249 $rows = $this->db->write(
250 "UPDATE $tableName SET entity_data = :entity_data WHERE entity_id = :entity_id",
251 $params
252 );
253 } else {
254 $rows = $this->db->write(
255 "INSERT INTO $tableName (entity_id, entity_data) VALUES (:entity_id, :entity_data)",
256 $params
257 );
258 }
259
260 return $rows === 1;
261 }
$metadata['__DYNAMIC:1__']
getTableName($table)
Replace the -'s to an _ in table names for Metadata sets since SQL does not allow a - in a table name...
$index
Definition: metadata.php:60
$rows
Definition: xhr_table.php:10

References $index, $metadata, PHPMailer\PHPMailer\$params, $rows, and getTableName().

+ Here is the call graph for this function:

◆ generateDynamicHostedEntityID()

SimpleSAML_Metadata_MetaDataStorageHandlerPdo::generateDynamicHostedEntityID (   $set)
private

Definition at line 188 of file MetaDataStorageHandlerPdo.php.

189 {
190 assert(is_string($set));
191
192 // get the configuration
194
195 if ($set === 'saml20-idp-hosted') {
196 return $baseurl.'saml2/idp/metadata.php';
197 } elseif ($set === 'saml20-sp-hosted') {
198 return $baseurl.'saml2/sp/metadata.php';
199 } elseif ($set === 'shib13-idp-hosted') {
200 return $baseurl.'shib13/idp/metadata.php';
201 } elseif ($set === 'shib13-sp-hosted') {
202 return $baseurl.'shib13/sp/metadata.php';
203 } elseif ($set === 'wsfed-sp-hosted') {
204 return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost();
205 } elseif ($set === 'adfs-idp-hosted') {
206 return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost().':idp';
207 } else {
208 throw new Exception('Can not generate dynamic EntityID for metadata of this type: ['.$set.']');
209 }
210 }
static getBaseURL()
Retrieve the base URL of the SimpleSAMLphp installation.
Definition: HTTP.php:597

References SimpleSAML\Utils\HTTP\getBaseURL().

Referenced by getMetadataSet().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMetaData()

SimpleSAML_Metadata_MetaDataStorageHandlerPdo::getMetaData (   $entityId,
  $set 
)

Retrieve a metadata entry.

Parameters
string$entityIdThe entityId we are looking up.
string$setThe set we are looking for metadata in.
Returns
array An associative array with metadata for the given entity, or NULL if we are unable to locate the entity.

Reimplemented from SimpleSAML_Metadata_MetaDataStorageSource.

Definition at line 153 of file MetaDataStorageHandlerPdo.php.

154 {
155 assert(is_string($entityId));
156 assert(is_string($set));
157
158 $tableName = $this->getTableName($set);
159
160 if (!in_array($set, $this->supportedSets, true)) {
161 return null;
162 }
163
164 $stmt = $this->db->read("SELECT entity_id, entity_data FROM $tableName WHERE entity_id=:entityId", array('entityId' => $entityId));
165 if ($stmt->execute()) {
166 $rowCount = 0;
167 $data = null;
168
169 while ($d = $stmt->fetch()) {
170 if (++$rowCount > 1) {
171 SimpleSAML\Logger::warning("Duplicate match for $entityId in set $set");
172 break;
173 }
174 $data = json_decode($d['entity_data'], true);
175 if ($data === null) {
176 throw new SimpleSAML_Error_Exception("Cannot decode metadata for entity '${d['entity_id']}'");
177 }
178 if (!array_key_exists('entityid', $data)) {
179 $data['entityid'] = $d['entity_id'];
180 }
181 }
182 return $data;
183 } else {
184 throw new Exception('PDO metadata handler: Database error: '.var_export($this->db->getLastError(), true));
185 }
186 }
static warning($string)
Definition: Logger.php:177
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
if( $source===null) if(!($source instanceof sspmod_saml_Auth_Source_SP)) $entityId
Definition: metadata.php:22
$stmt
$data
Definition: bench.php:6

References $d, $data, $entityId, $stmt, getTableName(), and SimpleSAML\Logger\warning().

+ Here is the call graph for this function:

◆ getMetadataSet()

SimpleSAML_Metadata_MetaDataStorageHandlerPdo::getMetadataSet (   $set)

Retrieve a list of all available metadata for a given set.

Parameters
string$setThe set we are looking for metadata in.
Returns
array $metadata An associative array with all the metadata for the given set.

Reimplemented from SimpleSAML_Metadata_MetaDataStorageSource.

Definition at line 119 of file MetaDataStorageHandlerPdo.php.

120 {
121 assert(is_string($set));
122
123 if (array_key_exists($set, $this->cachedMetadata)) {
124 return $this->cachedMetadata[$set];
125 }
126
127 $metadataSet = $this->load($set);
128 if ($metadataSet === null) {
129 $metadataSet = array();
130 }
131
132 foreach ($metadataSet as $entityId => &$entry) {
133 if (preg_match('/__DYNAMIC(:[0-9]+)?__/', $entityId)) {
134 $entry['entityid'] = $this->generateDynamicHostedEntityID($set);
135 } else {
136 $entry['entityid'] = $entityId;
137 }
138 }
139
140 $this->cachedMetadata[$set] = $metadataSet;
141 return $metadataSet;
142 }
load($set)
This function loads the given set of metadata from a file to a configured database.

References $entityId, generateDynamicHostedEntityID(), and load().

+ Here is the call graph for this function:

◆ getTableName()

SimpleSAML_Metadata_MetaDataStorageHandlerPdo::getTableName (   $table)
private

Replace the -'s to an _ in table names for Metadata sets since SQL does not allow a - in a table name.

Parameters
string$tableTable
Returns
string Replaced table name

Definition at line 272 of file MetaDataStorageHandlerPdo.php.

273 {
274 assert(is_string($table));
275
276 return $this->db->applyPrefix(str_replace("-", "_", $this->tablePrefix.$table));
277 }
if(empty($password)) $table
Definition: pwgen.php:24

References $table.

Referenced by addEntry(), getMetaData(), initDatabase(), and load().

+ Here is the caller graph for this function:

◆ initDatabase()

SimpleSAML_Metadata_MetaDataStorageHandlerPdo::initDatabase ( )

Initialize the configured database.

Returns
int|false The number of SQL statements successfully executed, false if some error occurred.

Definition at line 285 of file MetaDataStorageHandlerPdo.php.

286 {
287 $stmt = 0;
288 $fine = true;
289 foreach ($this->supportedSets as $set) {
290 $tableName = $this->getTableName($set);
291 $rows = $this->db->write(
292 "CREATE TABLE IF NOT EXISTS $tableName (entity_id VARCHAR(255) PRIMARY KEY NOT NULL, entity_data ".
293 "TEXT NOT NULL)"
294 );
295 if ($rows === 0) {
296 $fine = false;
297 } else {
298 $stmt += $rows;
299 }
300 }
301 if (!$fine) {
302 return false;
303 }
304 return $stmt;
305 }

References $rows, $stmt, and getTableName().

+ Here is the call graph for this function:

◆ load()

SimpleSAML_Metadata_MetaDataStorageHandlerPdo::load (   $set)
private

This function loads the given set of metadata from a file to a configured database.

This function returns NULL if it is unable to locate the given set in the metadata directory.

Parameters
string$setThe set of metadata we are loading.
Returns
array $metadata Associative array with the metadata, or NULL if we are unable to load metadata from the given file.
Exceptions
ExceptionIf a database error occurs.
SimpleSAML_Error_ExceptionIf the metadata can be retrieved from the database, but cannot be decoded.

Definition at line 80 of file MetaDataStorageHandlerPdo.php.

81 {
82 assert(is_string($set));
83
84 $tableName = $this->getTableName($set);
85
86 if (!in_array($set, $this->supportedSets, true)) {
87 return null;
88 }
89
90 $stmt = $this->db->read("SELECT entity_id, entity_data FROM $tableName");
91 if ($stmt->execute()) {
92 $metadata = array();
93
94 while ($d = $stmt->fetch()) {
95 $data = json_decode($d['entity_data'], true);
96 if ($data === null) {
97 throw new SimpleSAML_Error_Exception("Cannot decode metadata for entity '${d['entity_id']}'");
98 }
99 if (!array_key_exists('entityid', $data)) {
100 $data['entityid'] = $d['entity_id'];
101 }
102 $metadata[$d['entity_id']] = $data;
103 }
104
105 return $metadata;
106 } else {
107 throw new Exception('PDO metadata handler: Database error: '.var_export($this->db->getLastError(), true));
108 }
109 }

References $d, $data, $metadata, $stmt, and getTableName().

Referenced by getMetadataSet().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $cachedMetadata

SimpleSAML_Metadata_MetaDataStorageHandlerPdo::$cachedMetadata = array()
private

This is an associative array which stores the different metadata sets we have loaded.

Definition at line 29 of file MetaDataStorageHandlerPdo.php.

◆ $db

SimpleSAML_Metadata_MetaDataStorageHandlerPdo::$db
private

The PDO object.

Definition at line 19 of file MetaDataStorageHandlerPdo.php.

◆ $supportedSets

SimpleSAML_Metadata_MetaDataStorageHandlerPdo::$supportedSets
Initial value:
= array(
'adfs-idp-hosted',
'adfs-sp-remote',
'saml20-idp-hosted',
'saml20-idp-remote',
'saml20-sp-remote',
'shib13-idp-hosted',
'shib13-idp-remote',
'shib13-sp-hosted',
'shib13-sp-remote',
'wsfed-idp-remote',
'wsfed-sp-hosted'
)

All the metadata sets supported by this MetaDataStorageHandler.

Definition at line 34 of file MetaDataStorageHandlerPdo.php.

◆ $tablePrefix

SimpleSAML_Metadata_MetaDataStorageHandlerPdo::$tablePrefix
private

Prefix to apply to the metadata table.

Definition at line 24 of file MetaDataStorageHandlerPdo.php.


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