From 56babcc99c9c0fbf8138514aa1d3eb66c112f2dc Mon Sep 17 00:00:00 2001 From: anders elo Date: Tue, 20 Aug 2013 19:10:53 +0200 Subject: [PATCH 1/3] arangoDB auth plugin --- lib/DAV/plugins/auth/arango.js | 29 +++++++++++++++++++++++++++++ lib/shared/backends/arango.js | 10 ++++++++++ 2 files changed, 39 insertions(+) create mode 100644 lib/DAV/plugins/auth/arango.js create mode 100644 lib/shared/backends/arango.js diff --git a/lib/DAV/plugins/auth/arango.js b/lib/DAV/plugins/auth/arango.js new file mode 100644 index 00000000..874159a3 --- /dev/null +++ b/lib/DAV/plugins/auth/arango.js @@ -0,0 +1,29 @@ +"use strict"; + +var jsDAV_Auth_Backend_AbstractDigest = require("./abstractDigest"); + +/** + * This is an authentication backend that uses the arango database to manage passwords. + */ +var jsDAV_Auth_Backend_Arango = module.exports = jsDAV_Auth_Backend_AbstractDigest.extend({ + initialize: function (db) { + jsDAV_Auth_Backend_AbstractDigest.initialize.call(this); + this.db = db; + }, + + /** + * Returns a users' information + * + * @param {string} realm + * @param {string} username + * @return {string} + */ + getDigestHash: function (realm, username, cbdigest) { + this.db.simple.first({username:username,realm:realm}) + .then(function(ret){ + cbdigest(null,ret && ret.document && ret.document.password); + },function(err){ + return cbdigest(err); + }); + } +}); \ No newline at end of file diff --git a/lib/shared/backends/arango.js b/lib/shared/backends/arango.js new file mode 100644 index 00000000..c299d81c --- /dev/null +++ b/lib/shared/backends/arango.js @@ -0,0 +1,10 @@ +var arango = require("arango"); + +/* Example: getConnection("http://127.0.0.1:8529/users",clbk); */ +exports.getConnection = function(connStr, callback) { + try { + callback(null,new arango.Connection(connStr)); + } catch (err) { + callback(err); + } +}; \ No newline at end of file From e9da57f3e2a784685200d19ebd1734c5fe48d62b Mon Sep 17 00:00:00 2001 From: anders elo Date: Tue, 20 Aug 2013 19:11:28 +0200 Subject: [PATCH 2/3] added auth fileserver example --- examples/authfs.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 examples/authfs.js diff --git a/examples/authfs.js b/examples/authfs.js new file mode 100644 index 00000000..7a90adff --- /dev/null +++ b/examples/authfs.js @@ -0,0 +1,23 @@ +"use strict"; + +var jsDAV = require("./../lib/jsdav"); +jsDAV.debugMode = true; + +var jsDAV_Locks_Backend_FS = require("./../lib/DAV/plugins/locks/fs"); +var authBackend = require("./../lib/DAV/plugins/auth/arango"); +var authPlugin = require("./../lib/DAV/plugins/auth"); +var Db = require("./../lib/shared/backends/arango"); + +Db.getConnection("http://127.0.0.1:8529/users", function(err, db) { + if (err) throw err; + + var arangoDB = authBackend.new(db); + + jsDAV.createServer({ + node: __dirname + "/../test/assets", + authBackend: arangoDB, + locksBackend: jsDAV_Locks_Backend_FS.new(__dirname + "/../test/assets"), + realm: "jsDAV", + plugins: [authPlugin] + }, 8000); +}); \ No newline at end of file From a6061d542a1ce68c80e109f8658f002b59726290 Mon Sep 17 00:00:00 2001 From: anders elo Date: Tue, 20 Aug 2013 19:12:18 +0200 Subject: [PATCH 3/3] added arango client dependency --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 407c16c2..fdaa3a39 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "dbox": "~0.5.6", "redis": "~0.8.2", "mongodb": "~1.2.12", - "gnu-tools": "0.0.x" + "gnu-tools": "0.0.x", + "arango": "git://github.com/kaerus-component/arango.git#master" }, "licenses": [{ "type": "The MIT License",