UNPKG

graph-acl

Version:

An ACL module using Graph databases.

2,962 lines (934 loc) 42 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: ACL</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Class: ACL</h1> <section> <header> <h2> ACL </h2> </header> <article> <div class="container-overview"> <dt> <h4 class="name" id="ACL"><span class="type-signature"></span>new ACL<span class="signature">(connector)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Creates an instance of ACL. Examples: var neo4j = require('node-neo4j'); var graphACL = require('node-graph-acl'); var db = new neo4j('http://localhost:7474'); var connector = new graphACL.neo4jConnector(db); var acl = new graphACL(connector); </div> <h5>This:</h5> <ul><li>{<a href="ACL.html">ACL</a>}</li></ul> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>connector</code></td> <td class="type"> <span class="param-type"><a href="global.html#Connector">Connector</a></span> | <span class="param-type"><a href="Neo4jConnector.html">Neo4jConnector</a></span> </td> <td class="description last">A connector to a graph database of your choice</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line22">line 22</a> </li></ul></dd> </dl> </dd> </div> <h3 class="subsection-title">Methods</h3> <dl> <dt> <h4 class="name" id="_createRelationship"><span class="type-signature"></span>_createRelationship<span class="signature">(nodeId1, nodeId2, type, properties, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Create Relationship. If relationship already exists, does nothing. Examples: acl._createRelationship(1, 2, 'TYPE', callback); acl._createRelationship(1, 2, 'TYPE', {p1:'v1', p2:'v2'}, callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>nodeId1</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Number</span> </td> <td class="description last">First Node ID.</td> </tr> <tr> <td class="name"><code>nodeId2</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Number</span> </td> <td class="description last">Second Node ID.</td> </tr> <tr> <td class="name"><code>type</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">Relationship type.</td> </tr> <tr> <td class="name"><code>properties</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">Relationship properties.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line679">line 679</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="_createResource"><span class="type-signature"></span>_createResource<span class="signature">(resourceId, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Create Resource. If role already exists, does nothing. Examples: acl._createResource('resource1', callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>resourceId</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Number</span> </td> <td class="description last">Resource id.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line650">line 650</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="_createRole"><span class="type-signature"></span>_createRole<span class="signature">(roleId, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Create Role. If role already exists, does nothing. Examples: acl._createRole('role1', callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>roleId</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Number</span> </td> <td class="description last">Role id.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line625">line 625</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="_createUser"><span class="type-signature"></span>_createUser<span class="signature">(userId, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Create User. If user already exists, does nothing. Examples: acl._createUser('user1', callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>userId</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Number</span> </td> <td class="description last">User id.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line600">line 600</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="addRoleParents"><span class="type-signature"></span>addRoleParents<span class="signature">(role, parents, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Add one or more parent roles to a role. Examples: acl.addRoleParents('role1', 'role2', callback); acl.addRoleParents('role1', ['role2', 'role3'], callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>role</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Number</span> </td> <td class="description last">Role id.</td> </tr> <tr> <td class="name"><code>parents</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Parent role(s) to add to the role.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line164">line 164</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="addUserRoles"><span class="type-signature"></span>addUserRoles<span class="signature">(userId, roles, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Add roles to a given user. Examples: acl.addUserRoles('user1', 'role1', callback); acl.addUserRoles('user1', ['role1', 'role2'], callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>userId</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Number</span> </td> <td class="description last">User id.</td> </tr> <tr> <td class="name"><code>roles</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Role(s) to add to the user.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line37">line 37</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="allow"><span class="type-signature"></span>allow<span class="signature">(roles, resources, permissions, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Add permissions to roles over resources. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>roles</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Role(s) to add permission(s) of resource(s) to.</td> </tr> <tr> <td class="name"><code>resources</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Resource(s) to give permission(s) to.</td> </tr> <tr> <td class="name"><code>permissions</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Permission(s) of the resource(s).</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line257">line 257</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="allowedPermissions"><span class="type-signature"></span>allowedPermissions<span class="signature">(userId, resources, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Get all the permissions the user has to over this resources. It returns an array of objects where every object maps a resource name to a list of permissions for that resource. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>userId</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Number</span> </td> <td class="description last">User.</td> </tr> <tr> <td class="name"><code>resources</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Resource(s) to ask permissions about.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line397">line 397</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="areAnyRolesAllowed"><span class="type-signature"></span>areAnyRolesAllowed<span class="signature">(roles, resource, permissions, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Check if the role(s) have permission(s) on the resource(s). Examples: acl.areAnyRolesAllowed('role1', 'resource1', 'permission1', callback); acl.areAnyRolesAllowed('role1', 'resource1', ['permission1', 'permission2'], callback); acl.areAnyRolesAllowed(['role1', role2], 'resource1', 'permission1', callback); acl.areAnyRolesAllowed(['role1', role2], 'resource1', ['permission1', 'permission2'], callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>roles</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Role(s) ids to check the permissions for.</td> </tr> <tr> <td class="name"><code>resource</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">Resource to ask permissions for.</td> </tr> <tr> <td class="name"><code>permissions</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Permission(s) over the resource.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line527">line 527</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="isAllowed"><span class="type-signature"></span>isAllowed<span class="signature">(userId, resources, permissions, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Check if a user is allowed to access resource(s) with given permission(s) (note: it must fulfil all the permissions). Examples: acl.isAllowed('user1', 'resource1', 'permission1', callback); acl.isAllowed('user1', ['resource1', 'resource2'], ['permission1', 'permission2'], callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>userId</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Number</span> </td> <td class="description last">User id.</td> </tr> <tr> <td class="name"><code>resources</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Resource(s) to ask permissions for.</td> </tr> <tr> <td class="name"><code>permissions</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Permission(s).</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line479">line 479</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="removeAllow"><span class="type-signature"></span>removeAllow<span class="signature">(role, resources, permissions, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Remove permissions from roles over resources. Examples: acl.removeAllow('role1', 'resource1', 'permission1', callback); acl.removeAllow('role1', ['resource1', 'resource2'], ['permission1', 'permission2'], callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>role</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">Role to remove permission(s) of resource(s) from.</td> </tr> <tr> <td class="name"><code>resources</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Resource(s) to remove permission(s) from.</td> </tr> <tr> <td class="name"><code>permissions</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Permission(s) of the resource(s).</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line333">line 333</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="removeResource"><span class="type-signature"></span>removeResource<span class="signature">(resourceId, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Remove a resource from the system. Examples: acl.removeResource('resource1', callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>resourceId</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">Resource to be removed.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line559">line 559</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="removeRole"><span class="type-signature"></span>removeRole<span class="signature">(roleId, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Remove a role from the system. Examples: acl.removeRole('role1', callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>roleId</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Number</span> </td> <td class="description last">Role to be removed</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line200">line 200</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="removeUserRoles"><span class="type-signature"></span>removeUserRoles<span class="signature">(userId, roles, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Remove roles from a given user. Examples: acl.removeUserRoles('user1', 'role1', callback); acl.removeUserRoles('user1', ['role1', 'role2'], callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>userId</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Number</span> </td> <td class="description last">User id.</td> </tr> <tr> <td class="name"><code>roles</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Role(s) to remove from the user.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line84">line 84</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="userRoles"><span class="type-signature"></span>userRoles<span class="signature">(userId, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Return all the roles the user belongs to. Examples: acl.userRoles('user1', callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>userId</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Number</span> </td> <td class="description last">User id.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line129">line 129</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="whatResources"><span class="type-signature"></span>whatResources<span class="signature">(roles, permissions, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Get resources the role(s) has permission(s) over. Examples: acl.whatResources('role1', 'permission1', callback); acl.whatResources('role1', ['permission1', 'permission2'], callback); acl.whatResources(['role1', role2], 'permission1', callback); acl.whatResources(['role1', role2], ['permission1', 'permission2'], callback); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>roles</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Roles ids.</td> </tr> <tr> <td class="name"><code>permissions</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Array</span> </td> <td class="description last">Permissions ids.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback called when finished.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="acl.js.html">acl.js</a>, <a href="acl.js.html#line545">line 545</a> </li></ul></dd> </dl> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="ACL.html">ACL</a></li><li><a href="Neo4jConnector.html">Neo4jConnector</a></li></ul><h3>Global</h3><ul><li><a href="global.html#async">async</a></li><li><a href="global.html#Connector">Connector</a></li></ul> </nav> <br clear="both"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Fri Aug 08 2014 16:10:13 GMT-0000 (UTC) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>