Skip to content

Commit

Permalink
Adding security authorizers to the meadow base object and package loader
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenvelozo committed Dec 10, 2015
1 parent 3c34adf commit d09fd7a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meadow",
"version": "1.0.1",
"version": "1.0.2",
"description": "A data access library.",
"main": "source/Meadow.js",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions source/Meadow-PackageLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ var loadFromPackage = function(pMeadow, pPackage)
tmpNewMeadow.setDefault(tmpPackage.DefaultObject);
}

if (typeof(tmpPackage.Authorization) === 'object')
{
tmpNewMeadow.setAuthorizer(tmpPackage.Authorization);
}

return tmpNewMeadow;
};

Expand Down
28 changes: 28 additions & 0 deletions source/Meadow-Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ var MeadowSchema = function()
// The cached validator, which uses the JSONSchema
var _Validate = false;

// The authorizers available to this meadow object
var _Authorizers = {};


/**
* Set the Meadow schema
Expand Down Expand Up @@ -129,6 +132,17 @@ var MeadowSchema = function()
};
setDefault();

/**
* Set the authorizer set
*
* @method setAuthorizer
* @return {Object} This is chainable.
*/
var setAuthorizer = function(pAuthorizer)
{
_Authorizers = (typeof(pAuthorizer) === 'object') ? pAuthorizer : {};
};

/**
* Validate an object against the current schema
*
Expand All @@ -153,6 +167,7 @@ var MeadowSchema = function()
setSchema: setSchema,
setJsonSchema: setJsonSchema,
setDefault: setDefault,
setAuthorizer: setAuthorizer,
validateObject: validateObject,

new: createNew
Expand Down Expand Up @@ -197,6 +212,19 @@ var MeadowSchema = function()
});


/**
* Authorizer
*
* @property defaultObject
* @type object
*/
Object.defineProperty(tmpNewMeadowSchemaObject, 'authorizer',
{
get: function() { return _Authorizers; },
enumerable: true
});


return tmpNewMeadowSchemaObject;
}

Expand Down
13 changes: 13 additions & 0 deletions source/Meadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ var Meadow = function()
return this;
};

/**
* Set the authorizer set
*
* @method setAuthorizer
* @return {Object} This is chainable.
*/
var setAuthorizer = function(pAuthorizer)
{
_Schema.setAuthorizer(pAuthorizer);
return this;
};

/**
* Set the default identifier
*
Expand Down Expand Up @@ -265,6 +277,7 @@ var Meadow = function()
setJsonSchema: setJsonSchema,
setDefault: setDefault,
setDefaultIdentifier: setDefaultIdentifier,
setAuthorizer: setAuthorizer,

// Factory
new: createNew
Expand Down
20 changes: 19 additions & 1 deletion test/Animal.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,23 @@
}
},
"required": ["IDAnimal", "Name", "CreatingIDUser"]
}
},

"Authorization": {
"SomeSecurity": {
"Create": "Deny",
"Read": "Deny",
"Reads": "Deny",
"ReadsBy": "Deny",
"ReadMax": "Deny",
"ReadSelectList": "Deny",
"Update": "Deny",
"Delete": "Deny",
"Count": "Deny",
"CountBy": "Deny",
"Schema": "Deny",
"Validate": "Deny",
"New": "Deny"
}
}
}
6 changes: 6 additions & 0 deletions test/Meadow-Provider-MySQL_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ suite
var testMeadow = require('../source/Meadow.js').new(libFable)
.loadFromPackage(__dirname+'/Animal.json').setProvider('MySQL');

// Make sure the authentication stuff got loaded
Expect(testMeadow.schemaFull.authorizer.SomeSecurity)
.to.be.an('object');
Expect(testMeadow.schemaFull.authorizer.SomeSecurity.Create)
.to.equal('Deny');

var tmpQuery = testMeadow.query
.addRecord({Name:'Grommet', Type:'Dog'});

Expand Down

0 comments on commit d09fd7a

Please sign in to comment.