|
| __construct ($config) |
| Parse configuration. More...
|
|
| __sleep () |
| Called before serialization. More...
|
|
| hasConsent ($userId, $destinationId, $attributeSet) |
| Check for consent. More...
|
|
| saveConsent ($userId, $destinationId, $attributeSet) |
| Save consent. More...
|
|
| deleteConsent ($userId, $destinationId) |
| Delete consent. More...
|
|
| deleteAllConsents ($userId) |
| Delete all consents. More...
|
|
| getConsents ($userId) |
| Retrieve consents. More...
|
|
| getStatistics () |
| Get statistics from the database. More...
|
|
| selftest () |
| A quick selftest of the consent database. More...
|
|
| hasConsent ($userId, $destinationId, $attributeSet) |
| Check for consent. More...
|
|
| saveConsent ($userId, $destinationId, $attributeSet) |
| Save consent. More...
|
|
| deleteConsent ($userId, $destinationId) |
| Delete consent. More...
|
|
| deleteAllConsents ($userId) |
| Delete all consents. More...
|
|
| getStatistics () |
| Get statistics for all consent given in the consent store. More...
|
|
| getConsents ($userId) |
| Retrieve consents. More...
|
|
Definition at line 18 of file Database.php.
◆ __construct()
sspmod_consent_Consent_Store_Database::__construct |
( |
|
$config | ) |
|
Parse configuration.
This constructor parses the configuration.
- Parameters
-
array | $config | Configuration for database consent store. |
- Exceptions
-
Exception | in case of a configuration error. |
Definition at line 69 of file Database.php.
References $config.
74 if (!array_key_exists(
'dsn',
$config)) {
75 throw new Exception(
'consent:Database - Missing required option \'dsn\'.');
77 if (!is_string(
$config[
'dsn'])) {
78 throw new Exception(
'consent:Database - \'dsn\' is supposed to be a string.');
82 $this->_dateTime = (0 === strpos($this->_dsn,
'sqlite:')) ?
'DATETIME("NOW")' :
'NOW()';
84 if (array_key_exists(
'username',
$config)) {
85 if (!is_string(
$config[
'username'])) {
86 throw new Exception(
'consent:Database - \'username\' is supposed to be a string.');
88 $this->_username =
$config[
'username'];
90 $this->_username = null;
93 if (array_key_exists(
'password',
$config)) {
94 if (!is_string(
$config[
'password'])) {
95 throw new Exception(
'consent:Database - \'password\' is supposed to be a string.');
97 $this->_password =
$config[
'password'];
99 $this->_password = null;
102 if (array_key_exists(
'table',
$config)) {
103 if (!is_string(
$config[
'table'])) {
104 throw new Exception(
'consent:Database - \'table\' is supposed to be a string.');
106 $this->_table =
$config[
'table'];
108 $this->_table =
'consent';
111 if (isset(
$config[
'timeout'])) {
112 if (!is_int(
$config[
'timeout'])) {
113 throw new Exception(
'consent:Database - \'timeout\' is supposed to be an integer.');
115 $this->_timeout =
$config[
'timeout'];
◆ __sleep()
sspmod_consent_Consent_Store_Database::__sleep |
( |
| ) |
|
Called before serialization.
- Returns
- array The variables which should be serialized.
Definition at line 125 of file Database.php.
References array.
Create styles array
The data for the language used.
◆ _createTable()
sspmod_consent_Consent_Store_Database::_createTable |
( |
| ) |
|
|
private |
Create consent table.
This function creates the table with consent data.
- Returns
- True if successful, false if not.
Remove this function since it is not used
Definition at line 436 of file Database.php.
443 $res = $this->db->exec(
444 'CREATE TABLE ' . $this->_table .
' (consent_date TIMESTAMP NOT null, usage_date TIMESTAMP NOT null,' .
445 'hashed_user_id VARCHAR(80) NOT null, service_id VARCHAR(255) NOT null, attribute VARCHAR(80) NOT null,' .
446 'UNIQUE (hashed_user_id, service_id)' 448 if (
$res ===
false) {
_getDB()
Get database handle.
foreach($_POST as $key=> $value) $res
◆ _execute()
sspmod_consent_Consent_Store_Database::_execute |
( |
|
$statement, |
|
|
|
$parameters |
|
) |
| |
|
private |
Prepare and execute statement.
This function prepares and executes a statement. On error, false will be returned.
- Parameters
-
string | $statement | The statement which should be executed. |
array | $parameters | Parameters for the statement. |
- Returns
- PDOStatement|false The statement, or false if execution failed.
Definition at line 337 of file Database.php.
References _getDB(), and SimpleSAML\Logger\error().
Referenced by deleteAllConsents(), deleteConsent(), getConsents(), hasConsent(), and saveConsent().
339 assert(
'is_string($statement)');
340 assert(
'is_array($parameters)');
347 $st = $db->prepare($statement);
350 'consent:Database - Error preparing statement \'' .
351 $statement .
'\':
' . self::_formatError($db->errorInfo()) 356 if ($st->execute($parameters) !== true) { 357 SimpleSAML\Logger::error( 358 'consent:Database - Error executing statement \
'' .
359 $statement .
'\':
' . self::_formatError($st->errorInfo()) _getDB()
Get database handle.
◆ _formatError()
static sspmod_consent_Consent_Store_Database::_formatError |
( |
|
$error | ) |
|
|
staticprivate |
Format PDO error.
This function formats a PDO error, as returned from errorInfo.
- Parameters
-
array | $error | The error information. |
- Returns
- string Error text.
Definition at line 488 of file Database.php.
490 assert(
'is_array($error)');
491 assert(
'count($error) >= 3');
◆ _getDB()
sspmod_consent_Consent_Store_Database::_getDB |
( |
| ) |
|
|
private |
Get database handle.
- Returns
- PDO|false Database handle, or false if we fail to connect.
Definition at line 462 of file Database.php.
Referenced by _execute().
464 if ($this->_db !== null) {
468 $driver_options =
array();
469 if (isset($this->_timeout)) {
473 $this->_db =
new PDO($this->_dsn, $this->_username, $this->_password, $driver_options);
Create styles array
The data for the language used.
◆ deleteAllConsents()
sspmod_consent_Consent_Store_Database::deleteAllConsents |
( |
|
$userId | ) |
|
Delete all consents.
- Parameters
-
string | $userId | The hash identifying the user at an IdP. |
- Returns
- int Number of consents deleted
Definition at line 271 of file Database.php.
References _execute(), array, SimpleSAML\Logger\debug(), and SimpleSAML\Logger\warning().
273 assert(
'is_string($userId)');
276 'DELETE FROM ' . $this->_table .
' WHERE hashed_user_id = ?',
284 if ($st->rowCount() > 0) {
286 return $st->rowCount();
_execute($statement, $parameters)
Prepare and execute statement.
Create styles array
The data for the language used.
◆ deleteConsent()
sspmod_consent_Consent_Store_Database::deleteConsent |
( |
|
$userId, |
|
|
|
$destinationId |
|
) |
| |
Delete consent.
Called when a user revokes consent for a given destination.
- Parameters
-
string | $userId | The hash identifying the user at an IdP. |
string | $destinationId | A string which identifies the destination. |
- Returns
- int Number of consents deleted
Definition at line 239 of file Database.php.
References _execute(), array, SimpleSAML\Logger\debug(), and SimpleSAML\Logger\warning().
241 assert(
'is_string($userId)');
242 assert(
'is_string($destinationId)');
245 'DELETE FROM ' . $this->_table .
' WHERE hashed_user_id = ? AND service_id = ?;',
246 array($userId, $destinationId)
253 if ($st->rowCount() > 0) {
255 return $st->rowCount();
258 'consent:Database - Attempted to delete nonexistent consent'
_execute($statement, $parameters)
Prepare and execute statement.
Create styles array
The data for the language used.
◆ getConsents()
sspmod_consent_Consent_Store_Database::getConsents |
( |
|
$userId | ) |
|
Retrieve consents.
This function should return a list of consents the user has saved.
- Parameters
-
string | $userId | The hash identifying the user at an IdP. |
- Returns
- array Array of all destination ids the user has given consent for.
Definition at line 302 of file Database.php.
References $ret, $row, _execute(), and array.
304 assert(
'is_string($userId)');
309 'SELECT service_id, attribute, consent_date, usage_date FROM ' . $this->_table .
310 ' WHERE hashed_user_id = ?',
318 while (
$row = $st->fetch(PDO::FETCH_NUM)) {
_execute($statement, $parameters)
Prepare and execute statement.
Create styles array
The data for the language used.
◆ getStatistics()
sspmod_consent_Consent_Store_Database::getStatistics |
( |
| ) |
|
Get statistics from the database.
The returned array contains 3 entries
- total: The total number of consents
- users: Total number of uses that have given consent ' services: Total number of services that has been given consent to
- Returns
- array Array containing the statistics Change fixed table name to config option
Definition at line 379 of file Database.php.
384 $st = $this->
_execute(
'SELECT COUNT(*) AS no FROM consent',
array());
390 if (
$row = $st->fetch(PDO::FETCH_NUM)) {
396 'SELECT COUNT(*) AS no ' .
397 'FROM (SELECT DISTINCT hashed_user_id FROM consent ) AS foo',
405 if (
$row = $st->fetch(PDO::FETCH_NUM)) {
411 'SELECT COUNT(*) AS no FROM (SELECT DISTINCT service_id FROM consent) AS foo',
419 if (
$row = $st->fetch(PDO::FETCH_NUM)) {
_execute($statement, $parameters)
Prepare and execute statement.
Create styles array
The data for the language used.
◆ hasConsent()
sspmod_consent_Consent_Store_Database::hasConsent |
( |
|
$userId, |
|
|
|
$destinationId, |
|
|
|
$attributeSet |
|
) |
| |
Check for consent.
This function checks whether a given user has authorized the release of the attributes identified by $attributeSet from $source to $destination.
- Parameters
-
string | $userId | The hash identifying the user at an IdP. |
string | $destinationId | A string which identifies the destination. |
string | $attributeSet | A hash which identifies the attributes. |
- Returns
- bool True if the user has given consent earlier, false if not (or on error).
Definition at line 151 of file Database.php.
References _execute(), array, and SimpleSAML\Logger\debug().
153 assert(
'is_string($userId)');
154 assert(
'is_string($destinationId)');
155 assert(
'is_string($attributeSet)');
158 'UPDATE ' . $this->_table .
' ' .
159 'SET usage_date = ' . $this->_dateTime .
' ' .
160 'WHERE hashed_user_id = ? AND service_id = ? AND attribute = ?',
161 array($userId, $destinationId, $attributeSet)
168 $rowCount = $st->rowCount();
169 if ($rowCount === 0) {
_execute($statement, $parameters)
Prepare and execute statement.
Create styles array
The data for the language used.
◆ saveConsent()
sspmod_consent_Consent_Store_Database::saveConsent |
( |
|
$userId, |
|
|
|
$destinationId, |
|
|
|
$attributeSet |
|
) |
| |
Save consent.
Called when the user asks for the consent to be saved. If consent information for the given user and destination already exists, it should be overwritten.
- Parameters
-
string | $userId | The hash identifying the user at an IdP. |
string | $destinationId | A string which identifies the destination. |
string | $attributeSet | A hash which identifies the attributes. |
- Returns
- void|true True if consent is deleted.
Definition at line 191 of file Database.php.
References _execute(), array, and SimpleSAML\Logger\debug().
193 assert(
'is_string($userId)');
194 assert(
'is_string($destinationId)');
195 assert(
'is_string($attributeSet)');
199 'UPDATE ' . $this->_table .
' ' .
200 'SET consent_date = ' . $this->_dateTime .
', usage_date = ' . $this->_dateTime .
', attribute = ? ' .
201 'WHERE hashed_user_id = ? AND service_id = ?',
202 array($attributeSet, $userId, $destinationId)
209 if ($st->rowCount() > 0) {
217 'INSERT INTO ' . $this->_table .
' (' .
'consent_date, usage_date, hashed_user_id, service_id, attribute' .
218 ') ' .
'VALUES (' . $this->_dateTime .
', ' . $this->_dateTime .
', ?, ?, ?)',
219 array($userId, $destinationId, $attributeSet)
_execute($statement, $parameters)
Prepare and execute statement.
Create styles array
The data for the language used.
◆ selftest()
sspmod_consent_Consent_Store_Database::selftest |
( |
| ) |
|
A quick selftest of the consent database.
- Returns
- boolean True if OK, false if not. Will throw an exception on connection errors.
Definition at line 502 of file Database.php.
505 'SELECT * FROM ' . $this->_table .
' WHERE hashed_user_id = ? AND service_id = ? AND attribute = ?',
506 array(
'test',
'test',
'test')
_execute($statement, $parameters)
Prepare and execute statement.
Create styles array
The data for the language used.
◆ $_dateTime
sspmod_consent_Consent_Store_Database::$_dateTime |
|
private |
The DATETIME SQL function to use.
Definition at line 28 of file Database.php.
◆ $_db
sspmod_consent_Consent_Store_Database::$_db |
|
private |
Database handle.
This variable can't be serialized.
Definition at line 57 of file Database.php.
◆ $_dsn
sspmod_consent_Consent_Store_Database::$_dsn |
|
private |
◆ $_password
sspmod_consent_Consent_Store_Database::$_password |
|
private |
Password for the database;.
Definition at line 38 of file Database.php.
◆ $_table
sspmod_consent_Consent_Store_Database::$_table |
|
private |
◆ $_timeout
sspmod_consent_Consent_Store_Database::$_timeout = NULL |
|
private |
◆ $_username
sspmod_consent_Consent_Store_Database::$_username |
|
private |
Username for the database.
Definition at line 33 of file Database.php.
The documentation for this class was generated from the following file:
- libs/composer/vendor/simplesamlphp/simplesamlphp/modules/consent/lib/Consent/Store/Database.php