bacl
Simple, fast and secure node ACL
bacl is a nodejs module to work with ACL (access control list). It's work with mongodb using mongoose but you can create your own adapter to work with other databases.
Install and use bacl is very simple
Installation
Just the 'bacl' library:
npm install bacl
Using bacl with the mongoose adapter
Initialize the bacl and pass a mongoose connection
bacl = ;//you need a mongoose or jugglingb connection (to use jugglingdb, look at the bottom of the document)bacl = mongoose;
bacl has got a default list of messages for diferent events (grantAccess,denyAccess and userNotFound) you can change this
bacl = mongoose"grantAccess": "User has got grant access" ...;
Example adding roles
bacl;/* or */bacl;/* or */bacl;/* or */bacl;/* or */bacl;/* or */bacl;/* or */bacl;/* or */bacl;
Example adding users
bacl;/* or */bacl;/* or */bacl;
Example checking access
bacl;/* or */bacl;/* or */bacl;
When you recive the user with the method "can" you can check the roles when you want for example to show and hide elements in the views for diferents roles.
if user //show menu for the guestelse //show other menu/* you can define an "or" operator using arrays */if user //show menu for the guest or guest2else //show other menu/* you can define an operator using objects, everthing is posible */if user //if the user is guest and guest2 show the menu for thatelse //show other menu
bacl has got a fast and simple way to enable/disable users
bacl;/* or */bacl; /* the first parameter can be an array */
Using bacl in compoundjs with the jugglingdb Adapter
In the world of nodejs we have an excellent framework called compoundjs, I'm going to show how integrate bacl with compoundjs.
In config/environment.js
First we are going to create a new file in config/initializers/acl.js of the compound app and copy/paste this code:
module { var bacl = ; bacl = compoundorm_schemas0; bacl; //this is necesary to use in the controller files of compoundjs compoundbacl = bacl;}
And this is everthing. For example, if you want check the access of the user1 in the controller posts you can write this in the controller app/controllers/posts_controller.js:
;
Very simple!
License
MIT
Free Software, Fuck Yeah!