summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortailor <cygnus@janrain.com>2007-09-24 18:31:33 +0000
committertailor <cygnus@janrain.com>2007-09-24 18:31:33 +0000
commitf9d88780e22f049e92c7a23b39ce0b2784ef3021 (patch)
tree519214b07a286c4d3d7b9e962b6fd9c9eabe413d
parent0f270daead5c4821861718c734e55e54ed7ca4d7 (diff)
downloadphp-openid-f9d88780e22f049e92c7a23b39ce0b2784ef3021.zip
php-openid-f9d88780e22f049e92c7a23b39ce0b2784ef3021.tar.gz
php-openid-f9d88780e22f049e92c7a23b39ce0b2784ef3021.tar.bz2
[project @ Add cleanupNonces to SQL stores]
-rw-r--r--Auth/OpenID/MySQLStore.php3
-rw-r--r--Auth/OpenID/PostgreSQLStore.php3
-rw-r--r--Auth/OpenID/SQLStore.php19
-rw-r--r--Auth/OpenID/SQLiteStore.php3
-rw-r--r--Tests/Auth/OpenID/StoreTest.php3
5 files changed, 30 insertions, 1 deletions
diff --git a/Auth/OpenID/MySQLStore.php b/Auth/OpenID/MySQLStore.php
index 4b2d29d..04dded8 100644
--- a/Auth/OpenID/MySQLStore.php
+++ b/Auth/OpenID/MySQLStore.php
@@ -60,6 +60,9 @@ class Auth_OpenID_MySQLStore extends Auth_OpenID_SQLStore {
$this->sql['get_expired'] =
"SELECT server_url FROM %s WHERE issued + lifetime < ?";
+
+ $this->sql['clean_nonce'] =
+ "DELETE FROM %s WHERE timestamp < ?";
}
/**
diff --git a/Auth/OpenID/PostgreSQLStore.php b/Auth/OpenID/PostgreSQLStore.php
index ffbbc69..8babed4 100644
--- a/Auth/OpenID/PostgreSQLStore.php
+++ b/Auth/OpenID/PostgreSQLStore.php
@@ -61,6 +61,9 @@ class Auth_OpenID_PostgreSQLStore extends Auth_OpenID_SQLStore {
"INSERT INTO %s (server_url, timestamp, salt) VALUES ".
"(?, ?, ?)"
;
+
+ $this->sql['clean_nonce'] =
+ "DELETE FROM %s WHERE timestamp < ?";
}
/**
diff --git a/Auth/OpenID/SQLStore.php b/Auth/OpenID/SQLStore.php
index 0f58203..4192022 100644
--- a/Auth/OpenID/SQLStore.php
+++ b/Auth/OpenID/SQLStore.php
@@ -35,6 +35,11 @@ require_once 'Auth/OpenID/Nonce.php';
require_once 'Auth/OpenID.php';
/**
+ * @access private
+ */
+require_once 'Auth/OpenID/Nonce.php';
+
+/**
* This is the parent class for the SQL stores, which contains the
* logic common to all of the SQL stores.
*
@@ -250,7 +255,8 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore {
array(
'value' => $this->nonces_table_name,
'keys' => array('nonce_table',
- 'add_nonce')
+ 'add_nonce',
+ 'clean_nonce')
),
array(
'value' => $this->associations_table_name,
@@ -553,6 +559,17 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore {
return $result;
}
+
+ function cleanupNonces()
+ {
+ global $Auth_OpenID_SKEW;
+ $v = time() - $Auth_OpenID_SKEW;
+
+ $this->connection->query($this->sql['clean_nonce'], array($v));
+ $num = $this->connection->affectedRows();
+ $this->connection->commit();
+ return $num;
+ }
}
?>
diff --git a/Auth/OpenID/SQLiteStore.php b/Auth/OpenID/SQLiteStore.php
index debb5fe..a242f9b 100644
--- a/Auth/OpenID/SQLiteStore.php
+++ b/Auth/OpenID/SQLiteStore.php
@@ -47,6 +47,9 @@ class Auth_OpenID_SQLiteStore extends Auth_OpenID_SQLStore {
$this->sql['add_nonce'] =
"INSERT INTO %s (server_url, timestamp, salt) VALUES (?, ?, ?)";
+
+ $this->sql['clean_nonce'] =
+ "DELETE FROM %s WHERE timestamp < ?";
}
/**
diff --git a/Tests/Auth/OpenID/StoreTest.php b/Tests/Auth/OpenID/StoreTest.php
index 485a4c4..b5b6cb1 100644
--- a/Tests/Auth/OpenID/StoreTest.php
+++ b/Tests/Auth/OpenID/StoreTest.php
@@ -491,6 +491,7 @@ explicitly');
$this->_testStore($store);
$this->_testNonce($store);
+ $this->_testNonceCleanup($store);
$db->disconnect();
unset($db);
@@ -555,6 +556,7 @@ explicitly');
$this->assertTrue($store->createTables(), "Table creation failed");
$this->_testStore($store);
$this->_testNonce($store);
+ $this->_testNonceCleanup($store);
}
$db->disconnect();
@@ -612,6 +614,7 @@ explicitly');
$store->createTables();
$this->_testStore($store);
$this->_testNonce($store);
+ $this->_testNonceCleanup($store);
$db->query("DROP DATABASE $temp_db_name");
}