From 1942103f8ba6365943c632123fffe44b635fa2b4 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Mon, 26 Oct 2009 19:10:20 +0000 Subject: [PATCH] MDL-17135 external token access support --- lib/db/install.xml | 25 +++++++++++++++++++++++-- lib/db/upgrade.php | 31 +++++++++++++++++++++++++++++++ lib/externallib.php | 17 +++++++++++++++++ version.php | 2 +- 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/lib/db/install.xml b/lib/db/install.xml index e1337dd09c..bd18e06c2c 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -2276,7 +2276,7 @@ - +
@@ -2291,5 +2291,26 @@
+ + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 56462aaf19..841a86d7ab 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2598,6 +2598,37 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint($result, 2009100605); } + if ($result && $oldversion < 2009102600) { + + /// Define table external_tokens to be created + $table = new xmldb_table('external_tokens'); + + /// Adding fields to table external_tokens + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('token', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null); + $table->add_field('tokentype', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); + $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); + $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); + $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, null, null, null); + $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); + $table->add_field('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null); + $table->add_field('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); + $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); + $table->add_field('lastaccess', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); + + /// Adding keys to table external_tokens + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); + $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id')); + $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); + + /// Launch create table for external_tokens + $dbman->create_table($table); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009102600); + } + return $result; } diff --git a/lib/externallib.php b/lib/externallib.php index bb5330dcb1..6bcfc6a340 100644 --- a/lib/externallib.php +++ b/lib/externallib.php @@ -24,6 +24,23 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +/** + * Security token used for allowing access + * from external application such as web services. + * Scripts do not use any session, performance is relatively + * low because we need to load access info in each request. + * Scrits are executed in parallel. + */ +define('EXTERNAL_TOKEN_PERMANENT', 0); + +/** + * Security token used for allowing access + * of embedded applications, the code is executed in the + * active user session. Token is invalidated after user logs out. + * Scripts are executed serially - normal session locking is used. + */ +define('EXTERNAL_TOKEN_EMBEDDED', 1); + /** * Returns detailed functio information * @param string|object $function name of external function or record from external_function diff --git a/version.php b/version.php index 1a6d86bac2..e011e45d71 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2009102201; // YYYYMMDD = date of the last version bump + $version = 2009102600; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20091026)'; // Human-friendly version name -- 2.39.5