diff --git a/modules/consent/lib/Consent/Store/Cookie.php b/modules/consent/lib/Consent/Store/Cookie.php index e65c5ec103b8f0ee83059b68b5b3d737cd5929a1..3fbfe5fd554d34804d781d7f8f1cb1bdbf848bdb 100644 --- a/modules/consent/lib/Consent/Store/Cookie.php +++ b/modules/consent/lib/Consent/Store/Cookie.php @@ -110,6 +110,17 @@ class sspmod_consent_Consent_Store_Cookie extends sspmod_consent_Store { $this->setConsentCookie($name, NULL); } + + /** + * Delete consent. + * + * @param string $userId The hash identifying the user at an IdP. + */ + public function deleteAllConsents($userId) { + assert('is_string($userId)'); + + throw new Exception('The cookie consent handler does not support to delete all consents...'); + } /** diff --git a/modules/consent/lib/Consent/Store/Database.php b/modules/consent/lib/Consent/Store/Database.php index 7138a9971b8477600074318fc19cfbaf94f3901a..2b7ca8104e571888109913282aa5cd898ad86af1 100644 --- a/modules/consent/lib/Consent/Store/Database.php +++ b/modules/consent/lib/Consent/Store/Database.php @@ -242,6 +242,25 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store { } } + /** + * Delete all consents. + * + * @param string $userId The hash identifying the user at an IdP. + */ + public function deleteAllConsents($userId) { + assert('is_string($userId)'); + + $st = $this->execute('DELETE FROM ' . $this->table . ' WHERE hashed_user_id = ?', array($userId)); + if ($st === FALSE) return; + + if ($st->rowCount() > 0) { + SimpleSAML_Logger::debug('consent:Database - Deleted (' . $st->rowCount() . ') consent(s).'); + return $st->rowCount(); + } else { + SimpleSAML_Logger::warning('consent:Database - Attempted to delete nonexistent consent'); + } + } + /** * Retrieve consents. @@ -307,6 +326,31 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store { } + /** + * get statistics + * + */ + public function getStatistics() { + $ret = array(); + + $st = $this->execute('select count(*) as no from consent', array()); + if ($st === FALSE) return array(); + if($row = $st->fetch(PDO::FETCH_NUM)) $ret['total'] = $row[0]; + + $st = $this->execute('select count(*) as no from (select distinct hashed_user_id from consent ) as foo', array()); + if ($st === FALSE) return array(); + if($row = $st->fetch(PDO::FETCH_NUM)) $ret['users'] = $row[0]; + + $st = $this->execute('select count(*) as no from (select distinct service_id from consent ) as foo', array()); + if ($st === FALSE) return array(); + if($row = $st->fetch(PDO::FETCH_NUM)) $ret['services'] = $row[0]; + + return $ret; + } + + + + /** * Create consent table. * diff --git a/modules/consent/lib/Store.php b/modules/consent/lib/Store.php index c4ffe233f330b70373766c9b2758314696c49be3..a6ba0a7957fb96de4889303b287e5e83cdd729ec 100644 --- a/modules/consent/lib/Store.php +++ b/modules/consent/lib/Store.php @@ -60,6 +60,22 @@ abstract class sspmod_consent_Store { abstract public function deleteConsent($userId, $destinationId); + /** + * Delete all consents. + * + * Called when a user revokes all consents + * + * @param string $userId The hash identifying the user at an IdP. + */ + public function deleteAllConsents($userId) { + throw new Exception('Not implemented: deleteAllConsents()'); + } + + + public function getStatistics() { + throw new Exception('Not implemented: getStatistics()'); + } + /** * Retrieve consents. *