New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

acl-checker

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acl-checker

ACL checker library

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

ACL Checker

This is a NodeJS module that allows you to setup roles/resources/permissions and then allows you to check to see if a role has a particular permission for a resource.

Installation

You can install this using npm:

npm install acl-checker

Quick Guide

First thing you need to do is create a instance of the ACL class:

var AclChecker = require('acl-checker');
var acl = new AclChecker();

Setup Allowable Permissions

Next you have to load roles/resources/permissions. You can do this a few different way, all which use the allow() method.

Strings

You can use simple strings where you pass the role, resource, and then permissions:

acl.allow('guest', 'post', 'read');

This will give the guest roles the read permission on the post resources.

Arrays

Same parameters as strings but using arrays. It will give all the permissions to all the resources, for all the roles, for example:

acl.allow([
  'blogger',
  'admin'
], [
  'post',
  'comment'
], [
  'create',
  'read'
]);

This will give the blogger and admin roles the create and read permissions for both the post and comment resources.

You can also mix and match strings and arrays:

acl.allow([
  'blogger',
  'admin'
], 'post', [
  'create',
  'read'
]);

Object

You can also use an object with allow(). The object would be structure like:

roleName:
  resourceName:
    [permissions]

Defining however many you want, for example:

var permissions = {
  guest: {
    post: [
      'read'
    ],
    comment: [
      'create',
      'read'
    ]
  },
  blogger: {
    post: [
      'create',
      'read',
      'update',
      'delete'
    ],
    comment: [
      'create',
      'read',
      'approve'
    ]
  },
  admin: {
    post: [
      'create',
      'read',
      'update',
      'delete'
    ],
    comment: [
      'create',
      'read',
      'update',
      'delete',
      'approve'
    ]
  }
};

acl.allow(permissions);

Where Does The Data Come From?

This library is designed very specifically to handle the task of validating permissions on roles and resources, it does nothing with get or retrieving that data.

It is up to your application to prodive the data where it uses low level libraries like node-mysql or node_redis or using an Object Mapper like Simple ORM, Bookshelf, or Mongoose or a combination. You have full control in how the ACL data is retrieve and stored.

Removing Permissions

To remove permission, use the removeAllow() method which has the same structure as the allow() method.

acl.removeAllow('guest', 'post', 'read');

acl.removeAllow('guest', [
  'post',
  'comment'
], 'read');

acl.removeAllow({
  guest: {
    post: [
      'read'
    ]
  }
});

Checking Permission

To check if a permission is valid, use the either isAllowed() or allIsAllowed() method which has the same structure as the allow() method.

isAllowed() requires just one of the permission to be valid while isAllAllowed() requires all permissions to be valid.

acl.isAllowed('guest', 'post', 'read');

acl.isAllowed('guest', [
  'post',
  'comment'
], 'read');

acl.allIsAllowed({
  guest: {
    post: [
      'read'
    ]
  }
});

LICENSE

MIT

Keywords

FAQs

Package last updated on 07 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc